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. ural1523 K-inversions

    K-inversions Time limit: 1.0 secondMemory limit: 64 MB Consider a permutation a1, a2, …, an (all ai  ...

  2. 微信小程序实例教程(四)

    第八章:微信小程序分组开发与左滑功能实现   先来看看今天的整体思路: 进入分组管理页面 --> 点击新建分组新建 进入到未分组页面基本操作 进入到已建分组里面底部菜单栏操作 --> 从名 ...

  3. Ubuntu Server 重启 Apache Mysql

    a. 重启 apache sudo service apache2 restart b. 重启 MySQL sudo service mysql restart

  4. Jenkins启动、停止脚本

    1.jenkins下载地址:http://pan.baidu.com/s/1o79ZRzs 2.创建shell脚本,如:jenkins.sh #!/bin/bash pid=`ps -ef | gre ...

  5. <Natural Language Processing with Python>学习笔记二

    用Enthought Canopy作图果然方便.昨天频频出现无法识别pylab模块的异常,今天终于搞好了.以下是今天出来的图:

  6. OSX下编译安装opencv3.1.0与opencv_contrib_master

    OSX版本10.11.3 1.安装homebrew,打开终端,写入指令 ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Hom ...

  7. MySQL 同步状态

    Exec_Master_Log_Pos: The position of the last event executed by the SQL thread from the master's bin ...

  8. 最新 Spring 4.2.2 集成 Quartz Scheduler 2.2.2 任务调度示例

    参考http://blog.csdn.net/defonds/article/details/49496895 本文将演示如何通过 Spring 使用 Quartz Scheduler 进行任务调度. ...

  9. 忘记Django登陆账号和密码的处理方法

    Reference: http://nolinux.blog.51cto.com/4824967/1743392 公司部署了一套分布式网络监控系统,使用celery来做的分布式任务队列,针对celer ...

  10. Robocopy 轉帖

    实例一:文件,想怎么复制就怎么复制 [实现效果] 随时将源文件夹中的纯文本(TXT).Word文档(DOC)还有BMP.TIF图像文件复制到目标文件夹中 ,这是在"资源管理器"中直 ...