306961: CF1278C. Berry Jam

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Berry Jam

题意翻译

- 有 $2n$ 瓶果酱,分为草莓和蓝莓两种,珂朵莉初始站在第 $n$ 瓶和第 $n+1$ 瓶之间。 - 每次她可以吃完她左边第一瓶满的果酱,或者吃完她右边第一瓶满的果酱。 - 你的任务是判断她最少需要吃几瓶果酱才能使草莓和蓝莓果酱数量相等。 - 输入有多组数据,第一行输入一个整数 $T$,表示数据组数。每组数据第一行输入一个整数 $n$,接着输入 $2n$ 个整数。 - 第 $i$ 个整数若为 $1$ 则表示是草莓果酱,若为 $2$ 则表示蓝莓果酱。 - $1 \le n \le 10^5$,所有数据中 $n$ 的和不超过 $10^5$。

题目描述

Karlsson has recently discovered a huge stock of berry jam jars in the basement of the house. More specifically, there were $ 2n $ jars of strawberry and blueberry jam. All the $ 2n $ jars are arranged in a row. The stairs to the basement are exactly in the middle of that row. So when Karlsson enters the basement, he sees exactly $ n $ jars to his left and $ n $ jars to his right. For example, the basement might look like this: ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF1278C/241a083326516b3b4ad70c41dd4440502bf9af7a.png)Being the starightforward man he is, he immediately starts eating the jam. In one minute he chooses to empty either the first non-empty jar to his left or the first non-empty jar to his right. Finally, Karlsson decided that at the end the amount of full strawberry and blueberry jam jars should become the same. For example, this might be the result: ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF1278C/ce4aac0a2c1a17ee1f9a579db06c727cd2163ca6.png)He has eaten $ 1 $ jar to his left and then $ 5 $ jars to his right. There remained exactly $ 3 $ full jars of both strawberry and blueberry jam.Jars are numbered from $ 1 $ to $ 2n $ from left to right, so Karlsson initially stands between jars $ n $ and $ n+1 $ . What is the minimum number of jars Karlsson is required to empty so that an equal number of full strawberry and blueberry jam jars is left? Your program should answer $ t $ independent test cases.

输入输出格式

输入格式


The first line contains one integer $ t $ ( $ 1 \le t \le 1000 $ ) — the number of test cases. The first line of each test case contains a single integer $ n $ ( $ 1 \le n \le 10^5 $ ). The second line of each test case contains $ 2n $ integers $ a_1, a_2, \dots, a_{2n} $ ( $ 1 \le a_i \le 2 $ ) — $ a_i=1 $ means that the $ i $ -th jar from the left is a strawberry jam jar and $ a_i=2 $ means that it is a blueberry jam jar. It is guaranteed that the sum of $ n $ over all test cases does not exceed $ 10^5 $ .

输出格式


For each test case print the answer to it — the minimum number of jars Karlsson is required to empty so that an equal number of full strawberry and blueberry jam jars is left.

输入输出样例

输入样例 #1

4
6
1 1 1 2 2 1 2 1 2 1 1 2
2
1 2 1 2
3
1 1 1 1 1 1
2
2 1 1 1

输出样例 #1

6
0
6
2

说明

The picture from the statement describes the first test case. In the second test case the number of strawberry and blueberry jam jars is already equal. In the third test case Karlsson is required to eat all $ 6 $ jars so that there remain $ 0 $ jars of both jams. In the fourth test case Karlsson can empty either the second and the third jars or the third and the fourth one. The both scenarios will leave $ 1 $ jar of both jams.

Input

题意翻译

- 有 $2n$ 瓶果酱,分为草莓和蓝莓两种,珂朵莉初始站在第 $n$ 瓶和第 $n+1$ 瓶之间。 - 每次她可以吃完她左边第一瓶满的果酱,或者吃完她右边第一瓶满的果酱。 - 你的任务是判断她最少需要吃几瓶果酱才能使草莓和蓝莓果酱数量相等。 - 输入有多组数据,第一行输入一个整数 $T$,表示数据组数。每组数据第一行输入一个整数 $n$,接着输入 $2n$ 个整数。 - 第 $i$ 个整数若为 $1$ 则表示是草莓果酱,若为 $2$ 则表示蓝莓果酱。 - $1 \le n \le 10^5$,所有数据中 $n$ 的和不超过 $10^5$。

加入题单

算法标签: