#include <bits/stdc++.h>
using namespace std;
int A[100001], B[100001];
void CountSort(int a[], int b[], int byte, int n) {
  int _count[1 << 8];
  int ind[1 << 8];
  int length = (1 << 8) - 1;
  for (int i = 0; i <= length; i++) _count[i] = 0;
  for (int i = 1; i <= n; i++) _count[((a[i] >> (8 * byte)) & 0xFF)]++;
  ind[0] = 1;
  for (int i = 1; i <= length; i++) ind[i] = ind[i - 1] + _count[i - 1];
  for (int i = 1; i <= n; i++) b[ind[((a[i] >> (8 * byte)) & 0xFF)]++] = a[i];
}
void RadixSort(int a[], int n) {
  int *temp = new int[n + 1];
  for (int i = 0; i < 4; i++)
    if (i % 2 == 0)
      CountSort(a, temp, i, n);
    else
      CountSort(temp, a, i, n);
  delete[] temp;
}
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> A[i];
    B[i] = A[i];
  }
  RadixSort(A, n);
  RadixSort(B, n);
  long long int time = 0;
  for (int i = 1, j = n; i <= n && j >= 1; i++, j--)
    time += ((A[i] * 1LL) * B[j]) % 10007;
  cout << time % 10007 << "\n";
  return 0;
}
