{"trustable":false,"prependHtml":"\u003cstyle type\u003d\u0027text/css\u0027\u003e\n .input, .output {\n border: 1px solid #888888;\n }\n .output {\n margin-bottom: 1em;\n position: relative;\n top: -1px;\n }\n .output pre, .input pre {\n background-color: #EFEFEF;\n line-height: 1.25em;\n margin: 0;\n padding: 0.25em;\n }\n \u003c/style\u003e\n \u003clink rel\u003d\"stylesheet\" href\u003d\"//codeforces.org/s/96598/css/problem-statement.css\" type\u003d\"text/css\" /\u003e\u003cscript\u003e window.katexOptions \u003d { disable: true }; \u003c/script\u003e\n\u003cscript type\u003d\"text/x-mathjax-config\"\u003e\n MathJax.Hub.Config({\n tex2jax: {\n inlineMath: [[\u0027$$$\u0027,\u0027$$$\u0027], [\u0027$\u0027,\u0027$\u0027]],\n displayMath: [[\u0027$$$$$$\u0027,\u0027$$$$$$\u0027], [\u0027$$\u0027,\u0027$$\u0027]]\n }\n });\n\u003c/script\u003e\n\u003cscript type\u003d\"text/javascript\" async src\u003d\"https://mathjax.codeforces.org/MathJax.js?config\u003dTeX-AMS_HTML-full\"\u003e\u003c/script\u003e","sections":[{"title":"","value":{"format":"MD","content":"Một ngôi nhà có $n$ căn phòng đánh số từ $1$ đến $n$ và một con chuột duy nhất. Nhiệm vụ của bạn là phải bắt được con thuộc này bằng cách đặt bẫy ở một số căn phòng. Việc đặt bẫy ở căn phòng thứ $i$ sẽ mất một khoản tiền là $c_i$ đồng.\nCon chuột sẽ luôn di chuyển sang các phòng khác nhau theo một quy tắc. Nếu con chuột đang ở phòng thứ $i$ trong thời gian $t$ thì ở thời gian $t+1$ con chuột sẽ chạy tới phòng thứ $a_i$ ($i\u003da_i$ tức là con chuột sẽ chỉ loanh quanh trong phòng $i$). Nếu con chuột chạy vào bất kỳ phòng nào có chứa bẫy, con chuột sẽ bị bắt ngay tại thời điểm đó.\nViệc bắt chuột có vẻ dễ dàng nếu ta biết vị trí bắt đầu của nó ở đâu nhưng đáng tiếc là không. Con chuột có thể bắt đầu ở bất kỳ căn phòng nào trong các căn phòng từ $1$ đến $n$ tại thời điểm $0$.\nNhiệm vụ của bạn là hãy đặt bẫy sao cho con chuột sẽ bị bắt trong thời điểm hữu hạn nào đó với số tiển đặt bẫy là ít nhất."}},{"title":"Input","value":{"format":"MD","content":"Dòng đầu tiên chứa số nguyên $n$ ($1 \u003c\u003d n \u003c\u003d 2.10^5$) \nDòng thứ hai chứa dãy $c_1, c_2, ..., c_n$ ($1 \u003c\u003d c_i \u003c\u003d 10^4$)\nDòng thứ ba chứa dãy $a_1, a_2, ..., a_n$ ($1 \u003c\u003d a_i \u003c\u003d n$)"}},{"title":"Output","value":{"format":"MD","content":"In ra một số nguyên duy nhất là số tiền ít nhất phải bỏ ra để bắt được chuột trong thời điểm hữu hạn."}},{"title":"Examples","value":{"format":"MD","content":"\u003cdiv class\u003d\"sample-test\"\u003e\n \u003cdiv class\u003d\"input\"\u003e\n \u003cdiv class\u003d\"title\"\u003e\n Input\n \u003c/div\u003e\n \u003cpre\u003e5\u003cbr\u003e1 2 3 2 10\u003cbr\u003e1 3 4 3 3\u003cbr\u003e\u003c/pre\u003e\n \u003c/div\u003e\n \u003cdiv class\u003d\"output\"\u003e\n \u003cdiv class\u003d\"title\"\u003e\n Output\n \u003c/div\u003e\n \u003cpre\u003e3\u003cbr\u003e\u003c/pre\u003e\n \u003c/div\u003e\n \u003cdiv class\u003d\"input\"\u003e\n \u003cdiv class\u003d\"title\"\u003e\n Input\n \u003c/div\u003e\n \u003cpre\u003e4\u003cbr\u003e1 10 2 10\u003cbr\u003e2 4 2 2\u003cbr\u003e\u003c/pre\u003e\n \u003c/div\u003e\n \u003cdiv class\u003d\"output\"\u003e\n \u003cdiv class\u003d\"title\"\u003e\n Output\n \u003c/div\u003e\n \u003cpre\u003e10\u003cbr\u003e\u003c/pre\u003e\n \u003c/div\u003e\n \u003cdiv class\u003d\"input\"\u003e\n \u003cdiv class\u003d\"title\"\u003e\n Input\n \u003c/div\u003e\n \u003cpre\u003e7\u003cbr\u003e1 1 1 1 1 1 1\u003cbr\u003e2 2 2 3 6 7 6\u003cbr\u003e\u003c/pre\u003e\n \u003c/div\u003e\n \u003cdiv class\u003d\"output\"\u003e\n \u003cdiv class\u003d\"title\"\u003e\n Output\n \u003c/div\u003e\n \u003cpre\u003e2\u003cbr\u003e\u003c/pre\u003e\n \u003c/div\u003e\n\u003c/div\u003e"}},{"title":"Note","value":{"format":"MD","content":"Ở ví dụ đầu tiên, ta sẽ đặt bẫy ở phòng $1$ và $4$.\nỞ ví dụ thứ hai, ta đặt bẫy ở phòng $2$.\nỞ ví dụ thứ ba, ta đặt bẫy ở phòng $2$ và $6$."}}]}