n = int(input()) a = list(map(int, input().split())) t = 0 for i in range(n - 1, -1, -1): t += a[i * 2 + 1] - a[i * 2] ans = t for i in range(n): t += (a[i * 2] - a[i * 2 + 1]) * 2 ans = max(ans, t) print(ans)