#include<iostream>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<set>
#include<unordered_set>
#include<vector>
#include<array>
#include<string>
#include<stack>
#include<queue>
#include<algorithm>
#include<cassert>
#include<functional>
#include<random>
#include<complex>
#include<bitset>
#include<chrono>
//#include<boost/multiprecision/cpp_int.hpp>
#define int int64_t
#define uint uint64_t
#define REP(i, a, b) for (int64_t i = (int64_t)(a); i < (int64_t)(b); i++)
#define rep(i, a) REP(i, 0, a)
#define SZ(X) ((int64_t)((X).size()))
#define ITR(x, a) for (auto x = a.begin(); x != a.end(); x++)
#define ALL(a) (a.begin()), (a.end())
#define HAS(a, x) (a.find(x) != a.end())
#define Min(x) *min_element(ALL(x))
#define Max(x) *max_element(ALL(x))
#define Unique(L) (L.erase(unique(ALL(L)), L.end()))
#define intmax (std::numeric_limits<int64_t>::max() / 4)
#define doublemax (std::numeric_limits<double>::max() / 4)
using namespace std;
//typedef boost::multiprecision::cpp_int bigint;
const double EPS = 1e-9;
const double PI = acos(-1.0);



class modint {
	//MODが素数であることを前提として実装してあるが、その判定はしていない。
	//あまりが出るような除算をしてはいけない。
private:
	static const int MOD = 1000000007;
public:
	modint() {
		//assert(is_prime(MOD));
		this->number = 0;
	}
	modint(const int src) {
		//assert(is_prime(MOD));
		this->number = opposit(src);
	}
	modint(const modint &src) {
		this->number = src.number;
	}

	modint& operator += (const modint& obj) {
		this->number = san2(this->number + obj.number);
		return *this;
	}
	modint& operator -= (const modint& obj) {
		this->number = san2(this->number - obj.number + MOD);
		return *this;
	}
	modint& operator *= (const modint& obj) {
		this->number = (this->number * obj.number) % MOD;
		return *this;
	}
	modint& operator /= (const modint& obj) {
		this->number = (this->number * inverse(obj.number)) % MOD;
		return *this;
	}
	modint& operator += (const int n) {
		this->number = san2(this->number + opposit(n));
		return *this;
	}
	modint& operator -= (const int n) {
		this->number = san2(this->number - opposit(n) + MOD);
		return *this;
	}
	modint& operator *= (const int n) {
		this->number = (this->number * opposit(n)) % MOD;
		return *this;
	}
	modint& operator /= (const int n) {
		this->number = (this->number * inverse(n)) % MOD;
		return *this;
	}

	modint operator + (const modint obj) { modint re(*this); return re += obj; }
	modint operator - (const modint obj) { modint re(*this); return re -= obj; }
	modint operator * (const modint obj) { modint re(*this); return re *= obj; }
	modint operator / (const modint obj) { modint re(*this); return re /= obj; }
	modint operator + (const int n) { modint re(*this); return re += n; }
	modint operator - (const int n) { modint re(*this); return re -= n; }
	modint operator * (const int n) { modint re(*this); return re *= n; }
	modint operator / (const int n) { modint re(*this); return re /= n; }

	modint operator = (const int n) {
		this->number = opposit(n);
		return *this;
	}
	int get() {
		return number;
	}

private:
	int number;

	int opposit(int n) {
		if (n < 0)n = MOD - ((-n) % MOD);
		return n % MOD;
	}
	int inverse(int n) {
		n = opposit(n);
		int result = 1;
		for (int i = MOD - 2; i; i /= 2) {
			if (i % 2)result = (result * n) % MOD;
			n = (n * n) % MOD;
		}
		return result;
	}
	inline int san2(const int n) {
		return MOD <= n ? n - MOD : n;
	}
	bool is_prime(int n) {
		if (n <= 1)return false;
		if (n == 2)return true;
		if (n % 2 == 0) return false;
		const int upperbound = int(sqrt(n));
		for (int i = 3; i <= upperbound; i += 2) {
			if (n % i == 0) return false;
		}
		return true;
	}
};



//int n;
//vector<int>memo;
//
//modint solve(int x) {
//	if (x == 1)return n;
//	if (x <= 0)return 1;
//	if (memo[x] != -1)return modint(memo[x]);
//
//	modint ans = solve(x - 1);//左端に1を入れる場合
//
//	for (int i = 2; i <= n; i++) {
//		ans += solve(x - i - 1);//左端にiを入れて、その次に1を入れた場合
//		ans += n - 1;
//	}
//	memo[x] = ans.get();
//	return ans;
//}
//
//
//signed main() {
//	cin.tie(0);
//	ios::sync_with_stdio(false);
//
//	cin >> n;
//	memo = vector<int>(n + 1, -1);
//
//	cout << solve(n).get() << endl;
//
//	return 0;
//

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);


	int n;
	cin >> n;

	vector<modint>dp(n + 1, 0);
	dp[0] = 1;
	dp[1] = n;

	modint dpacc = 0;//dp[i-3]からdp[i-1-n]までの総和。ただしdp[0以下]=1とする
	for (int i = 2; i <= n; i++) {
		if (i == 2)dpacc = n - 1;
		else {
			int addindex = i - 3;
			int subindex = i - 2 - n;
			if (addindex <= 0)dpacc += 1;
			else dpacc += dp[addindex];
			if (subindex <= 0)dpacc -= 1;
			else dpacc -= dp[subindex];
		}
		dp[i] = dp[i - 1];
		dp[i] += modint(n - 1) * modint(n - 1);
		dp[i] += dpacc;
	}

	cout << dp[n].get() << endl;

	return 0;
}



Measured memory_bytes: 8064