#include #include #include using namespace std; #define MOD 1000000007 #define ull unsigned long long int template struct fast_fact { ull m(ull a, ull b) const { ull r = (a*b) % mod; return r; } template ull m(ull a, ull b, Ts...ts) const { return m(m(a, b), ts...); } // calculates x!!, ie 1*3*5*7*... ull double_fact(ull x) const { ull ret = 1; for (ull i = 3; i < x; i += 2) { ret = m(i, ret); } return ret; } // calculate 2^2^n for n=0...bits in ull // a pointer to this is stored statically to make calculating // 2^k faster: ull const* get_pows() const { static ull retval[sizeof(ull) * 8] = { 2 % mod }; for (int i = 1; i < sizeof(ull) * 8; ++i) { retval[i] = m(retval[i - 1], retval[i - 1]); } return retval; } // calculate 2^x. We decompose x into bits // and multiply together the 2^2^i for each bit i // that is set in x: ull pow_2(ull x) const { static ull const* pows = get_pows(); ull retval = 1; for (int i = 0; x; ++i, (x = x / 2)){ if (x & 1) retval = m(retval, pows[i]); } return retval; } // the actual calculation: ull operator()(ull x) const { x = x%mod; if (x == 0) return 1; ull result = 1; // odd case: if (x & 1) result = m((*this)(x - 1), x); else result = m(double_fact(x), pow_2(x / 2), (*this)(x / 2)); return result; } }; template ull factorial_mod(ull x) { return fast_fact()(x); } int main(){ long long int n; scanf("%lld", &n); if (n >= MOD){ puts("0"); return 0; } long long int c = factorial_mod(n); printf("%lld\n", c); return 0; }