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

Copy
7
10 1 1 1 5 5 3
output

Copy
4
input

Copy
5
1 1 1 1 1
output

Copy
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.

给你一个序列,你可以生成这个序列的任意一个排列,对于某个排列,

如果这个排列上某个位置的值大于原序列的值,那么就会产生1的贡献,问你最大能有多少贡献。

 #include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string.h>
#include<map>
using namespace std;
const int maxn = int(1e5) + ;
int a[maxn], n, r = , ans;
int main()
{
cin >> n;
for (int i = ; i <= n; i++)
cin >> a[i];
sort(a+ , a+ + n);
for (int i = ; i <= n; i++)
{
while (r <= n && a[r] <= a[i])
r++;
if (r <= n)
ans++, r++;
}
cout << ans << std::endl;
return ;
}

最新文章

  1. rails日记1
  2. Web前端性能优化教程07:精简JS 移除重复脚本
  3. UVa11054 Gergovia的酒交易 Wine trading in Gergovia-递推
  4. Spring 3.x企业应用开发实战(14)----事务
  5. 无法添加sql server ER图
  6. [Medusa-dev] psp_handler - embed python in HTML like ASP
  7. Android线程和handler
  8. 《JS权威指南学习总结--6.7属性的特性》
  9. 直方图均衡化CImg实现
  10. 在Redis Sentinel环境下,jedis该如何配置
  11. mysql 删除指定字符
  12. python:threading.Thread类的使用详解
  13. Python爬虫学习之正则表达式爬取个人博客
  14. OpenCV自带dnn的Example研究(3)— object_detection
  15. 【原】在Matplotlib绘图中添加Latex风格公式
  16. c++中利用localtime_s函数格式化输出当地日期与时间
  17. js动态删除某一行,内容超出单元格后超出的部分用省略号代替
  18. Selenium2+python自动化54-unittest生成测试报告(HTMLTestRunner)
  19. NPOI 创建Excel 设置宽度 样式 颜色对比表
  20. 用Keras搭建神经网络 简单模版(三)—— CNN 卷积神经网络(手写数字图片识别)

热门文章

  1. Java面试题3-附答案
  2. BCM93349DCM 手动升级 Fireware 指导
  3. iOS仿抖音节拍界面、Swift,MVVM架构完整项目、日历demo、滚动切换分类等源码
  4. php函数 之 iconv 不是php的默认函数,也是默认安装的模块。需要安装才能用的。
  5. [LC] 674. Longest Continuous Increasing Subsequence
  6. python 3新式类的多继承
  7. make的使用和Makefile规则和编程及其基本命令(简单)
  8. 吴裕雄--天生自然python学习笔记:Python3 网络编程
  9. Servlet.service() for servlet [appServlet] in context with path [/item] threw exception [Request processing failed
  10. 通用 mapper的简单使用