#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];
  }
  long long int count = 0;
  int j;
  for (i = 0; i < N - 1; ++i) {
    count += (x[N - 1] - x[i]);
    count %= 1000000007;
  }
  cout << count / N << endl;
}
