{"raw_statement":[{"iden":"problem statement","content":"Takahashi is a martial artist. There are $N$ moves that a martial artist can learn, called Move $1$, $2$, $\\ldots$, $N$. For each $1 \\leq i \\leq N$, it takes $T_i$ minutes of practice to learn Move $i$. Additionally, at the beginning of that practice, all of the Moves $A_{i,1}$, $A_{i,2}$, $\\ldots$, $A_{i,K_i}$ must be already learned. Here, it is guaranteed that $A_{i,j} < i$ for each $1 \\leq j \\leq K_i$.\nTakahashi has not learned any move at time $0$. He cannot practice for more than one move simultaneously, nor can he stop a practice he has already started. Find the minimum number of minutes needed for Takahashi to learn Move $N$."},{"iden":"constraints","content":"*   $1 \\leq N \\leq 2\\times 10^5$\n*   $1 \\leq T_i \\leq 10^9$\n*   $0 \\leq K_i < i$\n*   $1 \\leq A_{i,j} < i$\n*   $\\sum_{i=1}^N K_i \\leq 2\\times 10^5$\n*   $A_{i,1}$, $A_{i,2}$, $\\ldots$, $A_{i,K_i}$ are all distinct.\n*   All values in input are integers."},{"iden":"input","content":"Input is given from Standard Input in the following format:\n\n$N$\n$T_1$ $K_1$ $A_{1,1}$ $A_{1,2}$ $\\ldots$ $A_{1,K_1}$\n$T_2$ $K_2$ $A_{2,1}$ $A_{2,2}$ $\\ldots$ $A_{2,K_2}$\n$\\vdots$\n$T_N$ $K_N$ $A_{N,1}$ $A_{N,2}$ $\\ldots$ $A_{N,K_N}$"},{"iden":"sample input 1","content":"3\n3 0\n5 1 1\n7 1 1"},{"iden":"sample output 1","content":"10\n\nHere is one possible plan for Takahashi.\n\n*   At time $0$, start practicing for Move $1$ to learn Move $1$ at time $3$.\n*   Then, at time $3$, start practicing for Move $3$ to learn Move $3$ at time $10$.\n\nHere, Takahashi spends $3+7=10$ minutes to learn Move $3$, which is the fastest possible. Note that he does not need to learn Move $2$ to learn Move $3$."},{"iden":"sample input 2","content":"5\n1000000000 0\n1000000000 0\n1000000000 0\n1000000000 0\n1000000000 4 1 2 3 4"},{"iden":"sample output 2","content":"5000000000\n\nNote that the answer may not fit into a $32$\\-bit integer."}],"translated_statement":null,"sample_group":[],"show_order":["default"],"formal_statement":null,"simple_statement":null,"has_page_source":true}