A. Dr. TC

time limit per test

1 second

memory limit per test

256 megabytes

In order to test his patients' intelligence, Dr. TC created the following test.

First, he creates a binary string∗∗ ss having nn characters. Then, he creates nn binary strings a1,a2,…,ana1,a2,…,an. It is known that aiai is created by first copying ss, then flipping the ii'th character (11 becomes 00 and vice versa). After creating all nn strings, he arranges them into a grid where the ii'th row is aiai.

For example,

  • If s=101s=101, a=[001,111,100]a=[001,111,100].
  • If s=0000s=0000, a=[1000,0100,0010,0001]a=[1000,0100,0010,0001].

The patient needs to count the number of 11s written on the board in less than a second. Can you pass the test?

∗∗A binary string is a string that only consists of characters 11 and 00.

Input

The first line of the input consists of a single integer tt (1≤t≤10001≤t≤1000) — the number of test cases.

The first line of each test case contains a single integer nn (1≤n≤101≤n≤10) — the length of the binary string ss.

The second line of each test case contains a single binary string ss of size nn.

Output

For each test case, output a single integer, the number of 11s on the board.

Example

Input

Copy


5

3

101

1

1

5

00000

2

11

3

010

Output

Copy

5
0
5
2
4

Note

The first example is explained in the statement.

For the second example, the only string written on the board will be the string 00; therefore, the answer is 00.

In the third example, the following strings will be written on the board: [10000,01000,00100,00010,00001][10000,01000,00100,00010,00001]; so there are five 11s written on the board.

解题说明:此题是一道数学题,找规律即可,首先统计出原来数字中包含多少个1,多少个0.翻转后就能发现总的1的数目是(n-1)*(1的个数)+(0的个数)

#include<stdio.h>
int main()
{
	int t;
	scanf("%d", &t);
	while (t--)
	{
		int n, i, num;
		scanf("%d", &n);
		int sum = 0, arr[11];
		scanf("%d", &num);
		for (i = 0; i < n; i++)
		{
			arr[i] = num % 10;
			sum += arr[i];
			num /= 10;
		}
		printf("%d\n", (sum * n) + n - (2 * sum));
	}
	return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值