#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, i = 0, a, max_height = 0, sum = 0, sum1 = 0, sum2 = 0, c = 0, b = 0,
         index = 0;
  cin >> N;
  int height[N];
  for (i = 0; i < N; i++) {
    cin >> a;
    height[i] = a;
  }
  for (i = 0; i < N; i++) {
    if (i == 0) {
      max_height = height[i];
    }
    if (i != 0) {
      if (max_height > height[i]) {
        max_height = height[i];
        i = index;
      }
    }
  }
  cout << height[index] << endl;
  for (i = index; i < N; i++) {
    b = (height[index] - height[i]);
    sum2 = sum2 + b;
  }
  for (i = 0; i < index; i++) {
    if (height[i] < height[i - 1]) {
      c = (height[i - 1] - height[i]);
      sum1 = sum1 + c;
    }
  }
  sum = sum1 + sum2;
  cout << sum1 << sum2 << sum;
  return 0;
}
