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.

题解:去看是否出现次数最多的是否占n个数的一半以上

代码

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream> using namespace std; int main()
{ int n;
cin>>n;
int a[105];
int vis[1005]={0};
memset(vis,0,sizeof(vis));
for(int t=0;t<n;t++)
{
scanf("%d",&a[t]);
vis[a[t]]++;
}
int maxn=0;
for(int t=1;t<=1000;t++)
{
if(vis[t]>=2)
{
if(vis[t]>maxn)
maxn=vis[t];
}
}
if(maxn<=(n+1)/2)
{
cout<<"YES"<<endl;
}
else
{
cout<<"NO"<<endl;
}
return 0;
}

最新文章

  1. EntityFramework linq 多条件查询,不定条件查询
  2. 最小生成树 prime poj1258
  3. .NET使用OpenSSL生成的pem密钥文件[1024位]
  4. spring mvc 用freemarker实现/user/edit?id=${id}=${type} 的替换
  5. 【Java每日一题】20161114
  6. HDU2955 Robberies[01背包]
  7. checkbox 全选,反选 ,全不选
  8. linux mono环境
  9. java生成base64编码的png
  10. 基于.Net FrameWork的 RestFul Service
  11. STM32学习笔记(二) 基于STM32-GPIO的流水灯实现
  12. CSS学习笔记——定位position属性的学习
  13. Unity Navigation面板了解
  14. 【转】AC算法详解
  15. 取消a标签在移动端点击时的背景颜色
  16. java--计时器
  17. CentOS7创建本地yum源
  18. hdu 2642
  19. Swift3.0:照片选择
  20. Overriding managed version XX for YY

热门文章

  1. IDEAL葵花宝典:java代码开发规范插件 (maven helper)解决maven 包冲突的问题
  2. test pic重复
  3. spark源码笔记
  4. hdu1085Holding Bin-Laden Captive!组合问题
  5. 【Codeforces】894E.Ralph and Mushrooms Tarjan缩点+DP
  6. 【译】在ES6中如何优雅的使用Arguments和Parameters
  7. hdu-2586 How far away ?(lca+bfs+dfs+线段树)
  8. [acm]HDOJ 2673 shǎ崽 OrOrOrOrz
  9. PCL推荐的命名规范(1)
  10. 在Elasticsearch6.X中如何实现去重