当前位置: 首页 > 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.mrgr.cn/news/31411.html

相关文章:

  • 谁会从新技术中受益?
  • 【已为网站上传证书,却显示不安全】
  • 为什么在Ubuntu下使用VScode开发C++程序时需要手动配置链接库
  • 优化Mac的鼠标使用体验超简单方法
  • gorm使用注意事项
  • JSON.stringfy做深拷贝的缺点(代码示例)
  • MATLAB绘图基础8:双变量图形绘制
  • ELF文件结构
  • LeetCode337. 打家劫舍III
  • 【千帆AppBuilder】零代码+组件+代码节点方式实现AI应用《法定退休年龄计算器》
  • ArrayList和Array有什么区别?
  • 算法课习题汇总(2)
  • Data Lakehouse如何使用
  • BUUCTF-MISC-隐藏的钥匙
  • 三 auto占位符
  • Vue3中el-table组件实现分页,多选以及回显
  • 【Redis入门到精通三】Redis核心数据类型(List,Set)详解
  • 【Linux】进程概念
  • Zookeeper安装使用教程
  • JAVA8新特性——Optional
  • uboot:源码分析-启动第一阶段-start.S解析
  • IPD流程体系:IPD在硬件产品开发中的应用
  • NCNN 学习(2)-Mat
  • 嵌入式linux系统中rk3588芯片引脚基本操作
  • 基于SpringBoot的旅游管理系统
  • Linux:Bash中的文件描述符