#P9728. [EC Final 2022] Dining Professors

[EC Final 2022] Dining Professors

题目描述

Prof. Pang invited nn professors to his banquet. The professors sit at a round table. For all ii from 11 to nn, professor ii sits adjacent to professor (imodn)+1(i \bmod n) + 1 and ((i+n2)modn)+1((i + n - 2)\bmod n) + 1.

Prof. Pang prepared nn dishes. There are nn positions on the table. Position ii is in front of professor ii. Professor ii can access only the dishes placed at positions ii, (imodn)+1(i \bmod n) + 1, and ((i+n2)modn)+1((i + n - 2)\bmod n) + 1. Prof. Pang will place exactly one dish at each position.

Among the dishes, aa of them are spicy and nan-a of them are not spicy. Some (possibly 00) professors are unable to have spicy food. If a professor can have spicy food, his/her satisfaction level is the number of dishes (no matter spicy or not) he/she can access. If a professor cannot have spicy food, his/her satisfaction level is the number of not spicy dishes he/she can access.

Prof. Pang knows whether each professor can have spicy food or not. Please help him to arrange the dishes on the table so that the sum of satisfaction levels over all the professors is maximized. Output the maximum sum.

输入格式

The first line contains two integers n,an, a (3n105,0an3\le n\le 10^5, 0\le a\le n).

The second line contains nn integers b1,,bnb_1, \ldots, b_n. bib_i is 00 or 11. bi=1b_i=1 means professor ii can have spicy food. bi=0b_i=0 means professor ii cannot have spicy food.

输出格式

Output one integer representing the answer in one line.

5 2
1 0 1 0 1

13