Yaroslav has an array that consists of n integers. In one second Yaroslav can swap two neighboring array elements. Now Yaroslav is wondering if he can obtain an array where any two neighboring elements would be distinct in a finite time.

Help Yaroslav.

Input

The first line contains integer n (1 ≤ n ≤ 100) — the number of elements in the array. The second line contains n integers a1, a2, ..., an(1 ≤ ai ≤ 1000) — the array elements.

Output

In the single line print "YES" (without the quotes) if Yaroslav can obtain the array he needs, and "NO" (without the quotes) otherwise.

Examples
input
1
1
output
YES
input
3
1 1 2
output
YES
input
4
7 7 7 7
output
NO
Note

In the first sample the initial array fits well.

In the second sample Yaroslav can get array: 1, 2, 1. He can swap the last and the second last elements to obtain it.

In the third sample Yarosav can't get the array he needs.

题解:统计出现次数最多的 如果大于一半 就不满足

 #include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <vector>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <ctime>
#include <map>
#include <set>
using namespace std;
#define lowbit(x) (x&(-x))
#define max(x,y) (x>y?x:y)
#define min(x,y) (x<y?x:y)
#define MAX 100000000000000000
#define MOD 1000000007
#define pi acos(-1.0)
#define ei exp(1)
#define PI 3.141592653589793238462
#define INF 0x3f3f3f3f3f
#define mem(a) (memset(a,0,sizeof(a)))
typedef long long ll;
ll gcd(ll a,ll b){
return b?gcd(b,a%b):a;
}
const int N=;
const int mod=1e9+;
bool flag=;
int a[N];
int main()
{
std::ios::sync_with_stdio(false);
int n,t;
cin>>n;
for(int i=;i<n;i++){
cin>>t;
a[t]++;
if(a[t]>(n+)/) flag=;
}
if(flag) cout<<"NO"<<endl;
else cout<<"YES"<<endl;
return ;
}

Codeforce 296A - Yaroslav and Permutations的更多相关文章

  1. Codeforces Round #179 (Div. 1 + Div. 2)

    A. Yaroslav and Permutations 值相同的个数不能超过\(\lfloor \frac{n + 1}{2} \rfloor\). B. Yaroslav and Two Stri ...

  2. Permutations II

    Given a collection of numbers that might contain duplicates, return all possible unique permutations ...

  3. [LeetCode] Permutations II 全排列之二

    Given a collection of numbers that might contain duplicates, return all possible unique permutations ...

  4. [LeetCode] Permutations 全排列

    Given a collection of numbers, return all possible permutations. For example,[1,2,3] have the follow ...

  5. POJ2369 Permutations(置换的周期)

    链接:http://poj.org/problem?id=2369 Permutations Time Limit: 1000MS   Memory Limit: 65536K Total Submi ...

  6. Permutations

    Permutations Given a collection of distinct numbers, return all possible permutations. For example,[ ...

  7. 【leetcode】Permutations

    题目描述: Given a collection of numbers, return all possible permutations. For example, [1,2,3] have the ...

  8. [leetcode] 47. Permutations II

    Given a collection of numbers that might contain duplicates, return all possible unique permutations ...

  9. Leetcode Permutations

    Given a collection of numbers, return all possible permutations. For example,[1,2,3] have the follow ...

随机推荐

  1. cobbler自动安装操作系统

    cobbler介绍 快速网络安装linux操作系统的服务,支持众多的Linux发行版: Red Hat, Fedora,CentOS,Debian,Ubuntu和SuSE 也可以支持网络安装windo ...

  2. RabbitMQ -- unacked

    RabbitMQ解决大量unacked问题 为了快速响应用户请求,我们需要消息异步处理机制,比较简单的做法是用redis的List结构,我们项目使用更专业的RabbitMQ.关于redis和Rabbi ...

  3. DLNg第三周:序列模型和注意力机制

    1.基础模型 将法语翻译为英语,分为编码和解码阶段,将一个序列变为另一个序列.即序列对序列模型. 从图中识别出物体的状态,将图片转换为文字. 先使用CNN处理图片,再使用RNN将其转换为语言描述. 2 ...

  4. openshift 调度命令

    oc adm manage-node oc-node07 --schedulable=true  #可调度 oc adm manage-node oc-node07 --schedulable=fal ...

  5. 超全PHP学习资源整理:入门到进阶系列

    PHP是少数几门在语言层面饱受诟病,但在实际开发和应用上却又让人无法撒手的语言之一.就好比路边摊小吃,一遍骂人家不卫生,一遍却又说:真香.所谓接地气,不外如此,大道理不说,PHP光是轮子多.市场占有率 ...

  6. .NET拾忆:EventLog(Windows事件日志监控)

    操作Windows日志:EventLog 1:事件日志名(logName):“事件查看器”中的每一项,如“应用程序”.“Internet Explorer”.“安全性”和“系统”都是日志(严格地说是日 ...

  7. 关于设置cookie同源,axios请求加上cookie

    一个有cookie  一个没有 这是为啥!! axios都设置了的为true允许携带cookie 大佬答疑解惑:==>cookie同源域名才有啊,在Application看看cookie的pat ...

  8. vue父组件数据改变,子组件数据并未发生改变(那是因为你没写监听)附带子组件的写法

    下面的代码有 父组件有三个按钮,年.月.日 点击之后父组件的数据发生改变,子组件却没改变,打印接受的数据,除了第一次其他都没打印,那是因为你没有写监听 <template> <div ...

  9. Tortoisegit和GitHub使用入门

    作为一个Code人对于github并不陌生吧,记录下使用说明: gitHub是一个面向开源及私有软件项目的托管平台,因为只支持git 作为唯一的版本库格式进行托管,故名gitHub. 工具: git: ...

  10. HDU 1251 统计难题(Trie)

    统计难题 [题目链接]统计难题 [题目类型]Trie &题解: Trie的模板题,只不过这题坑点在没给数据范围,改成5e5就可以过了,用的刘汝佳蓝书模板 &代码: #include & ...