using System; using static System.Console; using System.Linq; using System.Collections.Generic; class Program { static int NN => int.Parse(ReadLine()); static int[] NList => ReadLine().Split().Select(int.Parse).ToArray(); static int[][] NArr(long n) => Enumerable.Repeat(0, (int)n).Select(_ => NList).ToArray(); public static void Main() { Solve(); } static void Solve() { var n = NN; var s = ReadLine(); var a = NList; var cum = new long[n + 1]; for (var i = 0; i < n; ++i) { if (s[i] == 'R') cum[i + 1] = cum[i] + a[i]; else cum[i + 1] = cum[i] - a[i]; } var ans = 0L; var max = 0L; var min = 0L; for (var i = 1; i <= n; ++i) { ans = Math.Max(ans, Math.Max(Math.Abs(max - cum[i]), Math.Abs(cum[i] - min))); max = Math.Max(max, cum[i]); min = Math.Min(min, cum[i]); } WriteLine(ans); } }