import heapq def main(): n = int(input()) s, t = map(int, input().split()) a = list(map(int, input().split())) used = [False] * (n + 1) # 1-based indexing # Mark initial positions as used used[s] = True used[t] = True x = a[s-1] y = a[t-1] heap315 = [] heap8128 = [] def get_neighbors(u): if u == 1: return [2, n] elif u == n: return [1, n-1] else: return [u-1, u+1] # Initialize heaps for both players for neighbor in get_neighbors(s): if not used[neighbor]: heapq.heappush(heap315, (-a[neighbor-1], neighbor)) for neighbor in get_neighbors(t): if not used[neighbor]: heapq.heappush(heap8128, (-a[neighbor-1], neighbor)) turn = 0 # 0 for 315's turn, 1 for 8128's turn while heap315 or heap8128: if turn == 0: # 315's turn while heap315: current_a, u = heapq.heappop(heap315) current_a = -current_a if not used[u]: x += current_a used[u] = True for v in get_neighbors(u): if not used[v]: heapq.heappush(heap315, (-a[v-1], v)) break turn = 1 else: # 8128's turn while heap8128: current_a, u = heapq.heappop(heap8128) current_a = -current_a if not used[u]: y += current_a used[u] = True for v in get_neighbors(u): if not used[v]: heapq.heappush(heap8128, (-a[v-1], v)) break turn = 0 print(x - y) if __name__ == "__main__": main()