time limit per test2 seconds

memory limit per test256 megabytes

inputstandard input

outputstandard output

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.

【题目链接】:http://codeforces.com/contest/761/problem/B

【题解】



给你两个环,问你能不能改变开始位置,逆时针转,使得两人遇到障碍物离初始点的距离构成的序列相同;

第一个人不动,改变第二个人的开始位置;看看在路上遇到的障碍物构成的序列和不和第一个相同;不同则继续枚举;

复杂度O(L^2)



【完整代码】

#include <bits/stdc++.h>
using namespace std; const int MAXN = 50+10;
const int MAXL = 100+10; int n,l;
int a[MAXN],b[MAXN],c[MAXN];
bool bo[MAXL]; void youjie()
{
puts("YES");
exit(0);
} bool ok()
{
for (int i = 1;i <= n;i++)
if (a[i]!=c[i])
return false;
return true;
} int main()
{
//freopen("F:\\rush.txt","r",stdin);
cin >> n >> l;
for (int i = 1;i <= n;i++)
cin >> a[i];
for (int i = 1;i <= n;i++)
{
cin >> b[i];
c[i] = b[i];
bo[b[i]] = true;
}
if (ok())
youjie();
for (int i = 1;i <= l-1;i++)
{
int num = 0,cnt = 0;
int j = i;
while (num < n)
{
if (bo[j])
c[++num] = cnt;
cnt++;
j++;
if (j==l)
j = 0;
}
if (ok())
youjie();
}
puts("NO");
return 0;
}

【codeforces 761B】Dasha and friends的更多相关文章

  1. 【codeforces 761A】Dasha and Stairs

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  2. 【codeforces 761C】Dasha and Password(动态规划做法)

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  3. 【codeforces 761C】Dasha and Password(贪心+枚举做法)

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  4. 【codeforces 761D】Dasha and Very Difficult Problem

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  5. 【codeforces 761E】Dasha and Puzzle

    [题目链接]:http://codeforces.com/contest/761/problem/E [题意] 给你一棵树,让你在平面上选定n个坐标; 使得这棵树的连接关系以二维坐标的形式展现出来; ...

  6. 【codeforces 415D】Mashmokh and ACM(普通dp)

    [codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...

  7. 【codeforces 707E】Garlands

    [题目链接]:http://codeforces.com/contest/707/problem/E [题意] 给你一个n*m的方阵; 里面有k个联通块; 这k个联通块,每个连通块里面都是灯; 给你q ...

  8. 【codeforces 707C】Pythagorean Triples

    [题目链接]:http://codeforces.com/contest/707/problem/C [题意] 给你一个数字n; 问你这个数字是不是某个三角形的一条边; 如果是让你输出另外两条边的大小 ...

  9. 【codeforces 709D】Recover the String

    [题目链接]:http://codeforces.com/problemset/problem/709/D [题意] 给你一个序列; 给出01子列和10子列和00子列以及11子列的个数; 然后让你输出 ...

随机推荐

  1. org.hibernate.PropertyAccessException: Null value was assigned to a property of primitive type setter of com.trs.om.bean.User.retryCount

    六月 29, 2019 5:42:45 下午 org.apache.catalina.core.AprLifecycleListener init信息: The APR based Apache To ...

  2. 二.python数据结构的性能分析

    目录: 1.引言 2.列表 3.字典 一.引言 - 现在大家对 大O 算法和不同函数之间的差异有了了解.本节的目标是告诉你 Python 列表和字典操作的 大O 性能.然后我们将做一些基于时间的实验来 ...

  3. Spring → 《Spring程序开发》教材大纲

  4. Directx11教程(31) 纹理映射(1)

    原文:Directx11教程(31) 纹理映射(1)         在前面的例子中,我们要么是直接给顶点赋颜色值,要么是在顶点属性中设置Diffuse和Specular系数,从而根据光照参数计算得到 ...

  5. 杨柳目-杨柳科-Info-新闻:注意了!杨絮解决有办法了

    ylbtech-杨柳目-杨柳科-Info-新闻:注意了!杨絮解决有办法了  1.返回顶部 1. 注意了!杨絮解决有办法了 2018-05-03 14:18 昨天中午经过一个理发店,门口蹲了个染黄发.系 ...

  6. mysql设置text字段为not null,并且没有默认值,插入报错:doesn't have a default value

    一.问题描述 在往数据库写入数据的时候,报错: '字段名' doesn't have a default value 本来这个错误是经常见到的,无非就是字段没有设置默认值造成的.奇怪的是,我这边报错的 ...

  7. JAVA中this的三种用法的详解

    this关键字必须放在非静态方法里面 this关键字代表自身,在程序中主要的使用用途有以下几个方面: ? 使用this关键字引用成员变量 ? 使用this关键字在自身构造方法内部引用其它构造方法 ? ...

  8. python 异常处理技巧

  9. sql:mysql:函数:TIMESTAMPDIFF函数实现TimeStamp字段相减,求得时间差

    函数内指定是minute,则最终结果value值的单位是分钟,如果函数内指定为hours,则最终结果value值单位为小时. //UPLOAD_TIME 减去 CREATE_DTTM 求得时间差,以分 ...

  10. 坚守安全第一准则!阿里云接连通过等保2.0测评、ISO国际认证

    斩获新资质 数字时代,数据的安全对于互联网用户来说显得尤为重要.阿里云更是一直坚持“安全第一准则”,致力于为客户的数据安全搭建更健全机制. 2019年5月,阿里云“电子政务云平台系统”正式通过网络安全 ...