While swimming at the beach, Mike has accidentally dropped his cellphone into the water. There was no worry as he bought a cheap replacement phone with an old-fashioned keyboard. The keyboard has only ten digital equal-sized keys, located in the following way:

Together with his old phone, he lost all his contacts and now he can only remember the way his fingers moved when he put some number in. One can formally consider finger movements as a sequence of vectors connecting centers of keys pressed consecutively to put in a number. For example, the finger movements for number "586" are the same as finger movements for number "253":

Mike has already put in a number by his "finger memory" and started calling it, so he is now worrying, can he be sure that he is calling the correct number? In other words, is there any other number, that has the same finger movements?

Input

The first line of the input contains the only integer n (1 ≤ n ≤ 9) — the number of digits in the phone number that Mike put in.

The second line contains the string consisting of n digits (characters from '0' to '9') representing the number that Mike put in.

Output

If there is no other phone number with the same finger movements and Mike can be sure he is calling the correct number, print "YES" (without quotes) in the only line.

Otherwise print "NO" (without quotes) in the first line.

Examples
Input
3
586
Output
NO
Input
2
09
Output
NO
Input
9
123456789
Output
YES
Input
3
911
Output
YES
Note

You can find the picture clarifying the first sample case in the statement above.

题意:给定一个0-9的数字键盘,随后输入一个操作序列,问该操作序列在键盘上形成的手势是否是唯一的,是则输出YES,否则为NO。

本题可以做一个响亮的边界处理,我们设上下左右方向的向量分别为U、D、L、R,当不可向该方向移动时对应的字母值为1。例如当操作序列含0时,左右下都不可移动,则L=R=D=0;

附AC代码:

 #include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std; int main(){
int n;
char s[];
while(cin>>n>>s){
int U=,D=,L=,R=;
for(int i=;i<n;i++){
if(s[i]=='')
D=R=L=;
if(s[i]==''||s[i]==''||s[i]=='')//上
U=;
if(s[i]==''||s[i]==''||s[i]=='')//左
L=;
if(s[i]==''||s[i]==''||s[i]=='')//右
R=;
if(s[i]==''||s[i]=='')//下
D=;
}
if(U==&&D==&&R==&&L==)//当所有方向都不可走时,即手势唯一
cout<<"YES"<<endl;
else
cout<<"NO"<<endl;
}
return ;
}

A - Mike and Cellphone的更多相关文章

  1. CodeForces 689A Mike and Cellphone (模拟+水题)

    Mike and Cellphone 题目链接: http://acm.hust.edu.cn/vjudge/contest/121333#problem/E Description While sw ...

  2. A. Mike and Cellphone(Round 361 Div.2)

    写一半去开程序的时候不小心关了网页,LOFTER我都不奢望加入代码高亮,最起码我关闭的时候弹个对话框,再不济也给我定时保存一下草稿吧. A. Mike and Cellphone time limit ...

  3. Codeforces Round #361 (Div. 2) A. Mike and Cellphone 水题

    A. Mike and Cellphone 题目连接: http://www.codeforces.com/contest/689/problem/A Description While swimmi ...

  4. Codeforces Round #361 (Div. 2)A. Mike and Cellphone

    A. Mike and Cellphone time limit per test 1 second memory limit per test 256 megabytes input standar ...

  5. codeforces 689A A. Mike and Cellphone(水题)

    题目链接: A. Mike and Cellphone time limit per test 1 second memory limit per test 256 megabytes input s ...

  6. codeforces 361 A - Mike and Cellphone

    原题: Description While swimming at the beach, Mike has accidentally dropped his cellphone into the wa ...

  7. B - Mike and Cellphone(map)

    Problem description While swimming at the beach, Mike has accidentally dropped his cellphone into th ...

  8. CodeForces 689A -Mike and Cellphone

    题目链接:http://acm.hust.edu.cn/vjudge/problem/visitOriginUrl.action?id=412142 题目大意: 给定一个0-9数字键盘,随后输入一个操 ...

  9. CoderForces 689A Mike and Cellphone (水题)

    题意:给定一个手机键盘数字九宫格,然后让你判断某种操作是不是唯一的,也就是说是不是可以通过平移也能实现. 析:我的想法是那就平移一下,看看能实现,就四种平移,上,下,左,右,上是-3,要注意0变成8, ...

随机推荐

  1. 为Redmine的项目加上起止时间

    没有时间约束的项目不是好项目. 要给项目配置起止时间,须要用到自己定义属性. 我们须要管理员身份登录.才干够定义自己定义属性. 自己定义属性 看图吧,先是点击页面导航条(最上面那排菜单,有主页.我的工 ...

  2. 如何求文件File的字节数

      [java]代码库 import java.io.*;   /**  * 获取文件的字节数  */   class FileInputStreamS {     public static voi ...

  3. IOS 汤姆猫核心代码

    // // MJViewController.m // 03-Tom // // Created by apple on 13-11-24. // Copyright (c) 2013年 itcast ...

  4. struts2上传图片超过大小给出错误提示

    struts2上传图片超过大小给出错误提示        今天碰到上传图片太大,上传不上去返回input视图的界面,回显的错误信息却是乱码,整了好久才整出来,在这里做个记录,方便自己以后查阅,也希望能 ...

  5. Java RESTful 框架

    [转载] 最好的8个 Java RESTful 框架 - 2015 Top 8 Java RESTful Micro Frameworks – Pros/Cons - 2017 Restlet - f ...

  6. Asp.Net Core 初探 (三)

    昨天失败的生产环境部署就先放着,明天再解决! 今天利用中午的空余时间看了一下Asp.net core 的Areas . 相对于Asp.net MVC5 以及之前的版本,asp.net core 的Ar ...

  7. PHP后台批量删除数据

    html <form action="" method="post"> <div><input type="submit ...

  8. 剑指Offer面试题16(Java版):反转链表

    题目:定义一个函数,输入一个链表的头结点,反转该链表并输出反转后链表的头结点. 解决与链表相关的问题总是有大量的指针操作.而指针操作的代码总是easy出错的. 非常多的面试官喜欢出链表相关的问题,就是 ...

  9. Geeks LCA最低公共单亲节点

    给出一颗二叉树.找到两个值的最小公共节点. 假设两个值都会在树中出现. 假设可能不会出现的话,也非常easy.就查找一遍看两个值是否在树中就能够了.假设不在就直接返回NULL. 基本思想:就是在二叉树 ...

  10. 从S3中导入数据到Dynamodb

    本节如果你已经从Dynamodb中导出过数据,而且导出的文件以及被存入S3.文件内部结构会在Verify Data Export File 中描写叙述. 我们称之前导出数据的原始表为source ta ...