{"raw_statement":[{"iden":"problem statement","content":"You are given a permutation $P=(P_1,P_2,\\dots,P_N)$ of $(1,2,\\dots,N)$.\nConsider the following operations $k\\ (k=2,3,\\dots,N)$ on this permutation.\n\n*   Operation $k$: For $i=1,2,\\dots,k-1$ in this order, if $P_i > P_{i+1}$, swap the values of the $i$\\-th and $(i+1)$\\-th elements of $P$.\n\nYou are also given a **non-decreasing** sequence $A=(A_1,A_2,\\dots,A_M)\\ (2 \\leq A_i \\leq N)$ of length $M$.\nFor each $i=1,2,\\dots,M$, find the inversion number of $P$ after applying the operations $A_1, A_2, \\dots, A_i$ in this order.\nWhat is the inversion number of a sequence? The inversion number of a sequence $x=(x_1,x_2,\\dots,x_n)$ of length $n$ is the number of pairs of integers $(i,j)\\ (1\\leq i < j \\leq n)$ such that $x_i > x_j$."},{"iden":"constraints","content":"*   $2 \\leq N \\leq 2 \\times 10^5$\n*   $1 \\leq M \\leq 2 \\times 10^5$\n*   $2 \\leq A_i \\leq N$\n*   $P$ is a permutation of $(1,2,\\dots,N)$.\n*   $A_i \\leq A_{i+1}$ for $i=1,2,\\dots,M-1$.\n*   All input values are integers."},{"iden":"input","content":"The input is given from Standard Input in the following format:\n\n$N$\n$P_1$ $P_2$ $\\dots$ $P_N$\n$M$\n$A_1$ $A_2$ $\\dots$ $A_M$"},{"iden":"sample input 1","content":"6\n3 2 4 1 6 5\n2\n4 6"},{"iden":"sample output 1","content":"3\n1\n\nFirst, operation $4$ is performed. During this, $P$ changes as follows: $(3,2,4,1,6,5) \\rightarrow (2,3,4,1,6,5) \\rightarrow (2,3,4,1,6,5) \\rightarrow (2,3,1,4,6,5)$. The inversion number of $P$ afterward is $3$.\nNext, operation $6$ is performed, where $P$ eventually becomes $(2,1,3,4,5,6)$, whose inversion number is $1$."},{"iden":"sample input 2","content":"20\n12 14 16 8 7 15 19 6 18 5 13 9 10 17 4 1 11 20 2 3\n15\n3 4 6 8 8 9 10 12 13 15 18 18 19 19 20"},{"iden":"sample output 2","content":"117\n116\n113\n110\n108\n105\n103\n99\n94\n87\n79\n72\n65\n58\n51"}],"translated_statement":null,"sample_group":[],"show_order":["default"],"formal_statement":null,"simple_statement":null,"has_page_source":true}