首页
学习
活动
专区
圈层
工具
发布
社区首页 >专栏 >H-Fashion in Berland

H-Fashion in Berland

作者头像
Lokinli
发布2023-03-09 16:03:20
发布2023-03-09 16:03:20
2720
举报
文章被收录于专栏:以终为始以终为始
代码语言:javascript
复制
#include <bits/stdc++.h>

using namespace std;
int a[1005];
int main()
{
    int n;
    scanf("%d",&n);
    int sum = 0;
    int flag;
    for(int i = 0; i < n; i ++)
    {
        scanf("%d",&a[i]);
        if(a[i]==0){
            sum ++;
        }
    }
    if(n == 1)
    {
        if(a[0] == 1)
        {
            flag = 1;
        }
        else
        {
            flag = 0;
        }
    }
    else
    {
        if(sum==1)
        {
            flag = 1;
        }
        else
        {
            flag = 0;
        }
    }
    if(flag)
        printf("YES\n");
    else
        printf("NO\n");
    return 0;
}

题目描述:

According to rules of the Berland fashion, a jacket should be fastened by all the buttons except only one, but not necessarily it should be the last one. Also if the jacket has only one button, it should be fastened, so the jacket will not swinging open.

You are given a jacket with n buttons. Determine if it is fastened in a right way.

Input

The first line contains integer n (1 ≤ n ≤ 1000) — the number of buttons on the jacket.

The second line contains n integers ai (0 ≤ ai ≤ 1). The number ai = 0 if the i-th button is not fastened. Otherwise ai = 1.

Output

In the only line print the word "YES" if the jacket is fastened in a right way. Otherwise print the word "NO".

Example

Input

代码语言:javascript
复制
3
1 0 1

Output

代码语言:javascript
复制
YES

Input

代码语言:javascript
复制
3
1 0 0

Output

代码语言:javascript
复制
NO
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2018-02-19,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档