Codeforces Round 920 (Div. 3) A B C D E

A. Square

time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
outputL: standard output

A square of positive (strictly greater than 000) area is located on the coordinate plane, with sides parallel to the coordinate axes. You are given the coordinates of its corners, in random order. Your task is to find the area of the square.

Input

Each test consists of several testcases. The first line contains one integer ttt (1≤t≤1001 \le t \le 1001t100) — the number of testcases. The following is a description of the testcases.

Each testcase contains four lines, each line contains two integers xi,yix_i, y_ixi,yi (−1000≤xi,yi≤1000-1000\le x_i, y_i\le 10001000xi,yi1000), coordinates of the corners of the square.

It is guaranteed that there is a square with sides parallel to the coordinate axes, with positive (strictly greater than 000) area, with corners in given points.

Output

For each test case, print a single integer, the area of the square.

Example

input

3
1 2
4 5
1 5
4 2
-1 1
1 -1
1 1
-1 -1
45 11
45 39
17 11
17 39

output

9
4
784

Tutorial

因为给出的四个点围起来是一个边与坐标轴平行的正方形,所以如果 xxx 的值相等,那 yyy 值的差就是边长,如果 yyy 的值相等,那 xxx 值的差就是边长,直接找出一条边的长度即可

Solution

for _ in range(int(input())):
    a = sorted(tuple(map(int, input().split())) for _ in range(4))
    print((a[1][1] - a[0][1]) ** 2)

B. Arranging Cats

time limit per test: 2 second
memory limit per test: 512 megabytes
input: standard input
outputL: standard output

In order to test the hypothesis about the cats, the scientists must arrange the cats in the boxes in a specific way. Of course, they would like to test the hypothesis and publish a sensational article as quickly as possible, because they are too engrossed in the next hypothesis about the phone's battery charge.

Scientists have nnn boxes in which cats may or may not sit. Let the current state of the boxes be denoted by the sequence b1,…,bnb_1, \dots, b_nb1,,bn: bi=1b_i = 1bi=1 if there is a cat in box number iii, and bi=0b_i = 0bi=0 otherwise.

Fortunately, the unlimited production of cats has already been established, so in one day, the scientists can perform one of the following operations:

  • Take a new cat and place it in a box (for some iii such that bi=0b_i = 0bi=0, assign bi=1b_i = 1bi=1).
  • Remove a cat from a box and send it into retirement (for some iii such that bi=1b_i = 1bi=1, assign bi=0b_i = 0bi=0).
  • Move a cat from one box to another (for some i,ji, ji,j such that bi=1,bj=0b_i = 1, b_j = 0bi=1,bj=0, assign bi=0,bj=1b_i = 0, b_j = 1bi=0,bj=1).

It has also been found that some boxes were immediately filled with cats. Therefore, the scientists know the initial position of the cats in the boxes s1,…,sns_1, \dots, s_ns1,,sn and the desired position f1,…,fnf_1, \dots, f_nf1,,fn.

Due to the large amount of paperwork, the scientists do not have time to solve this problem. Help them for the sake of science and indicate the minimum number of days required to test the hypothesis.

Input

Each test consists of several test cases. The first line contains a single integer ttt (1≤t≤1041 \le t \le 10^41t104) — the number of test cases. This is followed by descriptions of the test cases.

Each test case consists of three lines.

The first line of each test case contains a single integer nnn (1≤n≤1051 \le n \le 10^51n105) — the number of boxes.

The second line of each test case contains a string sss of nnn characters, where the iii-th character is ‘1’ if there is a cat in the iii-th box and ‘0’ otherwise.

The third line of each test case contains a string fff of nnn characters, where the iii-th character is ‘1’ if there should be a cat in the iii-th box and ‘0’ otherwise.

It is guaranteed that in a test the sum of nnn over all test cases does not exceed 10510^5105.

Output

For each test case, output a single integer on a separate line — the minimum number of operations required to obtain the desired position from the initial position. It can be shown that a solution always exists.

Example

input

6
5
10010
00001
1
1
1
3
000
111
4
0101
1010
3
100
101
8
10011001
11111110

output

2
0
3
2
1
4

Note

In the first test case, you can first move the cat from the first box to the fifth, and then remove the

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值