当前位置: 首页 > news >正文

A. Make All Equal

time limit per test

1 second

memory limit per test

256 megabytes

You are given a cyclic array a1,a2,…,ana1,a2,…,an.

You can perform the following operation on aa at most n−1n−1 times:

  • Let mm be the current size of aa, you can choose any two adjacent elements where the previous one is no greater than the latter one (In particular, amam and a1a1 are adjacent and amam is the previous one), and delete exactly one of them. In other words, choose an integer ii (1≤i≤m1≤i≤m) where ai≤a(imodm)+1ai≤a(imodm)+1 holds, and delete exactly one of aiai or a(imodm)+1a(imodm)+1 from aa.

Your goal is to find the minimum number of operations needed to make all elements in aa equal.

Input

Each test contains multiple test cases. The first line contains the number of test cases tt (1≤t≤5001≤t≤500). The description of the test cases follows.

The first line of each test case contains a single integer nn (1≤n≤1001≤n≤100) — the length of the array aa.

The second line of each test case contains nn integers a1,a2,…,ana1,a2,…,an (1≤ai≤n1≤ai≤n) — the elements of array aa.

Output

For each test case, output a single line containing an integer: the minimum number of operations needed to make all elements in aa equal.

Example

Input

Copy

 

7

1

1

3

1 2 3

3

1 2 2

5

5 4 3 2 1

6

1 1 2 2 3 3

8

8 7 6 3 8 7 6 3

6

1 1 4 5 1 4

Output

Copy

0
2
1
4
4
6
3

Note

In the first test case, there is only one element in aa, so we can't do any operation.

In the second test case, we can perform the following operations to make all elements in aa equal:

  • choose i=2i=2, delete a3a3, then aa would become [1,2][1,2].
  • choose i=1i=1, delete a1a1, then aa would become [2][2].

It can be proven that we can't make all elements in aa equal using fewer than 22 operations, so the answer is 22.

解题说明:水题,统计数列中那个数字出现的次数最多,删除其他数字就是答案。可以用数组来记录每个数字出现的次数,找出最大值再用总次数相减即可。

#include<stdio.h>int main()
{int t;scanf("%d", &t);while (t--){int n, m = 0;scanf("%d", &n);int a[101];for (int i = 0; i < n; i++){a[i] = 0;}for (int i = 0; i < n; i++){int x;scanf("%d", &x);a[x - 1]++;if (a[x - 1] > m){m = a[x - 1];}}printf("%d\n", n - m);}return 0;
}

http://www.lryc.cn/news/442532.html

相关文章:

  • 业务安全治理
  • HelpLook VS GitBook,在线文档管理工具对比
  • docker面经
  • Python 中的 Kombu 类库
  • safepoint是什么?有什么用?
  • axios相关知识点
  • LeetCode 面试经典150题 67.二进制求和
  • Dell PowerEdge 网络恢复笔记
  • Java面试——集合篇
  • 算法【双向广搜】
  • javascript检测数据类型的方法
  • 生信初学者教程(五):R语言基础
  • 深度学习计算
  • Hexo博客私有部署Twikoo评论系统并迁移评论记录(自定义邮件回复模板)
  • Vue.js 与 Flask/Django 后端配合:构建现代 Web 应用的最佳实践
  • 【笔记】自动驾驶预测与决策规划_Part3_路径与轨迹规划
  • Shiro-721—漏洞分析(CVE-2019-12422)
  • 【Python语言初识(一)】
  • Python 中的方法解析顺序(MRO)
  • MySQL表的内外连接
  • 系统架构设计师:软件架构的演化和维护
  • QT的dropEvent函数进入不了
  • Spring Boot 入门
  • LDD学习2--Scull(TODO)
  • 【算法-堆排序】
  • 音视频入门基础:AAC专题(4)——ADTS格式的AAC裸流实例分析
  • 【第33章】Spring Cloud之SkyWalking服务链路追踪
  • 如何选择OS--Linux不同Distribution的选用
  • cesium效果不酷炫怎么办--增加渲染器
  • 计算机网络:概述 --- 体系结构