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. 利用Oracle分析函数row_number和sys_connect_by_path实现多行数据合并为一行

    emo场景,以oracle自带库中的表emp为例: select ename,deptno from emp order by deptno; ENAME DEPTNO CLARK 10 KING 1 ...

  2. Feature Extractor[SENet]

    0.背景 这个模型是<Deep Learning高质量>群里的牛津大神Weidi Xie在介绍他们的VGG face2时候,看到对应的论文<VGGFace2: A dataset f ...

  3. JVM源码分析--ClassLoader类加载器

    本人原创,转载请注明出处:https://www.cnblogs.com/javallh/p/10224187.html 1.JDK已有类加载器: BootStrap ClassLoader (启动类 ...

  4. 对Android系统权限的认识

    Android系统是运行在Linux内核上的,Android与Linux分别有自己的一套严格的安全及权限机制 Android系统权限相关的内容 (一)linux文件系统上的权限 -rwxr-x--x ...

  5. JavaEE学习之Maven配置文件pom.xml详解(转)

    一.引言 (本文转载自:http://blog.csdn.net/longeremmy/article/details/9670619) 使用maven有一些时间了,一直没有好好将pom配置文件每个节 ...

  6. 在Linux的Windows子系统上(WSL)使用Docker(Ubuntu)

    背景 平时开发大部人都是在提供了高效GUI的window下工作,但是真正部署环境普遍都是在Linux中,所以为了让开发环境和部署环境统一,我们需要在windows模拟LInux环境,以前我们可能通过虚 ...

  7. 在线流媒体nginx/Windows解决方案

    1,下载安装nginx这里是1.15.10,修改默认端口,看到测试页即可 2,conf文件中加入flv支持 location ~ .flv { flv; } 3,把mp4文件转码,使用ffmpeg-2 ...

  8. 如何在C#中使用Dapper(译)

    前言: 对象关系映射(ORM)已经被使用了很长时间,以解决在编程过程中对象模型与数据模型在关系数据库中不匹配的问题. Dapper是由Stack OverFlow团队开发的开源的,轻量级的ORM.相比 ...

  9. python学习第七篇——字典访问键与值

    此程序的目的在于,正确而简单的访问字典的键与值 favorite_languages={ 'jen':['python','c'], 'sarah':['c'], 'edward':['ruby',' ...

  10. 软件工程(FZU2015) 学生博客列表(最终版)

    FZU:福州大学软件工程 张老师的博客:http://www.cnblogs.com/easteast/ 经过前两周选课,最后正式选上课程的所有学生博客如下: 序号 学号后3位 博客 1 629 li ...