n = int(input()) pa = [[int(i) for i in input().split()] for _ in range(n)] dp = [[0] * 2 for _ in range(n)] dp[0] = pa[0] for i in range(1, n): dp[i][0] = max(dp[i - 1][0] + pa[i][0], dp[i - 1][1] + pa[i][0] * 2) dp[i][1] = max(dp[i - 1][0] + pa[i][1], dp[i - 1][1] + pa[i][1] * 2) print(max(dp[-1]))