text
stringlengths
49
983k
#include <bits/stdc++.h> using namespace std; const long long int N = 4e5 + 10; struct Node { int a, b, ab, f; friend Node operator+(Node X, Node Y) { return {X.a + X.f * Y.a, Y.b + Y.f * X.b, max({X.ab, Y.ab, X.b + Y.a}), X.f && Y.f}; } }; long long int A[N]; int mx[N << 2], type[N], L[N], R[N], ...
#include <bits/stdc++.h> #pragma GCC target("pclmul") using ul = std::uint32_t; using ull = std::uint64_t; using li = std::int32_t; using ll = std::int64_t; using llf = long double; using us = std::uint16_t; const ul maxn = 1e5; const ul maxlen = 1e5; const ul bu = 10; std::mt19937_64 rnd; class node { public: ul lc...
#include <bits/stdc++.h> #pragma GCC target("pclmul") using ul = std::uint32_t; using ull = std::uint64_t; using li = std::int32_t; using ll = std::int64_t; using llf = long double; using us = std::uint16_t; const ul maxn = 1e5; const ul maxlen = 1e5; const ul bu = 20; std::mt19937_64 rnd; class node { public: ul lc...
#include <bits/stdc++.h> using namespace std; const int MAX = 1e5 + 5; const int SQ = 102; int n, q; string s[MAX]; int lcp[MAX]; set<int> active; const int LIM = 3e5 + 5; struct node { int lsuf[SQ], rsuf[SQ], maxi, len; node() { maxi = len = 0; for (int i = 0; i < SQ; i++) { lsuf[i] = rsuf[i] = 0; ...
#include <bits/stdc++.h> #pragma GCC target("pclmul") using ul = std::uint32_t; using ull = std::uint64_t; using li = std::int32_t; using ll = std::int64_t; using llf = long double; using us = std::uint16_t; const ul maxn = 1e5; const ul maxlen = 1e5; const ul bu = 18; std::mt19937_64 rnd; class node { public: ul lc...
#include <bits/stdc++.h> using namespace std; const int maxn = 100005; const int B = 40; char s[maxn]; string a[maxn]; int lcp[maxn]; set<int> st; int n, q; int tmp_mx, tmp_suf[B + 1]; struct SegmentTree { int pre[B + 1][maxn * 2 + 1], suf[B + 1][maxn * 2 + 1]; int mx[maxn * 2 + 1]; inline int getID(int l, int r)...
#include <bits/stdc++.h> using namespace std; #pragma GCC optimize("O2,no-stack-protector,unroll-loops,fast-math") const int maxn = 1e5 + 10, maxm = 1e3 + 10, lg = 17, mod = 1e9 + 7, inf = 1e18; struct node { int mxm, pre, suf; bool por; node(int mxm = 0, int pre = 0, int suf = 0, bool por = 0) : mxm(mxm), ...
#include <bits/stdc++.h> #pragma GCC optimize("O2") using namespace std; const int N = 1e5 + 10; const long long mod = 1e9 + 7; const long long mod2 = 998244353; const long long inf = 8e18; const int LOG = 22; const int SQ = 320; long long pw(long long a, long long b, long long M) { return (!b ? 1 : (b &...
#include <bits/stdc++.h> using namespace std; template <int n> using AI = array<int, n>; const double eps = 1e-9; const int oo = 0x3F3F3F3F; const long long ooLL = 0x3F3F3F3F3F3F3F3FLL; const int MOD = 1000000007; template <typename T> T sqr(T x) { return x * x; } const double PI = acos(-1.); long long Round(double x...
#include <bits/stdc++.h> using namespace std; template <typename T = int> struct Max { T val; const T nut = numeric_limits<T>::min(); Max() { val = nut; } Max(const T& _val) { val = _val; } void operator=(const Max& o) { val = o.val; } Max operator+(const Max& o) { return val > o.val ? val : o.val; } }; int...
#include <bits/stdc++.h> using namespace std; const int MOD = 1e9 + 7; const int SIZE = 1 << 17; string s[SIZE]; int h[SIZE]; int ma[SIZE * 2 + 100]; vector<pair<int, int> > stkL[SIZE * 2 + 100], stkR[SIZE * 2 + 100]; void pre(int n) { for (int i = (2); i < (n + 1); ++i) { while (h[i] < min(((int)(s[i - 1]).size(...
#include <bits/stdc++.h> using namespace std; char str[700000]; int Max[700000], L[700000], R[700000], ls[700000], rs[700000], root[700000], tot = 0, lcp[700000], n, last[700000], a[700000], sta[700000], tmp[700000]; inline int read() { int x = 0, f = 1; char ch = getchar(); while (ch < '0' || ch > '9') { ...
#include <bits/stdc++.h> using namespace std; int N, Q; string S[100005]; char Str[100005]; int X[100005]; int Left[45][400005], Right[45][400005], Arb[45][400005]; int Arb2[400005]; const int limit = 40; int Right2, ans; set<int> P; int Next[100005], Prev[100005]; int Aux[100005], Stack[100005]; void Read() { scanf(...
#include <bits/stdc++.h> using namespace std; long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); } const int MAXLEN = 100000; const int MAXN = 100000; const int MAXQ = 100000; const int MAXTN = MAXLEN + 1; const int MAXLG = 16; const int MAXSN = 4 * (MAXN - 1); const int MAXZN = 4 * MAXN; type...
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5; const int S = 80; int n, m, a[N]; string s[N]; struct item { int sum, suf[S + 1], pref[S + 1], ans; item(int x) { x = min(x, S); for (int i = 0; i <= S; i++) { suf[i] = pref[i] = (i <= x); } ans = x; sum = 1; } item()...
#include <bits/stdc++.h> template <typename T> T min(T x, T y) { return x < y ? x : y; } template <typename T> T max(T x, T y) { return x > y ? x : y; }; const int MAXN = 100005; struct tree1 { private: int mx; int l; int r; tree1 *lson; tree1 *rson; public: tree1() { mx = 0; lson = rson = NU...
#include <bits/stdc++.h> using namespace std; const int BUBEN = (int)110; struct Data { int goLeft[BUBEN], goRight[BUBEN]; int res; int length; Data(int x) { x = min(x, BUBEN - 1); res = x; length = 1; for (int i = 0; i < BUBEN; i++) { if (i <= x) { goLeft[i] = goRight[i] = 1; ...
#include <bits/stdc++.h> #pragma GCC optimize("O3") using namespace std; inline int getint() { int _x = 0; char _tc = getchar(); while (_tc < '0' || _tc > '9') _tc = getchar(); while (_tc >= '0' && _tc <= '9') _x *= 10, _x += (_tc - '0'), _tc = getchar(); return _x; } int st[202020 << 1]; void modify(int no, ...
#include <bits/stdc++.h> using namespace std; int n, Q, a[100005]; string s[100005]; int LCP(const string &a, const string &b) { int r = 0; for (; r < a.size() && r < b.size() && a[r] == b[r]; r++) ; return r; } int lc[100005 * 100], rc[100005 * 100], lx[100005 * 100], rx[100005 * 100], mx[100005 * 100], ...
#include <bits/stdc++.h> using namespace std; template <typename T = int> struct Max { T val; const T nut = numeric_limits<T>::min(); Max() { val = nut; } Max(const T& _val) { val = _val; } void operator=(const Max& o) { val = o.val; } Max operator+(const Max& o) const { return val > o.val ? val : o.val; } ...
#include <bits/stdc++.h> #pragma GCC target("pclmul") using ul = std::uint32_t; using ull = std::uint64_t; using li = std::int32_t; using ll = std::int64_t; using llf = long double; using us = std::uint16_t; const ul maxn = 1e5; const ul maxlen = 1e5; const ul bu = 50; std::mt19937_64 rnd; class node { public: ul lc...
#include <bits/stdc++.h> using namespace std; template <typename T = int> struct Max { T val; const T nut = numeric_limits<T>::min(); Max() { val = nut; } Max(const T& _val) { val = _val; } void operator=(const Max& o) { val = o.val; } Max operator+(const Max& o) const { return val > o.val ? val : o.val; } ...
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") #pragma GCC target("sse,sse2,sse3,sse3,sse4,popcnt,abm,mmx") const int N = (int)5e5 + 7, inf = (int)1e9 + 7, mod = (int)1e9 + 7; const long long linf = (long long)1e18 + 7; const int dx[] = {-1, 0, 1, 0, 1, -1, -1, 1}, dy[] = {0, 1, 0, -1, 1, -1, 1, -1}; ...
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const long long LINF = 0x3f3f3f3f3f3f3f3fll; const long long MAX = (long long)1e5 + 10; long long fat[] = {1, 1, 2, 6, 24}; long long comb(int n, int k) { long long ret = 1; for (int i = 0; i < k; i++) { ret *= n - i; } ret /= fat[k];...
#include <bits/stdc++.h> using namespace std; int main() { long long n, k, a[4]; cin >> n >> k; a[0] = 1; a[1] = n * (n - 1) / 2; a[2] = n * (n - 1) * (n - 2) / 6 * 2; a[3] = n * (n - 1) * (n - 2) * (n - 3) / 24 * (3 + 6); long long ans = 0; for (int i = 0; i < k; i++) ans += a[i]; cout << ans << endl...
#include <bits/stdc++.h> using namespace std; const long long mod = 1000000007; const long long INF = 0x3f3f3f3f3f3f3f3f; const double eps = 1e-6; template <class T> T gcd(T a, T b) { if (!b) return a; return gcd(b, a % b); } const int maxn = 1e3 + 10; long long c(int x, int y) { long long res = 1; for (int i =...
#include <bits/stdc++.h> using namespace std; long long derangements(long long n) { if (n == 0) return 1; if (n == 1) return 0; if (n == 2) return 1; return (n - 1) * (derangements(n - 1) + derangements(n - 2)); } long long nCr(long long n, long long r) { long long res = 1; if (r == 0) return res; for (lo...
#include <bits/stdc++.h> using namespace std; const int N = 5e5 + 10, eps = 1e-10; const double pi = acos(-1); int n, k; long long a[1100]; void init() { a[1] = 0, a[2] = 1; for (int i = (3); i < (1100); ++i) a[i] = (i - 1) * (a[i - 1] + a[i - 2]); } long long C(int a, int b) { long long res = 1; for (int i = (...
#include <bits/stdc++.h> using namespace std; const long long mod = 998244353; long long cmb(long long n, long long k) { double res = 1; for (long long i = 0; i < k; i++) { res *= (n - i); res /= (i + 1); } return (long long)(res + 0.1); } int main() { ios_base::sync_with_stdio(0); long long n, k; ...
#include <bits/stdc++.h> using namespace std; long long C(long long n, long long r) { long long C[r + 1]; memset(C, 0, sizeof(C)); C[0] = 1; for (long long i = 1; i <= n; i++) for (long long j = min(i, r); j > 0; j--) C[j] = (C[j] + C[j - 1]); return C[r]; } long long factorial[1000]; void fact(long long ...
#include <bits/stdc++.h> using namespace std; inline long long input() { int32_t x; scanf("%d", &x); return x; } inline long long in() { int32_t x; scanf("%d", &x); return x; } const long long maxn = 2e5 + 10; const long long mod = 1e9 + 7; long long C(long long n, long long r) { long long ans = 1; for ...
#include <bits/stdc++.h> using namespace std; long long nc2(long long n) { return (n * (n - 1)) / 2; } long long nc3(long long n) { return (n * (n - 1) * (n - 2)) / 6; } long long nc4(long long n) { return (n * (n - 1) * (n - 2) * (n - 3)) / 24; } int main() { int n, k; cin >> n >> k; long long ans = 1; for (in...
#include <bits/stdc++.h> using namespace std; const int MAX_N = -1; const int inf = 2e9 + 19; long long n, k, dp[5]; int main() { ios::sync_with_stdio(false), cin.tie(0), cout.tie(0); cin >> n >> k; dp[1] = 1; dp[2] = (n * (n - 1) / 2) + dp[1]; dp[3] = (((n * (n - 1) * (n - 2)) / 6) * 2) + dp[2]; dp[4] = ((...
#include <bits/stdc++.h> using namespace std; long long N, K; long long ans; int A[] = {1, 1, 2, 6, 24}; int B[] = {1, 1, 2, 9}; long long com(long long n, long long k) { long long res = 1; for (long long i = 0; i < k; i++) { res *= (n - i); } return res / A[k]; } int main() { scanf("%lld%lld", &N, &K); ...
#include <bits/stdc++.h> using namespace std; vector<long long> der(int k) { vector<long long> res; res.push_back(0); res.push_back(1); for (long long i = 3; i <= k; i++) { int n1 = res[i - 2]; int n2 = res[i - 3]; int cur = (i - 1) * (n1 + n2); res.push_back(cur); } return res; } long long ...
#include <bits/stdc++.h> using namespace std; long long int derange[1001]; long long int nCr(long long int n, long long int r) { long double ans = 1; long double upto = min(n - r, r); for (long double j = n, i = 1; j > upto; j--, i++) ans *= (j / i); return round(ans); } int main() { ios_base ::sync_with_stdi...
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:100000000") using namespace std; int main() { int n, k; cin >> n >> k; if (k == 1) cout << 1; else if (k == 2) cout << n * (n - 1) / 2 + 1; else if (k == 3) cout << n * 1LL * (n - 1) * (n - 2) / 3 + n * (n - 1) / 2 + 1; else cout << n ...
#include <bits/stdc++.h> using namespace std; long long c(long long n, long long k) { long long numerator = 1; long long i; vector<int> v(k - 1); for (i = 0; i < v.size(); i++) v[i] = i + 2; for (i = 0; i < k; i++) { numerator = (numerator * (n - i)); for (int j = 0; j < k - 1; j++) if (numerato...
#include <bits/stdc++.h> using namespace std; const int maxN = 1e3; string st; int n; long long tot; bool v[7]; void rec(long long s, long long curC) { if (curC == s) { tot++; return; } for (int i = 0; i < s; i++) { if (!v[i] && curC != i) { v[i] = true; rec(s, curC + 1); v[i] = fals...
#include <bits/stdc++.h> using namespace std; const long long N = 1e3 + 5; long long C[N][5], dif_fact[5]; void calc() { for (long long i = 0; i < N; i++) { for (long long j = 0; j <= min(i, 4LL); j++) { if (j == 0 || j == i) { C[i][j] = 1; } else { C[i][j] = C[i - 1][j - 1] + C[i - 1]...
#include <bits/stdc++.h> using namespace std; inline void solve() { long long n, k; cin >> n >> k; long long ans = 0; if (k >= 1) { ans++; } if (k >= 2) { ans += n * (n - 1) / 2; } if (k >= 3) { ans += n * (n - 1) * (n - 2) / 3; } if (k >= 4) { ans += n * (n - 1) * (n - 2) * (n - 3) ...
#include <bits/stdc++.h> using namespace std; using ll = long long; using lld = long double; using vi = vector<int>; using vll = vector<long long>; ll factorial(ll n) { if (n == 0) { return 1; } return (n * factorial(n - 1)); } ll choose(ll n, ll k) { ll res = 1; for (ll i = 0; i < k; i++) { res *= (n...
#include <bits/stdc++.h> using namespace std; long long d[10], dp[1111][11], n, k; long long c(long long x, long long y) { long long p = 1, q = 1, z; for (long long i = 0; i < y; i++) { p *= (x - i); q *= (1 + i); } p /= q; return p; } int main() { cin >> n >> k; d[0] = 1; for (long long i = 2; ...
#include <bits/stdc++.h> using namespace std; long long f[10], c[1005][1005]; int main() { f[0] = 1; f[1] = 0; f[2] = 1; f[3] = 2; f[4] = 9; int n, k; scanf("%d%d", &n, &k); for (int i = 1; i <= n; i++) { c[i][0] = c[i][i] = 1; for (int j = 1; j < i; j++) { c[i][j] = c[i - 1][j] + c[i - 1]...
#include <bits/stdc++.h> using namespace std; long long int de[101]; long long int cmb[1001][5]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); de[0] = 1; de[1] = 0; for (long long int i = 2; i < 101; i++) { de[i] = i * de[i - 1] + ((i % 2 == 0) ? 1 : -1); } cmb[1][1] = 1; cmb[1][0] =...
#include <bits/stdc++.h> using namespace std; long long int m[] = {1, 0, 1, 2, 9}; long long int res; long long int ch(int n, int k) { long long int r = 1; long long int s = 1; for (int i = n; i > n - k; i--) { r *= i; } for (int i = 2; i <= k; i++) { s *= i; } return r / s; } int main() { ios_b...
#include <bits/stdc++.h> using namespace std; const long long int M = 1e9 + 7; const double pi = 3.141592653589793238463; inline long long int add(long long int x, long long int y) { if (x + y >= M) return x + y - M; return x + y; } inline long long int sub(long long int x, long long int y) { if (x - y < 0) retur...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false), cin.tie(0), cout.tie(0); long long n, k; while (cin >> n >> k) { long long ans = 0; for (int i = 0; i <= k; i++) { if (i == 0) ans += 1; if (i == 2) ans += (n * (n - 1)) / 2; if (i == 3) ans += n * (n...
#include <bits/stdc++.h> using namespace std; long long binomial_coeff[1005][1005]; int main(int argc, char const *argv[]) { int n, k; cin >> n >> k; for (int i = 0; i <= 1000; i++) for (int j = 0; j <= 1000; j++) binomial_coeff[i][j] = 0; for (int i = 0; i <= 1000; i++) binomial_coeff[i][0] = 1; for (int...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long n, k; cin >> n >> k; long long d[5]; d[0] = 0; d[1] = 0; d[2] = 1; d[3] = 2; d[4] = 9; long long ans = 0; for (long long i = 0; i <= k; i++) { if (i == 0) {...
#include <bits/stdc++.h> #pragma warning(disable : 4996) using namespace std; int n, k; long long ans = 1; long long c(int n, int i) { long long a = 1, b = 1; for (int j = 0; j < i; j++) { a = a * (n - j); b = b * (j + 1); } return a / b; } int main() { cin >> n >> k; for (int i = 1; i <= k; i++) { ...
#include <bits/stdc++.h> using namespace std; long long d[5] = {1, 0, 1, 2, 9}; long long fact[6] = {1, 1, 2, 6, 24, 120}; long long nck(long long n, long long k) { long long ans = 1; long long mul = n; for (int i = 0; i < k; ++i) { ans = ans * mul; mul -= 1; } ans /= fact[k]; return ans; } int main...
#include <bits/stdc++.h> using namespace std; long long n, k, ans = 1; int main() { scanf("%lld %lld", &n, &k); if (k >= 2) ans += n * (n - 1) / 2; if (k >= 3) ans += 2 * n * (n - 1) * (n - 2) / 6; if (k >= 4) ans += 9 * n * (n - 1) * (n - 2) * (n - 3) / 24; printf("%lld\n", ans); }
#include <bits/stdc++.h> using namespace std; int main() { long long n, k, ans; cin >> n >> k; if (k == 1) ans = 1; else if (k == 2) ans = 1 + n * (n - 1) / 2; else if (k == 3) ans = 1 + n * (n - 1) / 2 + 2 * n * (n - 1) * (n - 2) / 6; else if (k == 4) ans = 1 + n * (n - 1) / 2 + 2 * n * (n ...
#include <bits/stdc++.h> using namespace std; const int MOD = (int)1e9 + 7; const int FFTMOD = 1007681537; const int INF = (int)1e9; const long long LINF = (long long)1e18; const long double PI = acos((long double)-1); const long double EPS = 1e-9; inline long long gcd(long long a, long long b) { long long r; while...
#include <bits/stdc++.h> using namespace std; const long long int maxn = 1e3 + 5, M = 11; const long long int inf = 1e9 + 7; long long int c[maxn][maxn], n, k, p[M]; int main() { cin >> n >> k; for (long long int i = 0; i < n + 1; i++) c[i][0] = c[i][i] = 1; for (long long int i = 1; i < n + 1; i++) for (long...
#include <bits/stdc++.h> using namespace std; const int d[] = {0, 0, 1, 2, 9}; int main() { long long n, k; while (cin >> n >> k) { long long ans = 1; for (long long i = 2; i <= k; i++) { long long C = n; for (int j = 1; j < i; j++) C = C * (n - j) / (j + 1); ans += C * d[i]; } cou...
#include <bits/stdc++.h> using namespace std; typedef priority_queue<int> pqi1; typedef priority_queue<int, vector<int>, greater<int>> pqi2; long long derange[1001]; long long fact(long long n) { long long ans = 1; for (long long i = 2; i <= n; i++) { ans *= i; } return ans; } long long choose(long long n, ...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); double n, k; cin >> n >> k; long long aux = n; long long ans = 0; long long d[5]; double com[5]; d[1] = 0; d[2] = 1; d[3] = 2; d[4] = 9; com[1] = n; com[2] = n * (n - 1) / 2; com[3] = n * (...
#include <bits/stdc++.h> using namespace std; long long ans = 0, n, k, c[1010][1010] = {0}, m[6] = {0, 0, 1, 2, 9, 44}; int main() { long long n, k, i, j; cin >> n >> k; c[0][0] = 1; for (i = 1; i <= 1000; i++) { c[i][0] = 1; for (j = 1; j <= i; j++) c[i][j] = c[i - 1][j - 1] + c[i - 1][j]; } for (j...
#include <bits/stdc++.h> using namespace std; int main() { long long int n, k, i, j; cin >> n >> k; long long int d[5]; d[1] = 0, d[2] = 1, d[3] = 2, d[4] = 9; if (k == 1) return cout << 1, 0; long long int r = 0; for (i = 2; i <= k; i++) { long long int ans = 1, f = 1; for (j = n; j > (n - i); j-...
#include <bits/stdc++.h> using namespace std; int dx[] = {0, 0, 1, -1, 1, -1, 1, -1}; int dy[] = {1, -1, 0, 0, -1, 1, 1, -1}; long long gcd(long long a, long long b) { return !b ? a : gcd(b, a % b); } long long lcm(long long a, long long b) { return (a / gcd(a, b)) * b; } void PLAY() { cout << fixed << setprecision(1...
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:5000000000") const long long m = 1000000007; const int INF = 1000000000; using namespace std; int main() { long long n, k; cin >> n >> k; long long ans1, ans2, ans3, ans4; ans1 = 1; ans2 = ans1 + (n * (n - 1)) / 2; ans3 = 2 * ((n * (n - 1) * (n - 2)) ...
#include <bits/stdc++.h> using namespace std; void DBG() { cerr << "]\n"; } template <typename T, typename... Args> void DBG(T first, Args... args) { cerr << first; if (sizeof...(args)) cerr << ", "; DBG(args...); } long long ncr(long long n, long long k) { k = n - k; long long fact = 1; long long num = 1; ...
#include <bits/stdc++.h> using namespace std; long long a[10]; int main() { int n, k; while (scanf("%d %d", &n, &k) != EOF) { long long ans = 0; a[4] = 1ll * n * (n - 1) * (n - 2) * (n - 3) / 24 * 9; a[3] = 1ll * n * (n - 1) * (n - 2) / 6 * 2; a[2] = 1ll * n * (n - 1) / 2; a[1] = 0; a[0] = 1...
#include <bits/stdc++.h> using namespace std; long long select(long long n, long long k) { if (k == 2) { return (n * (n - 1)) / 2; } if (k == 3) { return (n * (n - 1) * (n - 2)) / 6; } if (k == 4) { return (n * (n - 1) * (n - 2) * (n - 3)) / 24; } return 0; } long long d(long long num) { if ...
#include <bits/stdc++.h> int main() { long long n, k; scanf("%lld %lld", &n, &k); long long res = 1 + (k >= 2) * (n * (n - 1) / 2) * 1 + (k >= 3) * (n * (n - 1) * (n - 2) / 6) * 2 + (k >= 4) * (n * (n - 1) * (n - 2) * (n - 3) / 24) * 9; printf("%lld\n", res); return 0; }
#include <bits/stdc++.h> using namespace std; int main() { long long int sum = 0; long long int n, k; cin >> n >> k; switch (k) { case 4: { long long int t; t = n * (n - 1) * (n - 2) * (n - 3) / 24 * 9; sum += t; } case 3: { long long int t; t = n * (n - 1) * (n - 2) / ...
#include <bits/stdc++.h> using namespace std; long long int ncr(long long int n, long long int r) { long long int ret = 1; for (long long int i = n; i > n - r; i--) ret *= i; for (long long int i = 1; i <= r; i++) ret /= i; return ret; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(...
#include <bits/stdc++.h> using namespace std; long long n, k, n1, n2, n3, n4; int main() { cin >> n >> k; n1 = 1; n2 = n1 + n * (n - 1) / 2; n3 = n2 + n * (n - 1) * (n - 2) / 3; n4 = n3 + n * (n - 1) * (n - 2) * (n - 3) * 3 / 8; if (k == 1) cout << n1; else if (k == 2) cout << n2; else if (k == ...
#include <bits/stdc++.h> using namespace std; int n, k; long long ans = 1, t[1010][1010]; long long ncr(int n, int r) { if (r == 0 || n == r) return 1; if (t[n][r] != 0) return t[n][r]; t[n][r] = ncr(n - 1, r) + ncr(n - 1, r - 1); return t[n][r]; } int main() { cin >> n >> k; if (k > 1) { ans += ncr(n, ...
#include <bits/stdc++.h> using namespace std; long long const INF = INT_MAX; const long long MOD = 998244353; const long long N = 8e5 + 1; void SpeedForce() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); } int simple(int n) { int i, sq; if (n % 2 == 0) { return 0; } sq = (int)sqrt(n); for ...
#include <bits/stdc++.h> using namespace std; long long dp[5]; long long fat[1004]; long long pc(int n) { if (n == 1) return 0; if (n == 0) return 1; if (dp[n] != -1) return dp[n]; return dp[n] = (n - 1) * (pc(n - 1) + pc(n - 2)); } long long comb(long long a, long long b) { long long ret = 1; for (int i = ...
#include <bits/stdc++.h> using namespace std; int main() { long long n, k; long long ans; cin >> n >> k; if (k == 1) ans = 1; else if (k == 2) ans = n * (n - 1) / 2 + 1; else if (k == 3) ans = n * (n - 1) * (n - 2) / 3 + n * (n - 1) / 2 + 1; else if (k == 4) ans = 3 * n * (n - 1) * (n - 2)...
#include <bits/stdc++.h> using namespace std; const long long N = 1e5 + 5; const long long mod = 1000000007; long long n, ans = 1, k; long long jc[2 * N], inv[2 * N]; long long C(long long n, long long m); long long power(long long a, long long b); int main() { scanf("%lld%lld", &n, &k); if (k == 1) { printf("1...
#include <bits/stdc++.h> using namespace std; long long PI = acos(-1.0), MOD = 1000000007; long long n, m, x, y, z, k, sol, sum, ans, l, r, xx, yy, t; long long a[1000000], b[1000000], mem[1000][1000], pre[1000000], suff[1000000]; vector<pair<long long, long long> > v; vector<long long> v1; vector<long long> v2; vector...
#include <bits/stdc++.h> using namespace std; template <class T> struct rge { T b, e; }; template <class T> rge<T> range(T i, T j) { return rge<T>{i, j}; } struct debug { template <class T> debug& operator<<(const T&) { return *this; } }; using ll = long long; template <typename T> void min_self(T& a, T b...
#include <bits/stdc++.h> using namespace std; const int maxn = 3 * 100000 + 10; int a[maxn]; long long c(long long a, long long b) { if (b == 0) return 1; if (a - b < b) b = a - b; long long sum1 = 1; for (int i = a; i > a - b; i--) { sum1 = sum1 * i; } long long sum2 = 1; for (int i = b; i >= 1; i--)...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long n, i = 0, j = 0, k = 0, l = 0, m = 0, a = 0, b = 0, sum = 0, x = 0, y = 0, z = 0, c, p; cin >> n >> k; long long d[5], fac[5]; d[0] = 1; d[1] = 0; d[2] =...
#include <bits/stdc++.h> using namespace std; #pragma GCC optimize("O3") #pragma GCC target("sse4") const double PI = acos(-1.0); const long long mod = 1000000007; const long long INF = 1e9; const long long MAXN = 1000001; int main() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); long long n, k; cin >> ...
#include <bits/stdc++.h> using namespace std; template <class T> inline T binpow(T p, T e, T M) { long long int ret = 1; for (; e > 0; e >>= 1) { if (e & 1) ret = (ret * p) % M; p = (p * p) % M; } return (T)ret; } template <class T> inline T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b)...
#include <bits/stdc++.h> int main() { long long int n, k, m, z, y; while (scanf("%lld%lld", &n, &k) == 2) { m = 1 + n * (n - 1) / 2; z = m + n * (n - 1) * (n - 2) / 6 * 2; y = z + n * (n - 1) * (n - 2) * (n - 3) / 24 * 9; if (k == 1) { printf("1\n"); } else if (k == 2) { printf("%lld...
#include <bits/stdc++.h> using namespace std; long long fact(int n) { if (n < 2) return 1; return fact(n - 1) * n; } long long C(int n, int k) { long long ans = 1; for (int i = n - k + 1; i <= n; i++) ans *= i; return ans / fact(k); } long long mess(int n) { long long fn = fact(n); long long ans = 0; fo...
#include <bits/stdc++.h> using namespace std; long long int mod = 1000000007; int main() { long long int n, k, i; cin >> n >> k; long long int arr[5] = {0, 0, 1, 2, 9}; long long int prod = n; long long int ans = 0; for (i = 1; i <= k; i++) { ans += prod * arr[i]; prod *= (n - i); prod /= (i + 1...
#include <bits/stdc++.h> using namespace std; int main() { long long n, k; cin >> n >> k; vector<long long> v = {1, 0, 1, 2, 9}; long long ans = 0; for (long long i = k; i >= 0; i--) { long long tem = i; long long te = n; long long res = 1; while (tem--) { res *= te; res /= (i - te...
#include <bits/stdc++.h> using namespace std; const int MXN = 2e6 + 30; const int MAXN = 1e3 + 2; const long long INF = 1e9 + 7; const long long BINF = 1e15; const int MOD = 1e9 + 7; const long double EPS = 1e-15; const long long dx[] = {0, 0, 1, -1}; const long long dy[] = {1, -1, 0, 0}; long long n, k; long long cnt ...
#include <bits/stdc++.h> using namespace std; int32_t main() { ios::sync_with_stdio(false); cin.tie(0); long long der[5]; der[0] = 1; der[1] = 0; for (long long i = 2; i < 5; i++) der[i] = (i - 1) * (der[i - 1] + der[i - 2]); long long c[1001][1001]; for (long long i = 0; i <= 1000; i++) { c[i][...
#include <bits/stdc++.h> using namespace std; int n, k; int cc[5] = {1, 0, 1, 2, 9}; long long c[1010][1010]; int main(int argc, char const *argv[]) { for (int i = 1; i <= 1000; i++) { c[i][0] = 1; c[i][1] = i; c[i][i] = 1; } for (int i = 2; i <= 1000; i++) { for (int j = 2; j <= 4; j++) { c...
#include <bits/stdc++.h> using namespace std; long long binpow(long long a, long long b) { if (b == 0) return 1; long long res = binpow(a, b / 2); if (b % 2) return (res * res) * a; else return (res * res); } int mpow(int base, int exp, int mod) { base %= mod; int result = 1; while (exp > 0) { ...
#include <bits/stdc++.h> using namespace std; long long int nck(long long int n, long long int k) { long long int ans = 1; for (int i = 0; i < k; i++) { ans = ans * (n - i); } for (int i = 1; i <= k; i++) { ans = ans / i; } return ans; } int main() { int n, k; cin >> n >> k; long long int ans ...
#include <bits/stdc++.h> const long long INF = 2000000005; const long long BIG_INF = 2000000000000000005; const long long mod = 1000000007; const long long P = 31; const long double PI = 3.141592653589793238462643; const double eps = 1e-9; using namespace std; vector<pair<long long, long long> > dir = {{-1, 0}, {0, 1},...
#include <bits/stdc++.h> using namespace std; long long int M = 1e9 + 7; long long int n, k, m; long long int z, q, u, a1, l, r, ax, cx, ay, by, cy, ql, qr, d, x, y; multimap<long long int, long long int, greater<long long int>> s; long long int a[1000007]; long long int gh[15][100007]; long long int b[107]; long long ...
#include <bits/stdc++.h> using namespace std; long long C[1010][1010]; void dabiao() { C[0][0] = 1; for (int i = 1; i < 1010; ++i) { C[i][0] = 1; for (int j = 1; j <= i; ++j) C[i][j] = C[i - 1][j - 1] + C[i - 1][j]; } } int main() { dabiao(); int n, k; cin >> n >> k; if (k == 1) cout << 1 << e...
#include <bits/stdc++.h> using namespace std; long long ncr(long long n, long long r) { long long num = 1; for (int i = n; i > max(r, n - r); i--) num *= i; long long deno = 1; for (int i = 1; i <= min(r, n - r); i++) deno *= i; return num / deno; } void solve() { int n, k; cin >> n >> k; long long ans ...
#include <bits/stdc++.h> using namespace std; const long double EPS = 1e-9; const int N = 1e3 + 5; const int MOD = 1e9 + 7; const int INF = 0x3f3f3f3f; long long n, k; long long d[] = {1, 0, 1, 2, 9}; long long binom[N][N]; long long ans; int main() { scanf("%lld %lld", &n, &k); ans += d[0]; if (k >= 1) ans += d[...
#include <bits/stdc++.h> using namespace std; const int MX = 1 * 1e5 + 100; const long long INF = 1e18; int N, M, k; int arr[MX]; int cnt[33]; char s[MX]; long long nCk(long long n, long long k) { long long ans = 1; int kk = 0; while (kk != k) { ans = ans * (n - kk); kk++; } long long dd = 1; for (i...
#include <bits/stdc++.h> using namespace std; void boost() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); } int main() { boost(); long long n, k, t_cnt = 0; cin >> n >> k; long long k_value[5] = {0, 0, 1, 2, 9}; while (k) { if (k == 1) { t_cnt += 1; break; } l...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); int n, k; cin >> n >> k; if (k == 1) { cout << 1; return 0; } if (n == k) { cout << 24; return 0; } long long f2 = 1; for (int i = n - 2 + 1; i <= n; i++) { f2 *= i; } f2 ...
#include <bits/stdc++.h> using namespace std; int cuo[] = {1, 0, 1, 2, 9}; long long C[1100][5]; void init() { C[0][0] = 1; for (int i = 1; i <= 1000; i++) { C[i][0] = 1; for (int j = 1; j <= i && j <= 4; j++) C[i][j] = C[i - 1][j - 1] + C[i - 1][j]; } } int main() { int n, k; init(); while (s...
#include <bits/stdc++.h> using namespace std; clock_t time_p = clock(); void rtime() { time_p = clock() - time_p; cout << "\nTime Taken : " << fixed << (float)(time_p) / CLOCKS_PER_SEC << "s\n"; } inline long long gcd(long long a, long long b) { if (b == 0) return a; return gcd(b, a % b); } inline long l...