CodeForces - 982A Row

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

You're given a row with nn chairs. We call a seating of people "maximal" if the two following conditions hold:

  1. There are no neighbors adjacent to anyone seated.
  2. It's impossible to seat one more person without violating the first rule.

The seating is given as a string consisting of zeros and ones (00 means that the corresponding seat is empty, 11 — occupied). The goal is to determine whether this seating is "maximal".

Note that the first and last seats are not adjacent (if n≠2n≠2).

Input

The first line contains a single integer nn (1≤n≤10001≤n≤1000) — the number of chairs.

The next line contains a string of nn characters, each of them is either zero or one, describing the seating.

Output

Output "Yes" (without quotation marks) if the seating is "maximal". Otherwise print "No".

You are allowed to print letters in whatever case you'd like (uppercase or lowercase).

Examples

input

3

101

output

Yes

input

4
1011

output

No

input

5

10001

output

No

Note

In sample case one the given seating is maximal.

In sample case two the person at chair three has a neighbour to the right.

In sample case three it is possible to seat yet another person into chair three.


这题题意是给你一串01串  1代表有人 0代表空位  只要满足1.有人的位置两边不能有人 2.满足1的同时不能再坐下任何一个人  就属于满座状态

这题我选择用模拟去写   将字符串从头到尾扫一遍  遇见0判断前后是否有1 只要存在一个就跳过  否则这个位置还能再坐一个人, 遇见1就判断前后是否有1 去判断字符串是否合法 


#include 
const int MAXN = 1e3 + 10;
using namespace std;

int main()
{
    int n;
    scanf("%d", &n);
    getchar();
    char tmp[MAXN];
    scanf("%s", tmp);
    int flag = 0;
    for (int i = 0; i < n; i++)
    {
        if (tmp[i] == '0')
        {
            if ((tmp[i - 1] == '1' && i > 0) || (tmp[i + 1] == '1' && i < n - 1))//如果前或后有人就跳过  否则这位置还能再坐下一人 就不是满座状态
                continue;
            else
                flag = 1;
        }
        else
        {
            if ((tmp[i - 1] == '1' && i > 0) || (tmp[i + 1] == '1' && i < n - 1))//如果有人的位置旁边也有人那么也不符合题意
                flag = 1;
        }
    }
    if (!flag)
        printf("Yes");
    else
        printf("No");
    return 0;
}

 

你可能感兴趣的:(模拟只会猜题意)