{"problem":{"name":"Ears","description":{"content":"Snuke stands on a number line. He has $L$ ears, and he will walk along the line continuously under the following conditions: *   He never visits a point with coordinate less than $0$, or a point with","description_type":"Markdown"},"platform":"AtCoder","limit":{"time_limit":2000,"memory_limit":262144},"difficulty":"None","is_remote":true,"is_sync":true,"sync_url":null,"sign":"yahoo_procon2019_qual_d"},"statements":[{"statement_type":"Markdown","content":"Snuke stands on a number line. He has $L$ ears, and he will walk along the line continuously under the following conditions:\n\n*   He never visits a point with coordinate less than $0$, or a point with coordinate greater than $L$.\n*   He starts walking at a point with integer coordinate, and also finishes walking at a point with integer coordinate.\n*   He only changes direction at a point with integer coordinate.\n\nEach time when Snuke passes a point with coordinate $i-0.5$, where $i$ is an integer, he put a stone in his $i$\\-th ear.\nAfter Snuke finishes walking, Ringo will repeat the following operations in some order so that, for each $i$, Snuke's $i$\\-th ear contains $A_i$ stones:\n\n*   Put a stone in one of Snuke's ears.\n*   Remove a stone from one of Snuke's ears.\n\nFind the minimum number of operations required when Ringo can freely decide how Snuke walks.\n\n## Constraints\n\n*   $1 \\leq L \\leq 2\\times 10^5$\n*   $0 \\leq A_i \\leq 10^9(1\\leq i\\leq L)$\n*   All values in input are integers.\n\n## Input\n\nInput is given from Standard Input in the following format:\n\n$L$\n$A_1$\n$:$\n$A_L$\n\n[samples]","is_translate":false,"language":"English"}],"meta":{"iden":"yahoo_procon2019_qual_d","tags":[],"sample_group":[["4\n1\n0\n2\n3","1\n\nAssume that Snuke walks as follows:\n\n*   He starts walking at coordinate $3$ and finishes walking at coordinate $4$, visiting coordinates $3,4,3,2,3,4$ in this order.\n\nThen, Snuke's four ears will contain $0,0,2,3$ stones, respectively. Ringo can satisfy the requirement by putting one stone in the first ear."],["8\n2\n0\n0\n2\n1\n3\n4\n1","3"],["7\n314159265\n358979323\n846264338\n327950288\n419716939\n937510582\n0","1"]],"created_at":"2026-03-03 11:01:14"}}