#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int) n; i++)
using ll = long long;
template <class T>
using vt = std::vector<T>;
using vvi = std::vector<vt<int>>;

int main(){
  int n;
  std::cin >> n;
  int number = n/2;
  vt<std::pair<int,int>> a(n);
  rep(i,n) {
    std::cin >> a[i].first;
    a[i].second = i;
  }

  sort(a.rbegin(),a.rend());
  vt<bool> f(n+2);
  int cnt = 0;
  ll ans1 = 0;
  rep(i,n) {
    int k = a[i].second;
    if(f[k] == false && f[k+2] == false) {
      f[k+1] = true;
      ans1 += a[i].first;
      ++cnt;
    }
    if(cnt == number)
      break;
  }

  std::cout << ans1 << '\n';
  return 0;
}
