n = int(input()) s, t = map(int, input().split()) a = list(map(int, input().split())) used = [False] * (n + 1) # 1-based indexing used[s] = True used[t] = True x = a[s-1] y = a[t-1] # 315's territory boundaries l1 = r1 = s # 8128's territory boundaries l2 = r2 = t turn = 0 # 0 for 315, 1 for 8128 while True: all_used = True for i in range(1, n+1): if not used[i]: all_used = False break if all_used: break if turn % 2 == 0: # 315's turn left = l1 - 1 if l1 > 1 else n right = r1 + 1 if r1 < n else 1 candidates = [] if not used[left]: candidates.append((a[left-1], left, 'left')) if not used[right]: candidates.append((a[right-1], right, 'right')) if candidates: candidates.sort(reverse=True, key=lambda x: x[0]) val, pos, dir = candidates[0] x += val used[pos] = True if dir == 'left': l1 = pos else: r1 = pos else: # 8128's turn left = l2 - 1 if l2 > 1 else n right = r2 + 1 if r2 < n else 1 candidates = [] if not used[left]: candidates.append((a[left-1], left, 'left')) if not used[right]: candidates.append((a[right-1], right, 'right')) if candidates: candidates.sort(reverse=True, key=lambda x: x[0]) val, pos, dir = candidates[0] y += val used[pos] = True if dir == 'left': l2 = pos else: r2 = pos turn += 1 print(x - y)