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. ural1471 Distance in the Tree

    Distance in the Tree Time limit: 1.0 secondMemory limit: 64 MB A weighted tree is given. You must fi ...

  2. 计算机学院大学生程序设计竞赛(2015’12) 1003 The collector’s puzzle

    #include<cstdio> #include<algorithm> using namespace std; using namespace std; +; int a[ ...

  3. MAC OSX 10.10 下安装PHP环境

    Apache和PHP已经在系统里面预装好了,只要你开启即可使用.这篇文章给大家介绍如何开启并设置好PHP开发环境. 1.开启默认Apache服务 打开终端命令行,输入如下命令就会开启Apache了.然 ...

  4. [转]hibernate缓存机制所有详解

    以下文章来自http://www.blogjava.net/tbwshc/articles/380013.html Hibernate 所有缓存机制详解 hibernate提供的一级缓存 hibern ...

  5. javascript高级程序设计 重读系列

    1.基本概念.数据类型.函数 1.1 数据类型 ECMAScript中有5种简单数据类型:Undefind,Null,Boolean,Number,String 问题:判断变量是否是空值的代码 解析: ...

  6. [python]小练习__创建你自己的命令行 地址簿 程序

    创建你自己的命令行 地址簿 程序. 在这个程序中,你可以添加.修改.删除和搜索你的联系人(朋友.家人和同事等等)以及它们的信息(诸如电子邮件地址和/或电话号码). 这些详细信息应该被保存下来以便以后提 ...

  7. 关于 HTML5、Jquery、Phonegap 跨域问题的研究

    近期研究Phonegap的相关技术,遇到了服务资源访问的跨域.经过尝试使用服务器端的代理,Phonegap打包后不能够访问到相应资源.在搜索引擎的帮助下,找到了Jquery的jsonp的方式,尝试发现 ...

  8. (简单) POJ 2750 Potted Flower,环+线段树。

    Description The little cat takes over the management of a new park. There is a large circular statue ...

  9. EQueue - 一个C#写的开源分布式消息队列的总体介绍(转)

    源: EQueue - 一个C#写的开源分布式消息队列的总体介绍 EQueue - 一个纯C#写的分布式消息队列介绍2 EQueue - 详细谈一下消息持久化以及消息堆积的设计

  10. iOS开发——判断是否第一次启动

    在我们做项目的时候,判断是否是第一次启动,还是比较常用的,比如,欢迎界面,只是第一次启动需要的调查问卷等等,目的明确,方法很多,这里介绍一种简单的. 在你需要只有第一次启动才跳转的地方写上 if(![ ...