#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, ans = 0;
  cin >> n;
  long long a[n], b[n];
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
  }
  b[0] = 0;
  for (long long i = 1; i < n; i++) {
    if (a[i - 1] > a[i]) {
      b[i] = a[i - 1] - a[i];
      a[i] += b[i];
    } else {
      b[i] = 0;
    }
    cout << b[i] << endl;
  }
  for (long long i = 0; i < n; i++) {
    ans += b[i];
  }
  cout << ans << endl;
  return 0;
}
