{"problem":{"name":"Tree Burning","description":{"content":"Takahashi Lake has a perimeter of $L$. On the circumference of the lake, there is a residence of the lake's owner, Takahashi. Each point on the circumference of the lake has a coordinate between $0$ a","description_type":"Markdown"},"platform":"AtCoder","limit":{"time_limit":2000,"memory_limit":262144},"difficulty":"None","is_remote":true,"is_sync":true,"sync_url":null,"sign":"agc030_b"},"statements":[{"statement_type":"Markdown","content":"Takahashi Lake has a perimeter of $L$. On the circumference of the lake, there is a residence of the lake's owner, Takahashi. Each point on the circumference of the lake has a coordinate between $0$ and $L$ (including $0$ but not $L$), which is the distance from the Takahashi's residence, measured counter-clockwise.\nThere are $N$ trees around the lake; the coordinate of the $i$\\-th tree is $X_i$. There is no tree at coordinate $0$, the location of Takahashi's residence.\nStarting at his residence, Takahashi will repeat the following action:\n\n*   If all trees are burnt, terminate the process.\n*   Specify a direction: clockwise or counter-clockwise.\n*   Walk around the lake in the specified direction, until the coordinate of a tree that is not yet burnt is reached for the first time.\n*   When the coordinate with the tree is reached, burn that tree, stay at the position and go back to the first step.\n\nFind the longest possible total distance Takahashi walks during the process.\n\n## Constraints\n\n*   $2 \\leq L \\leq 10^9$\n*   $1 \\leq N \\leq 2\\times 10^5$\n*   $1 \\leq X_1 < ... < X_N \\leq L-1$\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$\n$X_1$\n$:$\n$X_N$\n\n## Partial Score\n\nA partial score can be obtained in this problem:\n\n*   $300$ points will be awarded for passing the input satisfying $N \\leq 2000$.\n\n[samples]","is_translate":false,"language":"English"}],"meta":{"iden":"agc030_b","tags":[],"sample_group":[["10 3\n2\n7\n9","15\n\nTakahashi walks the distance of $15$ if the process goes as follows:\n\n*   Walk a distance of $2$ counter-clockwise, burn the tree at the coordinate $2$ and stay there.\n*   Walk a distance of $5$ counter-clockwise, burn the tree at the coordinate $7$ and stay there.\n*   Walk a distance of $8$ clockwise, burn the tree at the coordinate $9$ and stay there."],["10 6\n1\n2\n3\n6\n7\n9","27"],["314159265 7\n21662711\n77271666\n89022761\n156626166\n160332356\n166902656\n298992265","1204124749"]],"created_at":"2026-03-03 11:01:14"}}