#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
ll gcd(ll a, ll b) {
  if (a < b) swap(a, b);
  if (b == 0) return a;
  return gcd(b, a % b);
}
ll beki(ll a, ll b) {
  ll tmp = 1;
  for (int i = 0; i < b; i++) tmp *= a;
  return tmp;
}
ll modPow(ll x, ll a) {
  if (a == 1) return x;
  if (a % 2) return (x * modPow(x, a - 1)) % (ll)(1e9 + 7);
  ll t = modPow(x, a / 2);
  return ((t % (ll)(1e9 + 7)) * (t % (ll)(1e9 + 7))) % (ll)(1e9 + 7);
}
ll modInv(ll x) { return modPow(x, (ll)(1e9 + 7) - 2); }
ll N;
ll A[200010];
ll ans;
int main() {
  cin >> N;
  for (int i = 0; i < N; i++) cin >> A[i];
  ll tmp = A[0];
  for (int i = 1; i < N; i++) {
    ans += max(tmp - A[i], (ll)0);
    A[i] += max(tmp - A[i], (ll)0);
    cout << A[i] << endl;
    tmp = A[i];
  }
  cout << ans << endl;
}
