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. IFeatureWorkspace OpenFeatureClass Example(转)

    网络来源:http://changqingnew.blog.163.com/blog/static/1075233820103383633639/ //IFeatureWorkspace OpenFe ...

  2. 移动web开发资源大整合

    移动web开发资源大整合 http://www.cnblogs.com/PeunZhang/p/3407453.html

  3. iOS多页面传值方式之单例传值singleton

    // 要实现单例传值,那就必须得新建一个类做为单例 提供创建该类对象的类方法(因为是要在alloc开辟内存空间后赋值).所有在.h文件中声明该方法 + (instancetype)defaultUII ...

  4. CodeForces 617A Elephant

    C语言语法入门题 #include<cstdio> #include<cstring> #include<vector> #include<cmath> ...

  5. shell之crontab

    一  crontab高级用法 Crontab 主要是在做排程, 通常一般寫法大概都是如下: 0 0 * * * /usr/local/www/awstats/cgi-bin/awstats.sh 這種 ...

  6. sharedPreferences存储数据

    sharedPreferences使用的是键值对的方式存储数据. 1.Android中三种获取sharedPreferences的方式 1)Context 类中的getSharedPreference ...

  7. 超市RFID结算系统项目进度与总结

    超市RFID结算系统项目进度与总结 超市RFID结算系统本周末(明天演示),目前进度如下: 一.后台PHP端已经完成了大部分的工作,包括以下: 1.数据库的建立(目前只包括用户表.商品信息表.购物车表 ...

  8. Lambda表达式例子

    转 Lambda表达式例子 1.Java8 新特性介绍 写java的同学对java8肯定知道 那么java8到底有哪些特性呢,总结如下: Lambda表达式 函数式接口 Stream Optional ...

  9. IOS开发中各种型号的分辨率及软件图标的制作

    IOS中各手机的分辨率为: 5.5寸: 1242*2208;4.7寸: 750*1334;4.0寸: 640*1136;3.5寸: 640*960; 软件的图标有以下需求(注意选中右侧红色框中这一条) ...

  10. Python3基础 lambda表达式 简单示例

    镇场诗: 诚听如来语,顿舍世间名与利.愿做地藏徒,广演是经阎浮提. 愿尽吾所学,成就一良心博客.愿诸后来人,重现智慧清净体.-------------------------------------- ...