local mce, mfl, msq, mmi, mma = math.ceil, math.floor, math.sqrt, math.min, math.max local n = io.read("*n") local a, b, c = {}, {}, {} local tot = 1 for i = 1, n do a[i], b[i] = io.read("*n", "*n") c[i] = b[i] - a[i] tot = tot * 2 end local function dotask(stage, curtask) local nexttask = {} for i = 1, n do nexttask[i] = {} end local mul = 1 for i = 1, n do for used, val in pairs(curtask[i]) do local tmp = used for j = 1, n do if tmp % 2 == 0 and i ~= j then if nexttask[j][used + mul] == nil then nexttask[j][used + mul] = mma(val, c[i] + a[j]) else nexttask[j][used + mul] = mmi(mma(val, c[i] + a[j]), nexttask[j][used + mul]) end end tmp = mfl(tmp / 2) end end mul = mul * 2 end return nexttask end local tasks = {} for i = 1, n do tasks[i] = {} tasks[i][0] = 0 end for i = 2, n do tasks = dotask(i, tasks) end local min = 1000 * 100 for i = 1, n do for k, v in pairs(tasks[i]) do -- print(i, k, v) min = mmi(min, v) end end print(min)