P14092 [ICPC 2023 Seoul R] M. S. I. S.

Description

We are given a $2\times n$ matrix $M$ of positive integers, and each row of $M$ does not contain duplicate numbers. For $i$-th row $r_i$ of $M$, $i=1,2$, we find the maximum sum $s_i$ of increasing subsequence contained in $r_i$. For example, if $M$ is given as the figure below, $s_1$ is $1 + 2 + 3 + 4 + 5 + 6$ and $s_2$ is $2 + 3 + 5$. We call $s_1+s_2$ *the maximum sum of increasing subsequences*, *MSIS*. ![](https://cdn.luogu.com.cn/upload/image_hosting/m4f54ytc.png) Once we permute the columns of $M$, MSIS can change. For example, if we permute the columns of the above matrix $M=[c_1,c_2,c_3,c_4,c_5,c_6]$ to $M=[c_2,c_3,c_4,c_5,c_6,c_1]$ as the figure below, MSIS becomes $36$. ![](https://cdn.luogu.com.cn/upload/image_hosting/s7qs0c8s.png) Given a $2\times n$ matrix $M$, write a program to output the maximum of MSIS among all possible permutations of the columns of $M$.

Input Format

Your program is to read from standard input. The input starts with a line containing an integer, $n$ ($1 \le n\le 10,000$), where $n$ is the number of columns of the input matrix $M$. In the following two lines, the $i$-th line contains $n$ positive integers of the $i$-th row of $M$, for $i=1,2$. The integers given as input are between $1$ and $50,000$, and each row does not contain duplicate numbers.

Output Format

Your program is to write to standard output. Print exactly one line. The line should contain the maximum of MSIS among all possible permutations of columns of $M$.