#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-9;
const double PI = acos(-1.0);
const int inf = int(1e9 + 7);
const long long INF = (long long)8e18 + 7;
const int mod = int(1e4 + 7);
const int N = int(3e5 + 7);
int n, a[N], b[N], ans;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    b[i] = a[i];
  }
  sort(a, a + n);
  sort(b, b + n);
  reverse(b, b + n);
  for (int i = 0; i < n; i++) {
    ans += (a[i] * 1ll * b[i]) % mod;
    if (ans >= mod) ans -= mod;
  }
  cout << ans << endl;
  return 0;
}
