#include <bits/stdc++.h>
using namespace std;
long long A[100005], n, x, s;
void citire() {
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    cin >> x;
    A[x]++;
  }
}
void parcurgere() {
  long long p = 1, u = 100000;
  while (x < n) {
    while (A[p] == 0) ++p;
    ++x;
    --A[p];
    if (x < n)
      while (A[u] == 0) --u;
    --A[u];
    ++x;
    if (x > n) {
      s += (p * p);
    } else
      s += 2 * (p * u);
    s %= 10007;
  }
}
int main() {
  citire();
  x = 0;
  parcurgere();
  cout << s;
}
