N = int(input()) inf = 10 ** 18 dp = [[-inf] * 2 for i in range(N + 1)] dp[0][0] = 0 D = [] for i in range(N): D.append(list(map(int, input().split()))) for i in range(N): p, a = D[i] dp[i + 1][0] = max(dp[i + 1][0], dp[i][0] + p, dp[i][1] + 2*p) dp[i + 1][1] = max(dp[i + 1][1], dp[i][0] + a, dp[i][1] + 2*a) print(max(dp[-1]))