题干:

Running with barriers on the circle track is very popular in the country where Dasha lives, so no wonder that on her way to classes she saw the following situation:

The track is the circle with length L, in distinct points of which there are nbarriers. Athlete always run the track in counterclockwise direction if you look on him from above. All barriers are located at integer distance from each other along the track.

Her friends the parrot Kefa and the leopard Sasha participated in competitions and each of them ran one lap. Each of the friends started from some integral point on the track. Both friends wrote the distance from their start along the track to each of the n barriers. Thus, each of them wrote n integers in the ascending order, each of them was between 0 and L - 1, inclusively.

 Consider an example. Let L = 8, blue points are barriers, and green points are Kefa's start (A) and Sasha's start (B). Then Kefa writes down the sequence [2, 4, 6], and Sasha writes down [1, 5, 7].

There are several tracks in the country, all of them have same length and same number of barriers, but the positions of the barriers can differ among different tracks. Now Dasha is interested if it is possible that Kefa and Sasha ran the same track or they participated on different tracks.

Write the program which will check that Kefa's and Sasha's tracks coincide (it means that one can be obtained from the other by changing the start position). Note that they always run the track in one direction — counterclockwise, if you look on a track from above.

Input

The first line contains two integers n and L (1 ≤ n ≤ 50, n ≤ L ≤ 100) — the number of barriers on a track and its length.

The second line contains n distinct integers in the ascending order — the distance from Kefa's start to each barrier in the order of its appearance. All integers are in the range from 0 to L - 1 inclusively.

The second line contains n distinct integers in the ascending order — the distance from Sasha's start to each barrier in the order of its overcoming. All integers are in the range from 0 to L - 1 inclusively.

Output

Print "YES" (without quotes), if Kefa and Sasha ran the coinciding tracks (it means that the position of all barriers coincides, if they start running from the same points on the track). Otherwise print "NO" (without quotes).

Examples

Input

3 8
2 4 6
1 5 7

Output

YES

Input

4 9
2 3 5 8
0 1 3 6

Output

YES

Input

2 4
1 3
1 2

Output

NO

Note

The first test is analyzed in the statement.

题目大意:

   有两个人分别在周长为L的圆上,圆上有n个障碍物,两个人分别以逆时针的方向告诉你他们各自距离各个障碍物的距离,问他们是否在同一个圆上

解题报告:

    构造一个方法来判断是否可以两个圈重合。

   方法是:求出每两个障碍物之间的坐标差,记为ca数组和cb数组,然后o(n)遍历起点,看有没有一种起点,使得ca和cb数组的值均相同。

 

AC代码:

#include<bits/stdc++.h>

using namespace std;
int a[55],b[55];
int ca[55],cb[55];
int main()
{
	int n,mod,flag = 1;
	scanf("%d%d",&n,&mod); 
	for(int i = 1; i<=n; i++) scanf("%d",&a[i]);
	for(int i = 1; i<=n; i++) scanf("%d",&b[i]);
	ca[0] = a[1] + mod-a[n];
	cb[0] = b[1] + mod-b[n];
	for(int i = 2; i<=n; i++) {
		ca[i-1] = a[i]-a[i-1];
		cb[i-1] = b[i]-b[i-1];
	}
	for(int k = 0; k<n; k++) {
		int j = k,cnt=n;
		flag=1;
		for(int i = 0; i<n; i++) {
			if(ca[i] != cb[j]){
				flag=0;break;
			}
			j=(j+1)%n;
		}
		if(flag == 1) break;
	}
	if(flag == 1) {
		printf("YES\n");return 0;
	}
	for(int k = 0; k<n; k++) {
		int j = k,cnt=n;
		flag=1;
		for(int i = n-1; i>=0; i--) {
			if(ca[i] != cb[j]){
				flag=0;break;
			}
			j=(j+1)%n;
		}
		if(flag == 1) break;
	}
	if(flag == 1) {
		printf("YES\n");return 0;
	}
	printf("NO\n");
	return 0 ;
 } 

总结一下:

   注意这样用的话涉及取模操作,凡是涉及取模操作的,都需要从0开始,我们这里也是注意到了这个问题。

 还有一种判断二者相同的方法,可以代替这种o(n)遍历起点的方法,就是:类似字符串匹配处理中的技巧,将ca数组复制一份(即长度变为两倍),然后用一个长度为n的窗口,扫一遍看有没有和cb完全重复的(转成字符串可以也能用kmp)(我记得有一个字符串的题就是需要复制一份然后直接strstr扫一遍就出答案了那种)

代码如下: