import std.stdio, std.conv, std.string, std.algorithm, std.range;

void main() {
  auto N = readln.split[0].to!int;
  auto A = new int[N];
  auto B = readln.split.to!(int[]);

  B.writeln;

  A[0] = B[0];
  A[$-1] = B[$-1];
  for(auto i = 1; i < A.length - 1; i++) {
    A[i] = min(B[i-1], B[i]);
  }

  A.writeln;
  A.reduce!"a+b"().writeln;
}