761B.md (2945B)
1 Source: https://codeforces.com/problemset/problem/761/B 2 3 B. Dasha and friends 4 5 time limit per test 6 7 2 seconds 8 9 memory limit per test 10 11 256 megabytes 12 13 input 14 15 standard input 16 17 output 18 19 standard output 20 21 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: 22 23 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. 24 25 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. 26 27  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]. 28 29 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. 30 31 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. 32 33 Input 34 35 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. 36 37 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. 38 39 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. 40 41 Output 42 43 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). 44 45 Examples 46 47 Input 48 49 ``` 50 3 8 51 2 4 6 52 1 5 7 53 ``` 54 55 Output 56 57 ``` 58 YES 59 ``` 60 61 Input 62 63 ``` 64 4 9 65 2 3 5 8 66 0 1 3 6 67 ``` 68 69 Output 70 71 ``` 72 YES 73 ``` 74 75 Input 76 77 ``` 78 2 4 79 1 3 80 1 2 81 ``` 82 83 Output 84 85 ``` 86 NO 87 ``` 88 89 Note 90 91 The first test is analyzed in the statement.