#include <bits/stdc++.h>
using namespace std;
long long int n, ans = 0;
vector<long long int> a, b;
int main() {
  ios_base::sync_with_stdio(false);
  cin >> n;
  for (long long int i = 0; i < n; i++) {
    long long int x;
    cin >> x;
    a.push_back(x);
    b.push_back(x);
  }
  sort(a.begin(), a.end());
  sort(b.begin(), b.end(), greater<int>());
  for (long long int i = 0; i < n; i++) {
    ans = (ans + (a[i] % 10007 * b[i] % 10007) % 10007) % 10007;
  }
  cout << ans;
  return 0;
}
