[关闭]
@xunuo 2017-02-18T21:27:38.000000Z 字数 2835 阅读 1092

Codeforces 761 B Dasha and friends


time limit per test2 seconds memory limit per test256 megabytes

暴力


Description

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 n barriers. 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.

题意:

一个环,上面有n个点,m个点上有障碍物,有两个人去跑步,现在给你他们两个人跑的过程中遇到的障碍物相对于他们的起点而言的位置,问你他们是不是在同一个跑道上;

解题思路:

不管怎么样,只要是他们在同一个跑道上,障碍物;两个点之间的距离肯定是相等的,就转化为看他们之间的距离是否相等;主要是处理的时候......

完整代码:

  1. #include<stdio.h>
  2. #include<string.h>
  3. #include<math.h>
  4. #include<algorithm>
  5. using namespace std;
  6. int a[110],aa[110];
  7. int b[110],bb[110];
  8. int main()
  9. {
  10. int m,n;
  11. while(scanf("%d%d",&m,&n)!=EOF)
  12. {
  13. for(int i=0;i<m;i++)
  14. scanf("%d",&a[i]);
  15. for(int i=0;i<m;i++)
  16. scanf("%d",&b[i]);
  17. for(int i=0;i<m;i++)
  18. {
  19. if(i<m-1)
  20. {
  21. aa[i]=a[i+1]-a[i];
  22. bb[i]=b[i+1]-b[i];
  23. }
  24. else
  25. {
  26. aa[i]=n-a[i]+a[0];
  27. bb[i]=n-b[i]+b[0];
  28. }
  29. }
  30. int flag1,flag2=0;
  31. for(int i=0;i<m;i++)
  32. {
  33. flag1=0;
  34. for(int j=0;j<m;j++)
  35. if(aa[j]!=bb[(i+j)%m])///你模拟一下这个就晓得了
  36. {
  37. flag1=1;
  38. break;
  39. }
  40. if(flag1==0)
  41. {
  42. flag2=1;
  43. break;
  44. }
  45. }
  46. if(flag2==0)
  47. printf("NO\n");
  48. else
  49. printf("YES\n");
  50. }
  51. return 0;
  52. }
添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注