#include <bits/stdc++.h>
using namespace std;
const int dir[4][2] = {1, 0, 0, 1, -1, 0, 0, -1};
const int N = 1e6 + 10;
const int mod = 1e4 + 7;
const double pi = acos(-1);
const double eps = 1e-8;
const int INF = 0x3f3f3f3f;
long long a[N], b[N];
int n, m, K;
int main() {
  ios::sync_with_stdio(0);
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
    b[i] = a[i];
  }
  sort(a + 1, a + 1 + n);
  sort(b + 1, b + 1 + n);
  long long sum = 0;
  for (int i = 1; i <= n; ++i) {
    sum += a[i] * b[n - i + 1] % mod;
    sum %= mod;
  }
  cout << sum << endl;
  return 0;
}
