{"trustable":true,"prependHtml":"\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 async src\u003d\"https://mathjax.codeforces.org/MathJax.js?config\u003dTeX-AMS-MML_HTMLorMML\" type\u003d\"text/javascript\"\u003e\u003c/script\u003e","sections":[{"title":"","value":{"format":"HTML","content":"\u003cdiv class\u003d\"panel_content\"\u003eLong long ago, there lived two rabbits Tom and Jerry in the forest. On a sunny afternoon, they planned to play a game with some stones. There were n stones on the ground and they were arranged as a clockwise ring. That is to say, the first stone was adjacent to the second stone and the n-th stone, and the second stone is adjacent to the first stone and the third stone, and so on. The weight of the i-th stone is ai.\u003cbr\u003e\u003cbr\u003eThe rabbits jumped from one stone to another. Tom always jumped clockwise, and Jerry always jumped anticlockwise.\u003cbr\u003e\u003cbr\u003eAt the beginning, the rabbits both choose a stone and stand on it. Then at each turn, Tom should choose a stone which have not been stepped by itself and then jumped to it, and Jerry should do the same thing as Tom, but the jumping direction is anti-clockwise.\u003cbr\u003e\u003cbr\u003eFor some unknown reason, at any time , the weight of the two stones on which the two rabbits stood should be equal. Besides, any rabbit couldn\u0027t jump over a stone which have been stepped by itself. In other words, if the Tom had stood on the second stone, it cannot jump from the first stone to the third stone or from the n-the stone to the 4-th stone.\u003cbr\u003e\u003cbr\u003ePlease note that during the whole process, it was OK for the two rabbits to stand on a same stone at the same time. \u003cbr\u003e\u003cbr\u003eNow they want to find out the maximum turns they can play if they follow the optimal strategy.\u003c/div\u003e"}},{"title":"Input","value":{"format":"HTML","content":"The input contains at most 20 test cases.\u003cbr\u003eFor each test cases, the first line contains a integer n denoting the number of stones.\u003cbr\u003eThe next line contains n integers separated by space, and the i-th integer ai denotes the weight of the i-th stone.(1 \u0026lt;\u003d n \u0026lt;\u003d 1000, 1 \u0026lt;\u003d ai \u0026lt;\u003d 1000)\u003cbr\u003eThe input ends with n \u003d 0."}},{"title":"Output","value":{"format":"HTML","content":"For each test case, print a integer denoting the maximum turns."}},{"title":"Sample","value":{"format":"HTML","content":"\u003ctable class\u003d\u0027vjudge_sample\u0027\u003e\n\u003cthead\u003e\n \u003ctr\u003e\n \u003cth\u003eInput\u003c/th\u003e\n \u003cth\u003eOutput\u003c/th\u003e\n \u003c/tr\u003e\n\u003c/thead\u003e\n\u003ctbody\u003e\n \u003ctr\u003e\n \u003ctd\u003e\u003cpre\u003e1\r\n1\r\n4\r\n1 1 2 1\r\n6\r\n2 1 1 2 1 3\r\n0\r\n\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003e1\r\n4\r\n5\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n"}},{"title":"Hint","value":{"format":"HTML","content":"\u003cbr\u003eFor the second case, the path of the Tom is 1, 2, 3, 4, and the path of Jerry is 1, 4, 3, 2.\u003cbr\u003eFor the third case, the path of Tom is 1,2,3,4,5 and the path of Jerry is 4,3,2,1,5.\u003cbr\u003e"}}]}