#include <bits/stdc++.h>
int main() {
  int n, a[2010], x, y, t, b[2010], c[2010], s;
  scanf("%d", &n);
  x = 0;
  y = 0;
  for (int i = 0; i < n; i++) scanf("%d", &a[i]);
  for (int i = 0; i < n; i++) {
    if (i % 2 != 0) {
      b[x] = i;
      x++;
    } else {
      c[y] = i;
      y++;
    }
  }
  if (fabs(x - y) == 0 || fabs(x - y) == 1)
    printf("0\n");
  else {
    for (int i = 0; i < x; i++)
      for (int j = 0; j < x - i - 1; j++) {
        if (b[j + 1] < b[j]) {
          t = b[j + 1];
          b[j + 1] = t;
          b[j] = t;
        }
      }
    for (int i = 0; i < y; i++)
      for (int j = 0; j < y - i - 1; j++) {
        if (c[j + 1] < c[j]) {
          t = c[j + 1];
          c[j + 1] = t;
          c[j] = t;
        }
      }
    t = fabs(x - y);
    for (int i = 0; i < t - 1; i++) {
      if (x > y)
        s += b[i];
      else
        s += c[i];
    }
    printf("%d\n", s);
  }
  return 0;
}
