{"raw_statement":[{"iden":"problem statement","content":"Given are two sequences of length $N$ each: $A = (A_1, A_2, A_3, \\dots, A_N)$ and $B = (B_1, B_2, B_3, \\dots, B_N)$.  \nDetermine whether it is possible to make $A$ equal $B$ by repeatedly doing the operation below (possibly zero times). If it is possible, find the minimum number of operations required to do so.\n\n*   Choose an integer $i$ such that $1 \\le i \\lt N$, and do the following in order:\n    *   swap $A_i$ and $A_{i + 1}$;\n    *   add $1$ to $A_i$;\n    *   subtract $1$ from $A_{i + 1}$."},{"iden":"constraints","content":"*   $2 \\le N \\le 2 \\times 10^5$\n*   $0 \\le A_i \\le 10^9$\n*   $0 \\le B_i \\le 10^9$\n*   All values in input are integers."},{"iden":"input","content":"Input is given from Standard Input in the following format:\n\n$N$\n$A_1$ $A_2$ $A_3$ $\\dots$ $A_N$\n$B_1$ $B_2$ $B_3$ $\\dots$ $B_N$"},{"iden":"sample input 1","content":"3\n3 1 4\n6 2 0"},{"iden":"sample output 1","content":"2\n\nWe can match $A$ with $B$ in two operations, as follows:\n\n*   First, do the operation with $i = 2$, making $A = (3, 5, 0)$.\n*   Next, do the operation with $i = 1$, making $A = (6, 2, 0)$.\n\nWe cannot meet our objective in one or fewer operations."},{"iden":"sample input 2","content":"3\n1 1 1\n1 1 2"},{"iden":"sample output 2","content":"\\-1\n\nIn this case, it is impossible to match $A$ with $B$."},{"iden":"sample input 3","content":"5\n5 4 1 3 2\n5 4 1 3 2"},{"iden":"sample output 3","content":"0\n\n$A$ may equal $B$ before doing any operation."},{"iden":"sample input 4","content":"6\n8 5 4 7 4 5\n10 5 6 7 4 1"},{"iden":"sample output 4","content":"7"}],"translated_statement":null,"sample_group":[],"show_order":["default"],"formal_statement":null,"simple_statement":null,"has_page_source":true}