intmain(){ cin >> n >> v; if (v >= n - 1) returnprintf("%d", n - 1), 0; int tot = v, ans = v; for (int i = 2; i <= n; i++) { tot--; if (tot < n - i) { int nd = min(n - i - tot, v - tot); tot += nd; ans += i * nd; } } cout << ans << endl; return0; }
string s; boolcheck(string s){ for (int i = 0; i < s.length(); i++) if (s[i] != s[s.length() - 1 - i]) return0; return1; }
intmain(){ ios::sync_with_stdio(false); cin >> s; int n = s.length(), flag = 1; for (int i = 1; i < n / 2; i++) if (s[i] != s[i - 1]) { flag = 0; break; } if (flag) returnputs("Impossible"), 0; for (int i = 1; i < n - 1; i++) { string t = s.substr(i) + s.substr(0, i); if (s == t) continue; if (check(t)) returnputs("1"), 0; } puts("2"); return0; }
int f[maxn], inv[maxn], finv[maxn]; voidinit(){ inv[1] = 1; for (int i = 2; i < maxn; i++) inv[i] = (mod - mod / i) * 1ll * inv[mod % i] % mod; f[0] = finv[0] = 1; for (int i = 1; i < maxn; i++) { f[i] = f[i - 1] * 1ll * i % mod; finv[i] = finv[i - 1] * 1ll * inv[i] % mod; } } intC(int n, int m){ if (m < 0 || m > n) return0; return f[n] * 1ll * finv[n - m] % mod * finv[m] % mod; } ll qpow(ll x, ll n){ ll r = 1; while (n > 0) { if (n & 1) r = r * x % mod; n >>= 1; x = x * x % mod; } return r; } ll T(ll n, ll k){ if (k == n) return1; return k * qpow(n, n - k - 1) % mod; }
int n, m, a, b;
intmain(){ init(); cin >> n >> m >> a >> b; ll ans = 0; for (int i = 1; i < n; i++) { ll tot = 1ll * C(m - 1, i - 1) * C(n - 2, i - 1) % mod * f[i - 1] % mod * qpow(m, n - i - 1) % mod * T(n, i + 1) % mod; ans += tot; if (ans >= mod) ans -= mod; } cout << ans << endl; return0; }