// #define DEBUGGING
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define ALL(V) (V).begin(), (V).end()
#define ALLR(V) (V).rbegin(), (V).rend()

template <typename T> using V = vector<T>;
template <typename T> using VV = V<V<T>>;
using ll = int64_t;
using ull = uint64_t;
using PLL = pair<ll, ll>;

template <typename T> const T& var_min(const T &t) { return t; }
template <typename T> const T& var_max(const T &t) { return t; }
template <typename T, typename... Tail> const T& var_min(const T &t, const Tail&... tail) { return min(t, var_min(tail...)); }
template <typename T, typename... Tail> const T& var_max(const T &t, const Tail&... tail) { return max(t, var_max(tail...)); }
template <typename T, typename... Tail> void chmin(T &t, const Tail&... tail) { t = var_min(t, tail...); }
template <typename T, typename... Tail> void chmax(T &t, const Tail&... tail) { t = var_max(t, tail...); }
template <typename T> const T& clamp(const T &t, const T &low, const T &high) { return max(low, min(high, t)); }
template <typename T> void chclamp(T &t, const T &low, const T &high) { t = clamp(t, low, high); }

namespace init__ {

struct InitIO {
    InitIO() {
        cin.tie(nullptr);
        ios_base::sync_with_stdio(false);
        cout << fixed << setprecision(30);
    }
} init_io;

}

#ifdef DEBUGGING
// #include "../debug/debug.cpp"
#include "../../debug/debug.cpp"
#else
#define DEBUG(...) 0
#define DEBUG_SEPARATOR_LINE 0
#endif

template <typename T>
T make_v(T init) { return init; }

template <typename T, typename... Tail>
auto make_v(T init, size_t s, Tail... tail) {
#define rec make_v(init, tail...)
    return V<decltype(rec)>(s, rec);
#undef rec
}

template <typename T>
class Bit {
private:
    V<T> data;
    T identity_ele;

public:
    Bit(ll size, T identity_ele) : identity_ele(identity_ele) {
        ll newsize = 1;
        while(newsize < size) {
            newsize = newsize << 1;
        }
        data = V<T>(newsize + 1, identity_ele);
    }

    /*
     * 0-origin
     * sum of [0, pos)
     */
    T sum(ll pos) {
        T ret = identity_ele;
        while(pos > 0) {
            ret += data[pos];
            pos -= pos & -pos;
        }
        return ret;
    }

    /*
     * 0-origin
     * sum of [l, r)
     */
    T sum(ll l, ll r) {
        return sum(r) - sum(l);
    }

    /*
     * 0-origin
     */
    void add(ll pos, T delta) {
        pos++;
        while(pos <= data.size()) {
            data[pos] = data[pos] + delta;
            pos += pos & -pos;
        }
    }
};

const ll mod = 1e9 + 7;

int main() {
    ll N;
    cin >> N;
    Bit<ll> bit(N + 10, 0), bit_just(N + 10, 0);
    bit.add(0, 1);
    bit.add(1, 1);
    bit.add(2, 1);
    bit.add(3, 2);
    bit_just.add(0, 1);
    bit_just.add(3, 1);
    for(ll i = 4; i <= N; i++) {
        ll sum = bit.sum(0, i - 3 + 1) % mod;
        ll just_sum = bit_just.sum(0, i) % mod;
        bit.add(i, (sum + just_sum) % mod);
        bit_just.add(i, sum);
        DEBUG(make_tuple("bit", i, sum));
    }
        
    // ..., 1, 1, 1, ...
    ll ans = bit_just.sum(0, N) % mod;
    DEBUG(ans);

    for(ll i = 1; i <= N; i++) {
        ll sum = bit.sum(i - 1, i);
        ll add_v;
        if(i < N) {
            DEBUG(sum);
            add_v = sum * (N - 1) % mod * (N - 1) % mod;
            add_v += sum * min<ll>(N - 1, (i + 1)) % mod;
        } else {
            add_v = sum * (N - 1)% mod;
        }
        
        DEBUG(add_v);
        // DEBUG(make_tuple(i, sum, sum, add_v));
        (ans += add_v) %= mod;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 16640