## ADACAROT Statement

Ada the Ladybug is a great farmer. She has many places where she grows vegetables. She wants to grow two completely different kinds of vegetable: carrots and baby carrots. She wants to connect them by paths in such way, that she can get from any carrot (or baby carrot) to any other carrot (or baby carrot). She isn’t amused by building itself, so she wants to make least number of paths, which is sufficient to make all carrots (and all baby carrots) connected. Due to regulations of Earwigean Union (EU), a carrot can’t be connected to other carrot (and same is true for baby carrots) [so basically, she can connect only “baby carrots” to “carrots”]. Ada also wants to keep track of everything, so she will somehow distinguish between each carrot and between each baby carrot (and also between each place).

She is wondering in how many ways she can plant carrots (and baby carrots) and connect them by ways, so that it corresponds to EU regulations.

### Input

The input contains up to 200 lines. Each line consists of single integer 2 ≤ N ≤ 2*105 , the number of places to which carrots/baby carrots shall be placed (note that she won’t waste so she will fill all the places).

### Output

For each line of input, print the number of ways, to plant carrots and baby carrots in such way, that it coresponds to EU regulations. Since this number might be pretty big, output it modulo 109+7 (1000000007)

## ADACAROT System

0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
#pragma comment(linker, "/stack:200000000") #pragma GCC optimize("Ofast") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") #define _CRT_SECURE_NO_WARNINGS /****Author: Barish Namazov****/ /* Number of spanning trees in complete bipartite graph is: X^{Y - 1} * Y^{X - 1} So, we have to calculate answer for each X = i, Y = n - i where 1 <= i < n then multiply answer by n! because of permutations of items */ #include <bits/stdc++.h> using namespace std; const int maxx = 100005; int powmod (int a, int b, int mod) { int res = 1; a %= mod; for (; b; b >>= 1) { if (b & 1) res = (1LL * res * a) % mod; a = (1LL * a * a) % mod; } return res; } const int MOD = 1e9 + 7; int fac[maxx << 1]; int main() { ios_base :: sync_with_stdio(0); cin.tie(0); fac[0] = 1; for (int i = 1; i < maxx << 1; i++) { fac[i] = 1LL * fac[i - 1] * i % MOD; } int n; while (cin >> n) { int res = 0; for (int i = 1; i <= n - 1; i++) { res = (res + (1LL * powmod(i, n - i - 1, MOD) * powmod(n - i, i - 1, MOD) % MOD)) % MOD; } res = (1LL * res * fac[n]) % MOD; cout << res << endl; } return 0; } |