A. Single Push

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

You're given two arrays a[1…n]a[1…n] and b[1…n]b[1…n], both of the same length nn.

In order to perform a push operation, you have to choose three integers l,r,kl,r,k satisfying 1≤l≤r≤n1≤l≤r≤n and k>0k>0. Then, you will add kk to elements al,al+1,…,aral,al+1,…,ar.

For example, if a=[3,7,1,4,1,2]a=[3,7,1,4,1,2] and you choose (l=3,r=5,k=2)(l=3,r=5,k=2), the array aa will become [3,7,3,6,3––––––,2][3,7,3,6,3_,2].

You can do this operation at most once. Can you make array aa equal to array bb?

(We consider that a=ba=b if and only if, for every 1≤i≤n1≤i≤n, ai=biai=bi)

Input

The first line contains a single integer tt (1≤t≤201≤t≤20) — the number of test cases in the input.

The first line of each test case contains a single integer nn (1≤n≤100 0001≤n≤100 000) — the number of elements in each array.

The second line of each test case contains nn integers a1,a2,…,ana1,a2,…,an (1≤ai≤10001≤ai≤1000).

The third line of each test case contains nn integers b1,b2,…,bnb1,b2,…,bn (1≤bi≤10001≤bi≤1000).

It is guaranteed that the sum of nn over all test cases doesn't exceed 105105.

Output

For each test case, output one line containing "YES" if it's possible to make arrays aa and bb equal by performing at most once the described operation or "NO" if it's impossible.

You can print each letter in any case (upper or lower).

Example

input

Copy

4
6
3 7 1 4 1 2
3 7 3 6 3 2
5
1 1 1 1 1
1 2 1 3 1
2
42 42
42 42
1
7
6

output

Copy

YES
NO
YES
NO

Note

The first test case is described in the statement: we can perform a push operation with parameters (l=3,r=5,k=2)(l=3,r=5,k=2) to make aa equal to bb.

In the second test case, we would need at least two operations to make aa equal to bb.

In the third test case, arrays aa and bb are already equal.

In the fourth test case, it's impossible to make aa equal to bb, because the integer kk has to be positive.

解题说明:此题是一道模拟题,首先算出两个数组中两个元素的差值,然后遍历判断是否满足条件即可。



#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>

using namespace std;

#define N	100000

int aa[100000], bb[100000];

int main() 
{
	int t;
	scanf("%d", &t);
	while (t--)
	{
		int n, i, a;
		scanf("%d", &n);
		for (i = 0; i < n; i++)
		{
			scanf("%d", &aa[i]);
		}
		for (i = 0; i < n; i++)
		{
			scanf("%d", &bb[i]);
		}
		i = 0;
		while (i < n && aa[i] == bb[i])
		{
			i++;
		}
		if (i == n) 
		{
			printf("YES\n");
			continue;
		}
		a = bb[i] - aa[i];
		if (a < 0) 
		{
			printf("NO\n");
			continue;
		}
		while (i < n && bb[i] - aa[i] == a)
		{
			i++;
		}
		while (i < n && aa[i] == bb[i])
		{
			i++;
		}
		printf(i == n ? "YES\n" : "NO\n");
	}
	return 0;
}
发布了1749 篇原创文章 · 获赞 382 · 访问量 276万+

猜你喜欢

转载自blog.csdn.net/jj12345jj198999/article/details/104135952