CF1254B1.Send Boxes to Alice (Easy Version)

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

This is the easier version of the problem. In this version, 1n1051 \le n \le 10^5 and 0ai10 \le a_i \le 1 . You can hack this problem only if you solve and lock both problems.

Christmas is coming, and our protagonist, Bob, is preparing a spectacular present for his long-time best friend Alice. This year, he decides to prepare nn boxes of chocolate, numbered from 11 to nn . Initially, the ii -th box contains aia_i chocolate pieces.

Since Bob is a typical nice guy, he will not send Alice nn empty boxes. In other words, at least one of a1,a2,,ana_1, a_2, \ldots, a_n is positive. Since Alice dislikes coprime sets, she will be happy only if there exists some integer k>1k > 1 such that the number of pieces in each box is divisible by kk . Note that Alice won't mind if there exists some empty boxes.

Charlie, Alice's boyfriend, also is Bob's second best friend, so he decides to help Bob by rearranging the chocolate pieces. In one second, Charlie can pick up a piece in box ii and put it into either box i1i-1 or box i+1i+1 (if such boxes exist). Of course, he wants to help his friend as quickly as possible. Therefore, he asks you to calculate the minimum number of seconds he would need to make Alice happy.

输入格式

The first line contains a single integer nn ( 1n1051 \le n \le 10^5 ) — the number of chocolate boxes.

The second line contains nn integers a1,a2,,ana_1, a_2, \ldots, a_n ( 0ai10 \le a_i \le 1 ) — the number of chocolate pieces in the ii -th box.

It is guaranteed that at least one of a1,a2,,ana_1, a_2, \ldots, a_n is positive.

输出格式

If there is no way for Charlie to make Alice happy, print 1-1 .

Otherwise, print a single integer xx — the minimum number of seconds for Charlie to help Bob make Alice happy.

输入输出样例

  • 输入#1

    3
    1 0 1
    

    输出#1

    2
    
  • 输入#2

    1
    1
    

    输出#2

    -1
    
首页