{"raw_statement":[{"iden":"problem statement","content":"There are $N$ monsters along a number line. At the coordinate $i$ $(1\\leq i\\leq N)$ is a monster with a stamina of $A_i$.  \nAdditionally, at the coordinate $i$, there is a permanent shield of a strength $B_i$.  \nThis shield persists even when the monster at the same coordinate has a health of $0$ or below.\nTakahashi, a magician, can perform the following operation any number of times.\n\n*   Choose integers $l$ and $r$ satisfying $1\\leq l\\leq r\\leq N$.\n*   Then, consume $\\max(B_l, B_{l+1}, \\ldots, B_r)$ MP (magic points) to decrease by $1$ the stamina of each of the monsters at the coordinates $l,l+1,\\ldots,r$.\n\nWhen choosing $l$ and $r$, it is fine if some of the monsters at the coordinates $l,l+1,\\ldots,r$ already have a stamina of $0$ or below.  \nNote, however, that the shields at all those coordinates still exist.\nTakahashi wants to make the stamina of every monster $0$ or below.  \nFind the minimum total MP needed to achieve his objective."},{"iden":"constraints","content":"*   $1 \\leq N \\leq 10^5$\n*   $1 \\leq A_i,B_i \\leq 10^9$\n*   All values in the input are integers."},{"iden":"input","content":"The input is given from Standard Input in the following format:\n\n$N$\n$A_1$ $A_2$ $\\ldots$ $A_N$\n$B_1$ $B_2$ $\\ldots$ $B_N$"},{"iden":"sample input 1","content":"5\n4 3 5 1 2\n10 40 20 60 50"},{"iden":"sample output 1","content":"210\n\nTakahashi can achieve his objective as follows.\n\n*   Choose $(l,r)=(1,5)$. Consume $\\max(10,40,20,60,50)=60$ MP, and the staminas of the monsters are $(3,2,4,0,1)$.\n*   Choose $(l,r)=(1,5)$. Consume $\\max(10,40,20,60,50)=60$ MP, and the staminas of the monsters are $(2,1,3,-1,0)$.\n*   Choose $(l,r)=(1,3)$. Consume $\\max(10,40,20)=40$ MP, and the staminas of the monsters are $(1,0,2,-1,0)$.\n*   Choose $(l,r)=(1,1)$. Consume $\\max(10)=10$ MP, and the staminas of the monsters are $(0,0,2,-1,0)$.\n*   Choose $(l,r)=(3,3)$. Consume $\\max(20)=20$ MP, and the staminas of the monsters are $(0,0,1,-1,0)$.\n*   Choose $(l,r)=(3,3)$. Consume $\\max(20)=20$ MP, and the staminas of the monsters are $(0,0,0,-1,0)$.\n\nHere, he consumes a total of $60+60+40+10+20+20=210$ MP, which is the minimum possible."},{"iden":"sample input 2","content":"1\n1000000000\n1000000000"},{"iden":"sample output 2","content":"1000000000000000000"},{"iden":"sample input 3","content":"10\n522 4575 6426 9445 8772 81 3447 629 3497 7202\n7775 4325 3982 4784 8417 2156 1932 5902 5728 8537"},{"iden":"sample output 3","content":"77917796"}],"translated_statement":null,"sample_group":[],"show_order":["default"],"formal_statement":null,"simple_statement":null,"has_page_source":true}