Send Boxes to Alice (Easy Version)
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.
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.
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.
def getAllFactors(x):
    factors = []
    for i in range(1, int(x ** 0.5) + 1):
        if x % i == 0:
            factors.append(i)
            if x // i != i:
                factors.append(x // i)
    return sorted(factors)

def getPrimeFactors(x):
    primeFacs = []
    for f in getAllFactors(x):
        if len(getAllFactors(f)) == 2:
            primeFacs.append(f)
    return primeFacs

def main():
    n = int(input())
    a = readIntArr()
    total = sum(a)
    if total <= 1:
        print(-1)
        return
    ans = inf
    for factor in getPrimeFactors(total):
        tempans = 0
        cnt = 0
        indexes = []
        for (i, x) in enumerate(a):
            if x == 1:
                indexes.append(i)
                cnt += 1
                if cnt == factor:
                    medianIndex = indexes[factor // 2]
                    for j in indexes:
                        tempans += abs(j - medianIndex)
                    indexes = []
                    cnt = 0
        ans = min(ans, tempans)
    print(ans)
    return
import sys
input = sys.stdin.buffer.readline

def oneLineArrayPrint(arr):
    print(' '.join([str(x) for x in arr]))

def multiLineArrayPrint(arr):
    print('\n'.join([str(x) for x in arr]))

def multiLineArrayOfArraysPrint(arr):
    print('\n'.join([' '.join([str(x) for x in y]) for y in arr]))

def readIntArr():
    return [int(x) for x in input().split()]

def makeArr(defaultVal, dimensionArr):
    dv = defaultVal
    da = dimensionArr
    if len(da) == 1:
        return [dv for _ in range(da[0])]
    else:
        return [makeArr(dv, da[1:]) for _ in range(da[0])]

def queryInteractive(x, y):
    print('? {} {}'.format(x, y))
    sys.stdout.flush()
    return int(input())

def answerInteractive(ans):
    print('! {}'.format(ans))
    sys.stdout.flush()
inf = float('inf')
MOD = 10 ** 9 + 7
for _abc in range(1):
    main()
import os, sys
from io import BytesIO, IOBase

def main():
    n = int(input())
    a = list(map(int, input().split()))
    su = sum(a)
    if su == 1:
        return -1
    fac = []
    if not su % 2:
        fac.append(2)
    while not su % 2:
        su //= 2
    for i in range(3, int(su ** 0.5) + 1, 2):
        if not su % i:
            fac.append(i)
        while not su % i:
            su //= i
    if su != 1:
        fac.append(su)
    ans = 10 ** 20
    for i in fac:
        (ans1, car) = (0, 0)
        for j in range(n - 1):
            if a[j] + car < 0:
                x = abs(a[j] + car)
                ans1 += x
                car = -x
                continue
            be = (a[j] + car) % i
            ab = i - be
            if ab < be:
                car = -ab
                ans1 += ab
            else:
                car = be
                ans1 += be
        if a[-1] + car < 0:
            ans1 += abs(a[-1] + car)
        ans = min(ans, ans1)
    return ans
BUFSIZE = 8192

class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = 'x' in file.mode or 'r' not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            (self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b'\n') + (not b)
            ptr = self.buffer.tell()
            (self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            (self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode('ascii'))
        self.read = lambda : self.buffer.read().decode('ascii')
        self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
if __name__ == '__main__':
    print(main())
import sys, os, io
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
n = int(input())
a = list(map(int, input().split()))
x = []
for i in range(n):
    if a[i]:
        x.append(i)
l = len(x)
y = [0] * (l + 5)
inf = pow(10, 12) + 1
ans = inf
for i in range(2, l + 5):
    if y[i]:
        continue
    for j in range(i, l + 5, i):
        y[j] = 1
    if l % i:
        continue
    cnt = 0
    for j in range(0, l, i):
        z = [x[k] for k in range(j, i + j)]
        u = list(z)
        for k in range(1, i):
            u[k] += u[k - 1]
        mi = min(u[-1] - u[0] - (i - 1) * z[0], (i - 1) * z[-1] - u[-2])
        for k in range(1, i - 1):
            mi = min(mi, k * z[k] - u[k - 1] + u[-1] - u[k] - (i - k - 1) * z[k])
        cnt += mi
    ans = min(ans, cnt)
ans = (ans + 1) % (inf + 1) - 1
print(ans)