#include <iostream>
#include <vector>

using namespace std;

const int MOD = 1000000007;

int main(){
	long long n;
	while(cin >> n){
		vector<long long> v(n+1, 1);
		vector<long long> s(n+1, 1);
		long long res = 0;
		for(int i=0;i<n;i++){
			if(i==n-1){
				res += (v[i] * n)%MOD;
			} else {
				long long sq = ((n-1) * (n-1)) % MOD;
				res += (v[i] * (sq + min(i+2LL, n-1))) %MOD;
			}
			res %= MOD;
			v[i+1] = s[i];
			if(i-1 >= 0) v[i+1] += (MOD - v[i-1]);
			v[i+1] %= MOD;
			s[i+1] = (s[i] + v[i+1])%MOD;
		}
		cout << res << endl;
	}
}

