/**
 * Author: Sergey Kopeliovich (Burunduk30@gmail.com)
 * Date: 2014.04.10
 */

#include <cstdio>
#include <cassert>
#include <algorithm>

using namespace std;

#define forn(i, n) for (int i = 0; i < (int)(n); i++)
#define all(a) (a).begin(), (a).end()

const int N = 1 << 20;

int n, a[N], sum[2 * N], is[2 * N], x[2 * N];

// [vl, vr), [L, R)
int get( int v, int vl, int vr, int L, int R ) {
  if (L >= vr || vl >= R)
    return 0;
  if (is[v]) 
    return x[v] * (min(R, vr) - max(L, vl));
  if (L <= vl && vr <= R)
    return sum[v];
  int sum = 0, vm = (vl + vr) / 2;
  sum += get(2 * v + 0, vl, vm, L, R);
  sum += get(2 * v + 1, vm, vr, L, R);
  return sum;
}
// [vl, vr), [L, R), x
void set_x( int v, int vl, int vr, int L, int R, int y ) {
  if (L >= vr || vl >= R)
    return;
  if (L <= vl && vr <= R) {
    is[v] = 1, x[v] = y;
    sum[v] = y * (vr - vl);
    return;
  }
  if (is[v]) {
    is[v] = 0;
    is[2 * v] = is[2 * v + 1] = 1;
    x[2 * v] = x[2 * v + 1] = x[v];
  }
  set_x(2 * v + 0, vl, vm, L, R, y);
  set_x(2 * v + 1, vm, vr, L, R, y);
  sum[v] = sum[2 * v] + sum[2 * v + 1];
}

int main()
{
  scanf("%d", &n);
  forn(i, n)
    scanf("%d", &a[i]);

  // = x, [L..R]
  // sum [L..R]
  get(1, 0, n, L, R + 1);
  return 0;
}