#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  int x[N];
  int i;
  for (i = 0; i < N; ++i) {
    cin >> x[i];
  }
  for (i = 0; i < N; ++i) {
    x[i] -= x[0];
  }
  long long int count = 0;
  int j;
  for (i = 0; i < j; ++i) {
    for (j = 1; j < N; j++) {
      count += (x[j] - x[i]) * 2;
      count %= 1000000007;
    }
  }
  cout << count << endl;
}
