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