n = int(input()) a = list(map(int, input().split())) original_sum = sum(abs(x) for x in a) if n == 0: print(0) exit() max_val = max(a) pos = a.index(max_val) # Calculate contributions contributions = [abs(max_val) - abs(x) for x in a] # Compute max_ending_at_pos (left part) max_ending = 0 current = 0 for i in range(pos - 1, -1, -1): current += contributions[i] if current > max_ending: max_ending = current # Compute max_starting_at_pos (right part) max_starting = 0 current = 0 for i in range(pos + 1, n): current += contributions[i] if current > max_starting: max_starting = current total_gain = max_ending + max_starting answer = original_sum + max(total_gain, 0) print(answer)