시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 (추가 시간 없음) 1024 MB31416715255.678%

문제

Alice, after mastering the sieve of Eratosthenes, excitedly created a puzzle game that made use of it.

The rules of the puzzle game are as follows:

  • An array $p_1,p_2,\ldots ,p_N$ is given where all $p_i$ is initially $0$.
  • A target array $t_1,t_2,\ldots ,t_N$ is given. Her goal is to make $p_i=t_i$ for all $1\le i\le N$.
  • Each time, she can perform one of the following two operations:
    • Choose $i$ and increase $p_j$ by $1$ for every $1\le j\le N$ that is a multiple of $i$.
    • Choose $i$ and decrease $p_j$ by $1$ for every $1\le j\le N$ that is a multiple of $i$.
  • She can repeat this process as much as she wants.

Alice aims to solve the puzzle using the fewest operations, showcasing her puzzle-solving skill. Please help Alice find the minimum number of operations to solve the puzzle.

입력

The first line contains one integer, $N$.

The second line contains space-separated $N$ integers — elements of the array $t$.

출력

Print out the minimum number of operations to solve the puzzle. If the puzzle is unsolvable, print -1.

제한

  • $1\le N\le 200\, 000$
  • $-10^9\le t_i\le 10^9\ (1\le i\le N)$
  • All values in the input are integers.

예제 입력 1

4
1 1 1 0

예제 출력 1

2

예제 입력 2

7
0 1 1 1 0 2 -1

예제 출력 2

3