This is the easier version of the problem. In this version, $1 \le n \le 10^5$ and $0 \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 $n$ boxes of chocolate, numbered from $1$ to $n$. Initially, the $i$-th box contains $a_i$ chocolate pieces.
Since Bob is a typical nice guy, he will not send Alice $n$ empty boxes. In other words, at least one of $a_1, a_2, \ldots, a_n$ is positive. Since Alice dislikes coprime sets, she will be happy only if there exists some integer $k > 1$ such that the number of pieces in each box is divisible by $k$. 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 $i$ and put it into either box $i-1$ or box $i+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.
-----Input-----
The first line contains a single integer $n$ ($1 \le n \le 10^5$) — the number of chocolate boxes.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($0 \le a_i \le 1$) — the number of chocolate pieces in the $i$-th box.
It is guaranteed that at least one of $a_1, a_2, \ldots, a_n$ is positive.
-----Output-----
If there is no way for Charlie to make Alice happy, print $-1$.
Otherwise, print a single integer $x$ — the minimum number of seconds for Charlie to help Bob make Alice happy.
-----Examples-----
Input
3
1 0 1
Output
2
Input
1
1
Output
-1
n = int(input())
a = list(map(int,input().split()))
if sum(a) == 1:
  print(-1)
  return
sm = sum(a)
nmax = 10**5+10
eratos = [0 for i in range(nmax+1)]
prime = []
cnt = 2
while True:
  while cnt <= nmax and eratos[cnt]:
    cnt += 1
  if cnt > nmax:
    break
  eratos[cnt] = 1
  prime.append(cnt)
  for i in range(cnt**2,nmax+1,cnt):
    eratos[i] = 1
dvls = []
for i in prime:
  if sm%i == 0:
    dvls.append(i)
ansls = []
ls = []
cnti = 0
for dv in dvls:
  ans = 0
  if dv == 2:
    for i in range(n):
      if a[i]:
        cnti += 1
        if cnti%2:
          pivot = i
        else:
          ans += i-pivot
  else:
    for i in range(n):
      if a[i]:
        cnti += 1
        if 1 <= cnti%dv <= dv//2:
          ls.append(i)
        elif cnti%dv == dv//2+1:
          pivot = i
          for j in ls:
            ans += pivot-j
          ls.clear()
        else:
          ans += i-pivot
  ansls.append(ans)
print(min(ansls))
n = int(input())
a = list(map(int,input().split()))
if sum(a) == 1:
  print(-1)
  return
sm = sum(a)
nmax = 10**5+10
eratos = [0 for i in range(nmax+1)]
prime = []
cnt = 2
while True:
  while cnt <= nmax and eratos[cnt]:
    cnt += 1
  if cnt > nmax:
    break
  eratos[cnt] = 1
  prime.append(cnt)
  for i in range(cnt**2,nmax+1,cnt):
    eratos[i] = 1
dvls = []
for i in prime:
  if sm%i == 0:
    dvls.append(i)
ansls = []
ls = []
cnti = 0
for dv in dvls:
  ans = 0
  if dv == 2:
    for i in range(n):
      if a[i]:
        cnti += 1
        if cnti%2:
          pivot = i
        else:
          ans += i-pivot
  else:
    for i in range(n):
      if a[i]:
        cnti += 1
        if 1 <= cnti%dv <= dv//2:
          ls.append(i)
        elif cnti%dv == dv//2+1:
          pivot = i
          for j in ls:
            ans += pivot-j
          ls.clear()
        else:
          ans += i-pivot
  ansls.append(ans)
print(min(ansls))