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. OC分割输入验证码的视觉效果

    效果图: 用到的类: UITextField+VerCodeTF.h #import <UIKit/UIKit.h> @protocol VerCodeTFDelegate <UIT ...

  2. UnicodeDecodeError异常

    UnicodeDecodeError异常 UnicodeDecodeError: 'utf8' codec can't decode byte 0xb2 in position 154: invali ...

  3. 小程序要求的 TLS 版本必须大于等于 1.2

    1.打开windows powershell   右击屏幕左下角的开始->所有程序->附件->“Windows PowerShell”.     2.在 PowerShell中运行以 ...

  4. python 字符串、列表和元祖之间的切换

    >>> s=['http','://','www','baidu','.com'] >>> url=''.join(s) >>> url 'htt ...

  5. JVM内存管理(转)

    转载出处:http://blog.csdn.net/wind5shy/article/details/8349559 模型 JVM运行时数据区域 JVM执行Java程序的过程中,会使用到各种数据区域, ...

  6. [django]主次表如何取出对方数据[主表obj.子表__set()]

    [sql]mysql管理手头手册,多对多sql逻辑 国家--城市例子 class Country(models.Model): name = models.CharField(max_length=3 ...

  7. 请求&注解

    @RequestMapping("/{page}") //获取路径中的page参数值 public String showPage(@PathVariable String pag ...

  8. ELK(上)

    什么是ELK: ELK是三个开源软件的缩写,分别表示:Elasticsearch , Logstash, Kibana , 它们都是开源软件.新增了一个FileBeat,它是一个轻量级的日志收集处理工 ...

  9. 不同平台windows、linux、mac 上换行符的问题

    http://blog.chinaunix.net/uid-26748613-id-3179595.html?page=2 https://blog.csdn.net/changruihe/artic ...

  10. jQuery-切换事件2

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...