#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,-1,sizeof(x))
const int INF = 1000000001;

int main(){
  int n;
  ll ans = 0;
  priority_queue<pair<int, int>> a;
  cin >> n;
  rep(i, n){
    int tmp;
    cin >> tmp;
    a.push(make_pair(tmp, i));
  }
  unordered_set<int> choosed;
  rep(i, n/2){
    pair<int, int> k = a.top();
    a.pop();
    
    if(!choosed.count(k.second+1) && !choosed.count(k.second-1)){
      ans += k.first;
      choosed.insert(k.second);
    }else{
      i--;
    }
  }
  cout << ans <<endl;
}