A. Holiday Of Equality

time limit per test:1 second
memory limit per test:256 megabytes
input:standard input
output:standard output

In Berland it is the holiday of equality. In honor of the holiday the king decided to equalize the welfare of all citizens in Berland by the expense of the state treasury.

Totally in Berland there are n citizens, the welfare of each of them is estimated as the integer in ai burles (burle is the currency in Berland).

You are the royal treasurer, which needs to count the minimum charges of the kingdom on the king's present. The king can only give money, he hasn't a power to take away them.

Input

The first line contains the integer n (1 ≤ n ≤ 100) — the number of citizens in the kingdom.

The second line contains n integers a1, a2, ..., an, where ai (0 ≤ ai ≤ 106) — the welfare of the i-th citizen.

Output

In the only line print the integer S — the minimum number of burles which are had to spend.

Examples

input

5
0 1 2 3 4

output

10

input

5
1 1 0 1 1

output

1

input

3
1 3 1

output

4

input

1
12

output

0

Note

In the first example if we add to the first citizen 4 burles, to the second 3, to the third 2 and to the fourth 1, then the welfare of all citizens will equal 4.

In the second example it is enough to give one burle to the third citizen.

In the third example it is necessary to give two burles to the first and the third citizens to make the welfare of citizens equal 3.

In the fourth example it is possible to give nothing to everyone because all citizens have 12 burles.

 //2017.01.19
#include <iostream>
#include <cstdio>
#include <cstring> using namespace std; int a[]; int main()
{
int n;
while(cin >> n)
{
int maxium = ;
for(int i = ; i < n; i++)
{
cin >> a[i];
if(a[i] > maxium)
maxium = a[i];
}
int ans = ;
for(int i = ; i < n; i++)
ans += maxium-a[i];
cout << ans << endl;
} return ;
}

CodeForces758A的更多相关文章

  1. Codeforces758A Holiday Of Equality 2017-01-20 10:08 48人阅读 评论(0) 收藏

    A. Holiday Of Equality time limit per test 1 second memory limit per test 256 megabytes input standa ...

随机推荐

  1. office web apps部署(一)

    准备两台服务器,A服务器作为域控制器,B服务器安装owa 1.配置域服务器A 参考 2.B服务器加入A所创建的域 参考 3.B服务器安装owa 参考 注意: 1.B服务器加入域后,使用A服务器的管理员 ...

  2. CentOS 6.5 GIT 服务器搭建

    环境: Git Sserver IP: 10.6.0.2 Git Client IP: 10.6.0.126 1. 在 Git Server 安装软件所需的依赖包 yum install curl-d ...

  3. python----mysql链接汉字编码的问题

    解决python连接mysql,UTF-8乱码问题 1.  Python文件设置编码 utf-8 (文件前面加上 #encoding=UTF-8)     2. MySQL数据库charset=utf ...

  4. ZOJ 3780 Paint the Grid Again

    拓扑排序.2014浙江省赛题. 先看行: 如果这行没有黑色,那么这个行操作肯定不操作. 如果这行全是黑色,那么看每一列,如果列上有白色,那么这一列连一条边到这一行,代表这一列画完才画那一行 如果不全是 ...

  5. POJ3723最小生成树

    题意:从一个起点出发连接男孩子和女孩子,若是两者之间有连接的,则花费为10000-d,若是没有连接的则花费为10000 分析:很显然是一个最小生成树,但是我们希望的是d越大越好,因为d越大,10000 ...

  6. HDU 3903 Trigonometric Function

    这题真难,并不会推理... #include<cstdio> #include<cstring> #include<cmath> #include<algor ...

  7. linux下实现ftp匿名用户的上传和下载文件功能

    1.配置/etc//vsftpd/vsftpd.conf 文件如下: 打开文件,改变如下选项,如果文件中没有该选项,需要自己手动编写该选项 write_enable=YES anonymous_ena ...

  8. 交换Ctrl和Caps Lock键

    由于使用vim的缘故,就把Ctrl和Caps Lock键交换了,在ubuntu系统下使用系统设置可以很简单地进行全局替换. 在ubuntu下习惯了之后在window下就经常按错...后来决定也把win ...

  9. 关于学习方法的借鉴和有关C语言学习的调查

    专长的高超技能获取的成功经验 在游戏方面,我相对于大多数人来说可能更为出色.首先是我投入了大量的时间进行游戏:其次,我几乎每天都会看一会教学视频来模仿:最后应该还是跟个人的天赋有点关系. 如果把这个类 ...

  10. UVa 990 - Diving for Gold

    题目大意:一个潜水者去海底寻找金子,已知有n个有金子的地点,分别给出他们的深度和价值.但是由于潜水者只有一瓶氧气,所以他只能在海底呆有限的时间,问他如何才能在这有限的时间里获得尽可能多的金子,并打印出 ...