#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  vector<int> v(t);
  vector<int> a(t);
  int max = 0, index = 0;
  for (int i = 0; i < t; i++) {
    cin >> a[i];
    if (max < a[i]) {
      max = a[i];
      index = i;
    }
  }
  cout << max << index << endl;
  int sum = 0, k = 1;
  v[k] = 0;
  cout << v[k] << ",";
  for (int i = 0; i < t; i++) {
    if (i <= index && a[i] > a[i + 1]) {
      v[k] = a[i] - a[i + 1];
      cout << v[k] << ",";
    }
    if (i <= index && a[i] < a[i + 1]) {
      v[k] = 0;
      cout << v[k] << ",";
    } else {
      v[k] = max - a[i];
      cout << v[k] << ",";
    }
    sum += v[k];
    k++;
  }
  cout << endl << sum << endl;
  return 0;
}
