Codeforces Round 673 (Div. 1)
E
Split
Codeforces
3200
原题
← DF →
翻译中…

One day, BThero decided to play around with arrays and came up with the following problem:

翻译中…

You are given an array $a$, which consists of $n$ positive integers. The array is numerated $1$ through $n$. You execute the following procedure exactly once:

翻译中…
  • You create a new array $b$ which consists of $2n$ positive integers, where for each $1 \le i \le n$ the condition $b_{2i-1}+b_{2i} = a_i$ holds. For example, for the array $a = [6, 8, 2]$ you can create $b = [2, 4, 4, 4, 1, 1]$.
  • You merge consecutive equal numbers in $b$. For example, $b = [2, 4, 4, 4, 1, 1]$ becomes $b = [2, 4, 1]$.
翻译中…

Find and print the minimum possible value of $|b|$ (size of $b$) which can be achieved at the end of the procedure. It can be shown that under the given constraints there is at least one way to construct $b$.

翻译中…

Input

翻译中…

The first line of the input file contains a single integer $T$ ($1 \le T \le 5 \cdot 10^5$) denoting the number of test cases. The description of $T$ test cases follows.

翻译中…

The first line of each test contains a single integer $n$ ($1 \le n \le 5 \cdot 10^5$).

翻译中…

The second line contains $n$ space-separated integers $a_1$, $a_2$, ..., $a_n$ ($2 \le a_i \le 10^9$).

翻译中…

It is guaranteed that $\sum{n}$ over all test cases does not exceed $5 \cdot 10^5$.

翻译中…

Output

翻译中…

For each test case, print a single line containing one integer — the minimum possible value of $|b|$.

翻译中…

样例

Input #1
3
3
6 8 2
1
4
3
5 6 6
Output #1
3
1
2
InputCopy OutputCopy
题目信息
题号
1416E
时间限制
2 s
内存限制
256 MB
标签
二分
数据结构
动态规划
贪心

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。