using static System.Math; using System; public class Hello { static void Main() { var n = int.Parse(Console.ReadLine().Trim()); var s = Console.ReadLine().Trim(); string[] line = Console.ReadLine().Trim().Split(' '); var a = Array.ConvertAll(line, int.Parse); getAns(n, s, a); } static void getAns(int n, string s, int[] a) { var b = new long[n]; b[0] = s[0] == 'R' ? a[0] : -a[0]; long tmax = Max(0, b[0]); long tmin = Min(0, b[0]); for (int i = 1; i < n; i++) { b[i] = b[i - 1] + s[i] == 'R' ? a[i] : -a[i]; tmax = Max(tmax, b[i]); tmin = Min(tmin, b[i]); } Console.WriteLine(Abs(tmax - tmin)); } }