#include <bits/stdc++.h>
using namespace std;
class RangeQuery {
 public:
  RangeQuery(const vector<int>& arr) {
    this->arr = arr;
    preprocess();
  }
  void preprocess() {
    log = vector<int>(arr.size() + 1, 0);
    log[1] = 0;
    for (int i = 2; i < arr.size() + 1; ++i) {
      log[i] = log[i / 2] + 1;
    }
    rq = vector<vector<int> >(log[arr.size()], vector<int>(arr.size(), 0));
    for (int i = 0; i < arr.size(); ++i) {
      rq[0][i] = i;
    }
    for (int p = 1; p < log[arr.size()]; ++p) {
      for (int i = 0; i < arr.size() - (1 << p) + 1; ++i) {
        int i1 = rq[p - 1][i];
        int i2 = rq[p - 1][i + (1 << (p - 1))];
        if (arr[i1] < arr[i2]) {
          rq[p][i] = i2;
        } else {
          rq[p][i] = i1;
        }
      }
    }
  }
  int query(int i, int j) {
    int p = log[j - i + 1];
    int i1 = rq[p][i];
    int i2 = rq[p][j - (1 << p) + 1];
    if (arr[i1] > arr[i2]) {
      return i1;
    } else {
      return i2;
    }
  }
  vector<int> arr;
  vector<int> log;
  vector<vector<int> > rq;
};
void print(const vector<int>& arr) {
  for (int i = 0; i < arr.size(); ++i) {
    cout << arr[i] << " ";
  }
  cout << endl;
}
int main() {
  int n;
  cin >> n;
  vector<int> arr(n, 0);
  for (int i = 0; i < n; ++i) {
    cin >> arr[i];
  }
  vector<int> index(n, 0);
  for (int i = 0; i < n; ++i) {
    index[i] = i;
  }
  sort(index.begin(), index.end(),
       [&arr](int a, int b) { return arr[a] > arr[b]; });
  vector<int> brr(n);
  for (int i = 0; i < n - 1; ++i) {
    brr[i] = arr[index[i]] - arr[index[i + 1]];
  }
  brr[n - 1] = arr[index[n - 1]];
  RangeQuery rq(brr);
  int b1 = 0, b2 = 1, b3 = 2;
  for (int i = 0; i < n - 2; ++i) {
    if (brr[i] < brr[b1]) {
      continue;
    }
    int tb2 = -1, tb3 = -1;
    for (int j = i + 1; j < n - 1; ++j) {
      int cnt2 = j - i;
      int cnt1 = i + 1;
      if (cnt1 > 2 * cnt2) {
        continue;
      }
      if (cnt2 > 2 * cnt1) {
        break;
      }
      if (tb2 != -1 && brr[j] < brr[tb2]) {
        continue;
      }
      int ub = min(2 * cnt1, 2 * cnt2) + j;
      int lb = max((cnt1 + 1) / 2, (cnt2 + 1) / 2) + j;
      if (lb > n - 1) {
        break;
      }
      ub = min(ub, n - 1);
      if (tb2 == -1) {
        tb2 = j;
        tb3 = rq.query(lb, ub);
      } else if (brr[j] == brr[tb2]) {
        int temp = rq.query(lb, ub);
        if (brr[temp] > brr[tb3]) {
          tb2 = j;
          tb3 = temp;
        }
      } else {
        tb2 = j;
        tb3 = rq.query(lb, ub);
      }
    }
    if (tb2 != -1) {
      if ((brr[i] > brr[b1]) || ((brr[i] == brr[b1]) && (brr[tb2] > brr[b2])) ||
          ((brr[i] == brr[b1]) && (brr[tb2] == brr[b2]) &&
           (brr[tb3] > brr[b3]))) {
        b1 = i;
        b2 = tb2;
        b3 = tb3;
      }
    }
  }
  vector<int> ans(n, -1);
  for (int i = 0; i <= b1; ++i) {
    ans[index[i]] = 1;
  }
  for (int i = b1 + 1; i <= b2; ++i) {
    ans[index[i]] = 2;
  }
  for (int i = b2 + 1; i <= b3; ++i) {
    ans[index[i]] = 3;
  }
  for (int i = 0; i < n; ++i) {
    cout << ans[i] << " ";
  }
  cout << endl;
}
