import heapq N = int(input()) s, t = map(int, input().split()) A = list(map(int, input().split())) # Initialize adjacency list for each vertex adj = [[] for _ in range(N + 1)] # 1-based indexing for i in range(1, N + 1): prev = i - 1 if i > 1 else N next_ = i + 1 if i < N else 1 adj[i].append(prev) adj[i].append(next_) visited = [False] * (N + 1) visited[s] = True visited[t] = True X = A[s - 1] Y = A[t - 1] # Priority queues for both players (using max-heap simulation with negative values) heap315 = [] heap8128 = [] # Initialize heaps with adjacent vertices of s and t for u in adj[s]: if not visited[u]: heapq.heappush(heap315, (-A[u - 1], u)) for u in adj[t]: if not visited[u]: heapq.heappush(heap8128, (-A[u - 1], u)) turn = 0 # 0 for 315's turn, 1 for 8128's turn while heap315 or heap8128: if turn == 0: if not heap315: turn = 1 continue val, u = heapq.heappop(heap315) current_A = -val if visited[u]: continue visited[u] = True X += current_A # Add adjacent vertices to the heap for v in adj[u]: if not visited[v]: heapq.heappush(heap315, (-A[v - 1], v)) turn = 1 else: if not heap8128: turn = 0 continue val, u = heapq.heappop(heap8128) current_A = -val if visited[u]: continue visited[u] = True Y += current_A # Add adjacent vertices to the heap for v in adj[u]: if not visited[v]: heapq.heappush(heap8128, (-A[v - 1], v)) turn = 0 print(X - Y)