Lottery

CodeForces - 589I

Today Berland holds a lottery with a prize — a huge sum of money! There are kpersons, who attend the lottery. Each of them will receive a unique integer from 1 to k.

The organizers bought n balls to organize the lottery, each of them is painted some color, the colors are numbered from 1 to k. A ball of color c corresponds to the participant with the same number. The organizers will randomly choose one ball — and the winner will be the person whose color will be chosen!

Five hours before the start of the lottery the organizers realized that for the lottery to be fair there must be an equal number of balls of each of k colors. This will ensure that the chances of winning are equal for all the participants.

You have to find the minimum number of balls that you need to repaint to make the lottery fair. A ball can be repainted to any of the k colors.

Input

The first line of the input contains two integers n and k (1 ≤ k ≤ n ≤ 100) — the number of balls and the number of participants. It is guaranteed that n is evenly divisible by k.

The second line of the input contains space-separated sequence of n positive integers ci (1 ≤ ci ≤ k), where ci means the original color of the i-th ball.

Output

In the single line of the output print a single integer — the minimum number of balls to repaint to make number of balls of each color equal.

Examples

Input
4 2
2 1 2 2
Output
1
Input
8 4
1 2 1 1 1 4 1 4
Output
3

Note

In the first example the organizers need to repaint any ball of color 2 to the color 1.

In the second example the organizers need to repaint one ball of color 1 to the color 2 and two balls of the color 1 to the color 3.

sol:略水,小学奥数随便搞搞,原题地址已经没了,我也不知道自己写的对不对

#include <bits/stdc++.h>
using namespace std;
typedef int ll;
inline ll read()
{
ll s=;
bool f=;
char ch=' ';
while(!isdigit(ch))
{
f|=(ch=='-'); ch=getchar();
}
while(isdigit(ch))
{
s=(s<<)+(s<<)+(ch^); ch=getchar();
}
return (f)?(-s):(s);
}
#define R(x) x=read()
inline void write(ll x)
{
if(x<)
{
putchar('-'); x=-x;
}
if(x<)
{
putchar(x+''); return;
}
write(x/);
putchar((x%)+'');
return;
}
#define W(x) write(x),putchar(' ')
#define Wl(x) write(x),putchar('\n')
const int N=;
int n,m,Ges[N];
int main()
{
int i,ans=;
R(n); R(m);
for(i=;i<=n;i++)
{
Ges[read()]++;
}
int oo=n/m;
for(i=;i<=m;i++) ans+=abs(Ges[i]-oo);
Wl(ans>>);
return ;
}
/*
Input
4 2
2 1 2 2
Output
1 Input
8 4
1 2 1 1 1 4 1 4
Output
3
*/

codeforces589I的更多相关文章

随机推荐

  1. ajax请求基于restFul的WebApi(post、get、delete、put)

    近日逛招聘软件,看到部分企业都要求会编写.请求restFul的webapi.正巧这段时间较为清闲,于是乎打开vs准备开撸. 1.何为restFul? restFul是符合rest架构风格的网络API接 ...

  2. Python全栈开发之路 【第五篇】:Python基础之函数进阶(装饰器、生成器&迭代器)

    本节内容 一.名称空间 又名name space,就是存放名字的地方.举例说明,若变量x=1,1存放于内存中,那名字x存放在哪里呢?名称空间正是存放名字x与1绑定关系的地方. 名称空间共3种,分别如下 ...

  3. 设计模式之单例模式(C#)

    本文来自于本人个人微信公众号,欢迎关注本人微信公众号,二维码附在文章末尾~~~ 一直都特别羡慕能写文章的人,但是由于本人比较懒再加上写文章功底实在是just so so,所以就一搁再搁,最近突然觉得自 ...

  4. Mergeable Stack(链表实现栈)

    C - Mergeable Stack ZOJ - 4016 一开始用stl中内置的栈来写,其中第三个操作,我先复制到一个数组,再将其倒给另一个栈 这个方法有两个错误的地方: 1.栈在内存很大需要扩容 ...

  5. Python学习第十一篇——for 的本质及如何正确修改列表

    假如现在有一个列表:magicians_list = ['mole','jack','lucy'],现在想通过一个函数来实现,在列表的每个元素前面加上“the Great”的字样.现在通过一个函数来实 ...

  6. 书城项目第五阶段---book表的curd

    JavaEE三层架构分析 MVC

  7. scrapy之多环境的选择使用

    scrapy之多环境的选择使用 个人主机主机上可能存在多个python环境,当在终端中使用scrapy时,容易产生错误,无法使用到自己想使用的那个python,如何解决这个问题呢? 出现这类问题时,直 ...

  8. nodejs 中的一些方法

    fs.unlink(path, [callback(err)]) //删除文件操作. //path 文件路径 //callback 回调,传递一个异常参数err. ndoe中解决跨域问题 expres ...

  9. 迁移 VMware 虚拟机到 KVM

    虚拟机转换| VMware vCenter Converterhttps://www.vmware.com/cn/products/converter.html 迁移 VMware 虚拟机到 KVMh ...

  10. vue router 根据不同的id切换链接界面不刷新

    我们一般使用vue的router时候会根据不同的id来切换界面,但是界面没有立刻刷新.下面我们讲下如何解决这个问题. html: <template> <div id="a ...