logo AlgoBeat OnlineJudge
登录 注册

#214213. [ZJCPC 2017] Sequence to Sequence

内存限制:64 MiB 时间限制:2000 ms 标准输入输出
题目类型:VJudge(洛谷) 评测方式:VJudge
上传者: 匿名

题目描述

Chiaki has a sequence . She would like to change it to another sequence using the following operations:

  • choose two indices and (), and add to every nonzero element between the indices and (both inclusive).
  • choose two indices and (), and subtract from every nonzero element between the indices and (both inclusive).

Chiaki would like to know the minimum number of operations needed.

输入格式

There are multiple test cases. The first line of input contains an integer , indicating the number of test cases. For each test case:

The first line contains an integer () -- the length of the sequence.

The second line contains integers ().

The third line contains integers ().

It is guaranteed that the sum of over all test cases does not exceed .

输出格式

For each test case, output an integer denoting the minimum number of operations. If it is impossible to change the sequence, output instead.

样例

样例输入 1

2
5
1 1 1 1 1
2 0 2 0 2
7
3 1 2 3 2 1 4
2 0 0 0 0 0 2

样例输出 1

3
3

数据范围与提示

For the first test case: .