Package for this problem was not updated by the problem writer or Codeforces administration after we’ve upgraded the judging servers. To adjust the time limit constraint, solution execution time will be multiplied by 2. For example, if your solution works for 400 ms on judging servers, then value 800 ms will be displayed and used to determine the verdict.

Virtual contest is a way to take part in past contest, as close as possible to participation on time. It is supported only ACM-ICPC mode for virtual contests.
If you've seen these problems, a virtual contest is not for you - solve these problems in the archive.
If you just want to solve some problem from a contest, a virtual contest is not for you - solve this problem in the archive.
Never use someone else's code, read the tutorials or communicate with other person during a virtual contest.

No tag edit access

D. Cows and Cool Sequences

time limit per test

2 secondsmemory limit per test

256 megabytesinput

standard inputoutput

standard outputBessie and the cows have recently been playing with "cool" sequences and are trying to construct some. Unfortunately they are bad at arithmetic, so they need your help!

A pair (*x*, *y*) of positive integers is "cool" if *x* can be expressed as the sum of *y* consecutive integers (not necessarily positive). A sequence (*a*_{1}, *a*_{2}, ..., *a*_{n}) is "cool" if the pairs (*a*_{1}, *a*_{2}), (*a*_{2}, *a*_{3}), ..., (*a*_{n - 1}, *a*_{n}) are all cool.

The cows have a sequence of *n* positive integers, *a*_{1}, *a*_{2}, ..., *a*_{n}. In one move, they may replace some *a*_{i} with any other positive integer (there are no other limits on the new value of *a*_{i}). Determine the smallest number of moves needed to make the resulting sequence cool.

Input

The first line contains a single integer, *n* (2 ≤ *n* ≤ 5000). The next line contains *n* space-separated integers, *a*_{1}, *a*_{2}, ..., *a*_{n} (1 ≤ *a*_{i} ≤ 10^{15}).

Please do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.

Output

A single integer, the minimum number of *a*_{i} that must be changed to make the sequence cool.

Examples

Input

3

6 4 1

Output

0

Input

4

20 6 3 4

Output

2

Note

In the first sample, the sequence is already cool, so we don't need to change any elements. In the second sample, we can change *a*_{2} to 5 and *a*_{3} to 10 to make (20, 5, 10, 4) which is cool. This changes 2 elements.

Codeforces (c) Copyright 2010-2017 Mike Mirzayanov

The only programming contests Web 2.0 platform

Server time: Apr/28/2017 17:17:36 (p1).

Desktop version, switch to mobile version.
User lists

Name |
---|