#!/usr/bin/env python3 # %% import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines # %% import numpy as np # %% N = int(readline()) m = map(int, read().split()) AB = list(zip(m, m)) # %% AB_1 = AB[: N // 2] AB_2 = AB[N // 2:] # %% def make_nums(AB): dp = np.zeros(1, np.int64) for a, b in AB: dp = np.concatenate([dp + a, dp - b]) return dp # %% X = make_nums(AB_1) Y = make_nums(AB_2) INF = 10 ** 18 Y = np.append(Y, INF) X.sort() Y.sort() # %% ind = np.searchsorted(Y, -X) vals_1 = X + Y[ind] vals_2 = X + Y[ind] vals = np.concatenate([np.abs(vals_1), np.abs(vals_2)]) # %% print(vals.min())