The capital of Berland has n multifloor buildings. The architect who built up the capital was very creative, so all the houses were built in one row.

Let's enumerate all the houses from left to right, starting with one. A house is considered to be luxurious if the number of floors in it is strictly greater than in all the houses with larger numbers. In other words, a house is luxurious if the number of floors in it is strictly greater than in all the houses, which are located to the right from it. In this task it is assumed that the heights of floors in the houses are the same.

The new architect is interested in n questions, i-th of them is about the following: "how many floors should be added to the i-th house to make it luxurious?" (for all i from 1 to n, inclusive). You need to help him cope with this task.

Note that all these questions are independent from each other — the answer to the question for house i does not affect other answers (i.e., the floors to the houses are not actually added).

Input

The first line of the input contains a single number n (1 ≤ n ≤ 105) — the number of houses in the capital of Berland.

The second line contains n space-separated positive integers hi (1 ≤ hi ≤ 109), where hi equals the number of floors in the i-th house.

Output

Print n integers a1, a2, ..., an, where number ai is the number of floors that need to be added to the house number i to make it luxurious. If the house is already luxurious and nothing needs to be added to it, then ai should be equal to zero.

All houses are numbered from left to right, starting from one.

Examples
Input

Copy
5
1 2 3 1 2
Output

Copy
3 2 0 2 0 
Input

Copy
4
3 2 1 4
Output

Copy
2 3 4 0 
dp[ i ] 表示从 I 位置到尾的区间最大值;
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cstring>
#include<string>
#include<cmath>
#include<map>
#include<set>
#include<vector>
#include<queue>
#include<bitset>
#include<ctime>
#include<deque>
#include<stack>
#include<functional>
#include<sstream>
//#include<cctype>
//#pragma GCC optimize(2)
using namespace std;
#define maxn 1000005
#define inf 0x7fffffff
//#define INF 1e18
#define rdint(x) scanf("%d",&x)
#define rdllt(x) scanf("%lld",&x)
#define rdult(x) scanf("%lu",&x)
#define rdlf(x) scanf("%lf",&x)
#define rdstr(x) scanf("%s",x)
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int U;
#define ms(x) memset((x),0,sizeof(x))
const long long int mod = 1e9 + 7;
#define Mod 1000000000
#define sq(x) (x)*(x)
#define eps 1e-4
typedef pair<int, int> pii;
#define pi acos(-1.0)
//const int N = 1005;
#define REP(i,n) for(int i=0;i<(n);i++)
typedef pair<int, int> pii;
inline ll rd() {
ll x = 0;
char c = getchar();
bool f = false;
while (!isdigit(c)) {
if (c == '-') f = true;
c = getchar();
}
while (isdigit(c)) {
x = (x << 1) + (x << 3) + (c ^ 48);
c = getchar();
}
return f ? -x : x;
} ll gcd(ll a, ll b) {
return b == 0 ? a : gcd(b, a%b);
}
int sqr(int x) { return x * x; } /*ll ans;
ll exgcd(ll a, ll b, ll &x, ll &y) {
if (!b) {
x = 1; y = 0; return a;
}
ans = exgcd(b, a%b, x, y);
ll t = x; x = y; y = t - a / b * y;
return ans;
}
*/ int n;
int h[maxn];
int a[maxn];
int dp[maxn]; int main() {
//ios::sync_with_stdio(0);
rdint(n);
for (int i = 1; i <= n; i++)rdint(h[i]);
dp[n] = h[n]; int maxx = h[n];
for (int i = n; i >= 1; i--) {
maxx = max(maxx, h[i]);
dp[i] = maxx;
// cout << dp[i] << endl;
}
for (int i = 1; i <= n; i++) {
if (i == n) {
cout << 0 << endl; return 0;
}
if (h[i] > dp[i+1])cout << 0 << ' ';
else {
cout << dp[i+1] - h[i] + 1 << ' ';
}
}
return 0;
}

最新文章

  1. RecyclerView-------MainActivity代码
  2. Application_Error VS OnException 遇到的坑
  3. windows dir改成ls
  4. python 简介
  5. 《30天自制操作系统》06_day_学习笔记
  6. 由浅入深了解Thrift之结果封装
  7. 基于Linux的oracle数据库管理 part3( 存储 网络 常用命令 )
  8. Emeditor所有快捷键操作
  9. django--的第一个项目hello world
  10. Windows Azure Storage Client Library 2.0 入门
  11. Java第二章 变量
  12. Swagger
  13. Web离线应用解决方案——ServiceWorker
  14. 《你不知道的 JavaScript 上卷》 学习笔记
  15. 【Mybatis】【3】mybatis Example Criteria like 模糊查询
  16. 如何系统的学习Java
  17. 835.Hamming距离
  18. Spring Boot(二):Web 综合开发
  19. 基于Hadoop2.6.5(HA)的HBase2.0.5配置
  20. C语言与VT100控制码编程

热门文章

  1. redis学习二 排序
  2. Solaris与Windows Active Directory集成
  3. 12-01JavaScript事件(Events)
  4. 监控和安全运维 1.4 nagios安装
  5. mac上virtualBox的安装和使用
  6. 杭电ACM刷题(1):1002,A + B Problem II 标签: acmc语言 2017-05-07 15:35 139人阅读 评
  7. 前端基础 之JS
  8. opencv中读写视频
  9. wordcount程序实现与测试
  10. 《Head First Servlets & JSP》-8-无脚本的JSP