暑期集训2:ACM基础算法 练习题A:CF-1008C

2018学校暑期集训第二天——ACM基础算法

练习题A  ——  CodeForces - 1008C 


Reorder the Array

You are given an array of integers. Vasya can permute (change order) its integers. He wants to do it so that as many as possible integers will become on a place where a smaller integer used to stand. Help Vasya find the maximal number of such integers.

For instance, if we are given an array [10,20,30,40][10,20,30,40], we can permute it so that it becomes [20,40,10,30][20,40,10,30]. Then on the first and the second positions the integers became larger (20>1020>10, 40>2040>20) and did not on the third and the fourth, so for this permutation, the number that Vasya wants to maximize equals 22. Read the note for the first example, there is one more demonstrative test case.

Help Vasya to permute integers in such way that the number of positions in a new array, where integers are greater than in the original one, is maximal.

Input

The first line contains a single integer nn (1≤n≤1051≤n≤105) — the length of the array.

The second line contains nn integers a1,a2,…,ana1,a2,…,an (1≤ai≤1091≤ai≤109) — the elements of the array.

Output

Print a single integer — the maximal number of the array's elements which after a permutation will stand on the position where a smaller element stood in the initial array.

Examples

Input

7
10 1 1 1 5 5 3

Output

4

Input

5
1 1 1 1 1

Output

0

Note

In the first sample, one of the best permutations is [1,5,5,3,10,1,1][1,5,5,3,10,1,1]. On the positions from second to fifth the elements became larger, so the answer for this permutation is 4.

In the second sample, there is no way to increase any element with a permutation, so the answer is 0.


#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cstdio>
#include<cmath>
#include<set>
#include<map>
using namespace std;

int a[100005];

int main(void)
{
	int n;
	cin >> n;
	for(int i=0;i<n;i++)
		scanf("%d", &a[i]);
	
	int count=0;
	sort(a,a+n);
	for(int i=0;i<n;i++)
		if(a[i]>a[count])
			count++;

	cout << count << endl;
	
	return 0;
}

 

全部评论

相关推荐

Ryan188:我觉得你简历最核心的问题就是太大众化。 你要有一个认知就是,如果你是面试官,你是HR,其实他们每天都会收到非常多大量重复的像你这种简历。 就是说你的项目不是一个真实的上线的项目,可能是从网上学习而来的,或者是直接copy别人的项目,没有新意,没有展现出你自己对技术的思考,而且你的学历也不占优,自然而然就很难有人去选择你。 所以要做的实际上是差异化方向的工作,也就是“给我一个选择你的理由”,比如最近很火的ai,你可以写一个ai相关项目比如问答应用或者mcp编写或者agent搭建,需要你先花点时间学习,34天吧,展现你对这方面相较于其他人特有的思考; 或者写相关技术博客输出一些技术内容,有具体可以量化的成果等等去增加你的竞争力。 但以上这些都是后话,我去年在你这个时候也是没人理我,咱们双非学历也没实习,难找也正常,我当时整个3月份都没人鸟我,直到有个新招的岗位,很缺人很急,流程很快,所以我一下子进去了,所以运气方面也很重要,需要你一直坚持喝复盘,直到看到光明,加油兄弟
简历被挂麻了,求建议
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务