import sequtils,strutils var N = stdin.readline.parseInt A = newSeq[int](19) B = newSeq[int](19) dp : array[(1 shl 18), array[20, int]] m,nb,ans : int for i in 0 ..< N: (A[i], B[i]) = stdin.readline.split.map(parseInt) B[i] -= A[i] for b in 0 ..< 1 shl N: for i in 0 ..< N: if (b and (1 shl i)) > 0: for j in 0 ..< N: if (b and (1 shl j)) == 0: m = max(dp[b][i], B[i] + A[j]) nb = (b or (1 shl j)) if dp[nb][j] == 0: dp[nb][j] = m else: dp[nb][j] = min(dp[nb][j], m) echo min(dp[(1 shl N) - 1][0..