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;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值