#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int N, ans = 0, temp;
  vector<long long int> vec1;
  vector<long long int> vec2;
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> temp;
    vec1.push_back(temp);
    vec2.push_back(temp);
  }
  sort(vec1.begin(), vec1.end());
  sort(vec2.begin(), vec2.end());
  for (int i = 0; i < N; i++) ans = (ans + vec1[i] * vec2[N - 1 - i]) % 10007;
  cout << ans << endl;
  return 0;
}
