#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main() {
  int n;
  cin >> n;
  vector<int> l(n);
  for (int i = 0; i < (n); ++i) cin >> l.at(i);
  ll count = 0;
  for (int i = 1; i < n; i++) {
    if (l.at(i - 1) > l.at(i)) {
      count += l.at(i - 1) - l.at(i);
      l.at(i) = l.at(i - 1);
    }
  }
  cout << '[';
  for (int i = 0; i < (n); ++i) cout << l.at(i) << ", ";
  cout << ']' << endl;
  cout << count << endl;
  return 0;
}
