Score : $700$ points
You are given sequences $A$ and $B$ consisting of non-negative integers. The lengths of both $A$ and $B$ are $N$, and the sums of the elements in $A$ and $B$ are equal. The $i$-th element in $A$ is $A_i$, and the $i$-th element in $B$ is $B_i$.
Tozan and Gezan repeats the following sequence of operations:
Tozan wants the number of candies given to Takahashi until the process is terminated to be as large as possible, while Gezan wants it to be as small as possible. Find the number of candies given to Takahashi when both of them perform the operations optimally.
Input is given from Standard Input in the following format:
$N$ $A_1$ $B_1$ $:$ $A_N$ $B_N$
Print the number of candies given to Takahashi when both Tozan and Gezan perform the operations optimally.
2 1 2 3 2
2
When both Tozan and Gezan perform the operations optimally, the process will proceed as follows:
3 8 3 0 1 4 8
9
1 1 1
0