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;
}

CodeForces - 296A-Yaroslav and Permutations(思维)的更多相关文章

  1. Codeforce 296A - Yaroslav and Permutations

    Yaroslav has an array that consists of n integers. In one second Yaroslav can swap two neighboring a ...

  2. CodeForces - 987E Petr and Permutations (思维+逆序对)

    题意:初始有一个序列[1,2,...N],一次操作可以将任意两个位置的值互换,Petr做3*n次操作:Alxe做7*n+1次操作.给出最后生成的新序列,问是由谁操作得到的. 分析:一个序列的状态可以归 ...

  3. CodeForces - 427A (警察和罪犯 思维题)

    Police Recruits Time Limit: 1000MS   Memory Limit: 262144KB   64bit IO Format: %I64d & %I64u Sub ...

  4. Codeforces Round #337 Alphabet Permutations

    E. Alphabet Permutations time limit per test:  1 second memory limit per test:  512 megabytes input: ...

  5. codeforces 341C Iahub and Permutations(组合数dp)

    C. Iahub and Permutations time limit per test 1 second memory limit per test 256 megabytes input sta ...

  6. Codeforces 463D Gargari and Permutations

    http://codeforces.com/problemset/problem/463/D 题意:给出k个排列,问这k个排列的最长公共子序列的长度. 思路:只考虑其中一个的dp:f[i]=max(f ...

  7. codeforces 340E Iahub and Permutations(错排or容斥)

    转载请注明出处: http://www.cnblogs.com/fraud/          ——by fraud Iahub and Permutations Iahub is so happy ...

  8. codeforces 895B XK Segments 二分 思维

    codeforces 895B XK Segments 题目大意: 寻找符合要求的\((i,j)\)对,有:\[a_i \le a_j \] 同时存在\(k\),且\(k\)能够被\(x\)整除,\( ...

  9. codeforces 893D Credit Card 贪心 思维

    codeforces 893D Credit Card 题目大意: 有一张信用卡可以使用,每天白天都可以去给卡充钱.到了晚上,进入银行对卡的操作时间,操作有三种: 1.\(a_i>0\) 银行会 ...

  10. C. Nice Garland Codeforces Round #535 (Div. 3) 思维题

    C. Nice Garland time limit per test 1 second memory limit per test 256 megabytes input standard inpu ...

随机推荐

  1. jQuery选项卡tabulous

    jQuery选项卡tabulous,jQuery,选项卡,tab标签切换代码,扁平设计,jQuery选项卡tabulous是一款支持Scale.Slide.Scale Up.Flip等效果jquery ...

  2. layer 插件 在子页面关闭自身的方法

    先取到该子页面在父级页面中的name 值 var  index= parent.layer.getFrameIndex(Window.name); 然后用该方法关闭 parent.layer.clos ...

  3. AOP和IOC的作用(转)

    AOP和IOC的作用 转载▼     IOC:控制反转,是一种设计模式.一层含义是控制权的转移:由传统的在程序中控制依赖转移到由容器来控制:第二层是依赖注入:将相互依赖的对象分离,在spring配置文 ...

  4. linux 进程学习笔记-消息队列messagequeue

    可以想象,如果两个进程都可以访问同一个队列:其中一个进程(sender)向其中写入结构化数据,另外一个进程(receiver)再从其中把结构化的数据读取出来.那么这两个进程就是在利用这个队列进行通信了 ...

  5. AR/VR-VR:VR

    ylbtech-AR/VR-VR:VR 虚拟现实技术是一种可以创建和体验虚拟世界的计算机仿真系统,它利用计算机生成一种模拟环境,是一种多源信息融合的.交互式的三维动态视景和实体行为的系统仿真使用户沉浸 ...

  6. 我对sobel算子的理解

    转自:http://blog.csdn.net/yanmy2012/article/details/8110316 索贝尔算子(Sobeloperator)主要用作边缘检测,在技术上,它是一离散性差分 ...

  7. Ternary Calculation

    Ternary Calculation Time Limit : /2000ms (Java/Other) Memory Limit : /65536K (Java/Other) Total Subm ...

  8. failed to create rwlayer: lstat /var/lib/docker/overlay2/ no such file or directory

    在使用Docker构建微服务镜像时出现的错误.第一天构建好好的,第二天就出现了这样的错误.通过百度这条错误的信息非常少,只在 stackoverflow.com 上找到一条,问题指向了 dockerf ...

  9. algo: 冒泡排序(Java实现)

    package com.liuxian.algo; public class MySortClass implements Comparable<MySortClass> { public ...

  10. DOM,API,CSS,href,万方db文章,数据库工程师要求

    DOM,文档对象模型(Document Object Model),是W3C组织推荐的处理可扩展标志语言的标准编程接口. API,应用程序接口 (API:Application Program Int ...