{"problem":{"name":"Takahashi and Animals","description":{"content":"Takahashi is with $N$ animals. The $N$ animals are called Animal $1$, Animal $2$, $\\ldots$, Animal $N$. Takahashi will perform the following $N$ kinds of action. Each action can be performed any numbe","description_type":"Markdown"},"platform":"AtCoder","limit":{"time_limit":2000,"memory_limit":262144},"difficulty":"None","is_remote":true,"is_sync":true,"sync_url":null,"sign":"abc251_e"},"statements":[{"statement_type":"Markdown","content":"Takahashi is with $N$ animals. The $N$ animals are called Animal $1$, Animal $2$, $\\ldots$, Animal $N$.\nTakahashi will perform the following $N$ kinds of action. Each action can be performed any number of (possibly zero) times.\n\n*   Pay $A_1$ yen (the currency in Japan) to feed Animals $1$ and $2$.\n*   Pay $A_2$ yen to feed Animals $2$ and $3$.\n*   Pay $A_3$ yen to feed Animals $3$ and $4$.\n*   $\\cdots$\n*   Pay $A_i$ yen to feed Animals $i$ and $(i+1)$.\n*   $\\cdots$\n*   Pay $A_{N-2}$ yen to feed Animals $(N-2)$ and $(N-1)$.\n*   Pay $A_{N-1}$ yen to feed Animals $(N-1)$ and $N$.\n*   Pay $A_N$ yen to feed Animals $N$ and $1$.\n\nNote that the $N$\\-th action above feeds \"Animals $N$ and $1$.\"\nPrint the minimum possible total cost to feed every animal at least once.\n\n## Constraints\n\n*   $2 \\leq N \\leq 3 \\times 10^5$\n*   $1 \\leq A_i \\leq 10^9$\n*   All values in input are integers.\n\n## Input\n\nInput is given from Standard Input in the following format:\n\n$N$\n$A_1$ $A_2$ $\\ldots$ $A_N$\n\n[samples]","is_translate":false,"language":"English"}],"meta":{"iden":"abc251_e","tags":[],"sample_group":[["5\n2 5 3 2 5","7\n\nIf Takahashi performs the $1$\\-st, $3$\\-rd, and $4$\\-th actions once each, Animals $1$, $2$, $3$, $4$, and $5$ are fed once, once, once, twice, once, respectively, so every animal is fed at least once. The total cost to do so is $A_1 + A_3 + A_4 = 2 + 3 + 2 = 7$ yen, which is the minimum possible."],["20\n29 27 79 27 30 4 93 89 44 88 70 75 96 3 78 39 97 12 53 62","426"]],"created_at":"2026-03-03 11:01:14"}}