#include <bits/stdc++.h>
using namespace std;
bool call_back(pair<double, double> a, pair<double, double> b) {
  if (abs(a.second - b.second) > 1e-9)
    return a.second > b.second;
  else
    return a.first < b.first;
}
int main() {
  long long int n;
  cin >> n;
  long long int a[n], b[n];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    b[n - i - 1] = a[i];
  }
  sort(a, a + n);
  sort(b, b + n);
  long long int sum = 0;
  for (int i = 0; i < n; i++) {
    sum = sum + (a[i] * b[n - i - 1]) % 10007;
    sum = sum % 10007;
  }
  cout << sum;
}
