CSES - KILO 2018 2/5 - Massive Matrices
  • Time limit: 2.00 s
  • Memory limit: 512 MB

Uolevi has found two matrices AA and BB of size n×nn\times n. Every element in both matrices is either 00 or 11. They also have the following special property: if the element in (i0,j0)(i_0,j_0) is 11, then for all ii and jj such that ii0i\geq i_0 and jj0j\leq j_0 the element in (i,j)(i, j) is also 11.

Now Uolevi is wondering what happens if he multiplies AA with BB. Particularly he is interested in how many non-zero elements A×BA\times B contains.

Can you help him to answer this question?

Input

In the first line you're given the integer nn.

The second line contains nn non-decreasing integers a1,a2,,ana_{1}, a_{2}, \dots, a_{n}. These integers describe the matrix AA. For 1x,y,n1 \leq x, y, \leq n, let Ay,x=0A_{y,x} = 0 if ay<xa_y < x, and otherwise one. It can be proven that every matrix with the given property can be presented this way.

The third line contains nn non-decreasing integers b1,b2,bnb_{1}, b_{2}, \dots b_{n}. These integers describe the matrix BB, in the same way as the integers a1,,ana_{1}, \dots, a_{n} describe AA.

Output

Output a single integer: the number of non-zero elements in A×BA\times B.

Constraints

  • 1n21051\leq n\leq 2\cdot 10^5
  • 0ai,bin0\leq a_i, b_i\leq n
  • aiai+1a_i\leq a_{i+1}
  • bibi+1b_i\leq b_{i+1}

Example

Input:

3
2 2 3
0 1 3

Output:

5