New Year is coming in Line World! In this world, there are n cells numbered by integers from 1 to n, as a 1 × n board. People live in cells. However, it was hard to move between distinct cells, because of the difficulty of escaping the cell. People wanted to meet people who live in other cells.

So, user tncks0121 has made a transportation system to move between these cells, to celebrate the New Year. First, he thought of n - 1 positive integers a1, a2, ..., an - 1. For every integer i where 1 ≤ i ≤ n - 1 the condition 1 ≤ ai ≤ n - i holds. Next, he made n - 1 portals, numbered by integers from 1 to n - 1. The i-th (1 ≤ i ≤ n - 1) portal connects cell i and cell (i + ai), and one can travel from cell i to cell (i + ai) using the i-th portal. Unfortunately, one cannot use the portal backwards, which means one cannot move from cell (i + ai) to cell i using the i-th portal. It is easy to see that because of condition 1 ≤ ai ≤ n - i one can't leave the Line World using portals.

Currently, I am standing at cell 1, and I want to go to cell t. However, I don't know whether it is possible to go there. Please determine whether I can go to cell tby only using the construted transportation system.

Input

The first line contains two space-separated integers n (3 ≤ n ≤ 3 × 104) and t (2 ≤ t ≤ n) — the number of cells, and the index of the cell which I want to go to.

The second line contains n - 1 space-separated integers a1, a2, ..., an - 1 (1 ≤ ai ≤ n - i). It is guaranteed, that using the given transportation system, one cannot leave the Line World.

Output

If I can go to cell t using the transportation system, print "YES". Otherwise, print "NO".

Examples

Input

8 4
1 2 1 2 1 2 1

Output

YES

Input

8 5
1 2 1 2 1 1 1

Output

NO

Note

In the first sample, the visited cells are: 1, 2, 4; so we can successfully visit the cell 4.

In the second sample, the possible cells to visit are: 1, 2, 4, 6, 7, 8; so we can't visit the cell 5, which we want to visit.

题解:模拟更新可以到达的位置,然后加上该位置下标的值

代码:

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream> using namespace std; int main() {
int n,m;
cin>>n>>m;
int a[30005];
for(int t=1; t<=n-1; t++) {
scanf("%d",&a[t]);
}
int flag=0;
for(int t=1; t<n;) {
t=t+a[t];
//cout<<t<<endl;
if(t==m) {
flag=1;
}
} if(flag==1) {
cout<<"YES"<<endl;
} else {
cout<<"NO"<<endl;
}
return 0;
}

最新文章

  1. 64位系统装oracle(ora-12154 )
  2. mysql root用户 远程登录其它机器,看不到数据库
  3. 纯css3圆角下拉菜单 都没敢用js
  4. 支付宝api教程,支付宝根据交易号自动充值
  5. 关于css中透明度继承的问题
  6. CF 322A Ciel and Dancing 好简单的题。。最喜欢水题了
  7. Python学习--15 日期和时间
  8. python学习笔记(一)元组tuple
  9. EBS系统启动&amp;停止&amp;增加表空间&amp;替换首页图片
  10. Springmvc 并发访问的线程安全性问题
  11. T-SQL基础(五)之增删改
  12. Mergeable Stack(链表实现栈)
  13. 2.3.7synchronized代码块有volatile同步的功能
  14. 记录Linux中遇到的技巧
  15. winform 与百度搜索智能提示
  16. STM32 CRC-32 Calculator Unit
  17. MIUI7,Android版本5.0.2,一个程序发送自定义广播,另一个程序没有接收到
  18. JS常见的几种数组去重方法
  19. Mysql SQL 优化
  20. LoadRunner 事物

热门文章

  1. JAVA- 成员变量与局部变量的区别
  2. 基于深度学习的目标检测算法:SSD——常见的目标检测算法
  3. jquery操作全选、批量删除、加减行
  4. POJ2349(求生成树中符合题意的边)
  5. Python中datetime的使用和常用时间处理
  6. SpringBoot之导入导出Excel
  7. 【241】◀▶IEW-Unit06
  8. [转]对 td 使用 overflow:hidden; 无效的几点错误认识
  9. [poj2955/nyoj15]括号匹配(区间dp)
  10. [codeforces161D]Distance in Tree(点分治/树形dp)