n = gets.to_i s, t = gets.split.map { _1.to_i.pred } a = gets.split.map &:to_i x, y = [], [] (1..).each do |i| break if (s + i) % n == t x << a[(s + i) % n] end (1..).each do |i| break if (s - i) % n == t y << a[(s - i) % n] end ans = a[s] - a[t] X, Y = x.size, y.size if X.even? && Y.even? ans += x[...X / 2].sum - x[X / 2..].sum ans += y[...Y / 2].sum - y[Y / 2..].sum elsif X.even? && Y.odd? ans += x[...X / 2].sum - x[X / 2..].sum ans += y[..Y/2].sum - y[Y/2+1..].sum elsif X.odd? && Y.even? ans += x[..X/2].sum - x[X/2+1..].sum ans += y[...Y / 2].sum - y[Y / 2..].sum else x1=x[..X/2].sum-x[X/2+1..].sum x2=x[...X/2].sum-x[X/2..].sum y1=y[..X/2].sum-y[Y/2+1..].sum y2=y[...Y/2].sum-y[Y/2..].sum ans += [x1+y2,x2+y1].max end puts ans