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