func_code_string
stringlengths
59
71.4k
#include <bits/stdc++.h> using namespace std; unsigned int max_ID(long long int a[], long long int b[], unsigned int n) { unsigned int max_ID; unsigned long long int max; max_ID = 0; max = pow(a[0] - b[0], 2); for (unsigned int i = 1; i < n; i++) { if (pow(a[i] - b[i], 2) > max) { ...
#include <bits/stdc++.h> using namespace std; using namespace chrono; template <class T> void Swap(T& a, T& b) { a ^= b; b ^= a; a ^= b; } template <class type> void show(type name) { for (auto& nm : name) cerr << nm << ; cerr << n ; } using lng = long long; using ivec = vec...
#include <bits/stdc++.h> using namespace std; int main() { cin.tie(0); ios_base::sync_with_stdio(0); string s; cin >> s; int c[2]; c[0] = c[1] = 0; const int m[] = {2, 1}; for (int i = 0; i < s.size(); i++) { int d = s[i] - 0 ; cout << ((c[d]++ * m[d]) % 4) + 1 << <<...
#include <bits/stdc++.h> using namespace std; template <typename T> void __p(T a) { cout << a; } template <typename T, typename F> void __p(pair<T, F> a) { cout << { ; __p(a.first); cout << , ; __p(a.second); cout << } n ; } template <typename T> void __p(std::vector<T> a) {...
#include <bits/stdc++.h> using namespace std; int main() { int n; while (cin >> n) { vector<string> v(n); string s; for (int i = 0; i < n; ++i) { cin >> v[i]; for (int j = 0; j < v[i].size(); ++j) { if (v[i][j] >= A && v[i][j] <= Z ) v[i][j] = v[i][j] - A + ...
#include <bits/stdc++.h> struct heap { int heapsize; int arr[100009]; }; void max_heapify(struct heap *c, int i, int *array) { if (c->heapsize == 0) return; int smallest, tmp; if (((2 * i) <= c->heapsize) && (array[c->arr[2 * i]] > array[c->arr[i]])) smallest = 2 * i; else smal...
#include <bits/stdc++.h> using namespace std; const int N = 1e3 + 10; const long long mod = 1e9 + 7; const long long inf = 1e18 + 10; long long n, L, k; string s, ans[N]; int ptr; void doIt(int l, int r) { if (l + 1 == r) { while (ans[l].size() < L) ans[l] += s[ptr], ptr++; return; }...
#include <bits/stdc++.h> using namespace std; int l[100100]; int d[100100]; map<int, vector<int> > p; int cntd[202] = {0}; int main(int argc, char** argv) { ios::sync_with_stdio(0); cin.tie(0); int n; cin >> n; for (int i = 0; i < n; i++) cin >> l[i]; for (int i = 0; i < n; i++) cin ...
#include <bits/stdc++.h> #pragma GCC optimize( Ofast ) using namespace std; const long long infl = 2e18; const long long infi = 1e9; const long long mod = 1000000007; auto clk = clock(); mt19937_64 rang( chrono::high_resolution_clock::now().time_since_epoch().count()); long long rng(long long lim)...
#include <bits/stdc++.h> using namespace std; const long long int mod = 1e9 + 7; void solve() { long long int a, s; cin >> a >> s; vector<long long int> b; while (s) { long long int x = a % 10; long long int y = s % 10; if (y >= x) { b.push_back(y - x); } else { ...
#include <bits/stdc++.h> using namespace std; int main() { int T; cin >> T; while (T--) { int n, p; scanf( %d%d , &n, &p); for (int i = 0; i < n; i++) printf( %d %d n , i + 1, (i + 1) % n + 1); for (int i = 0; i < n; i++) printf( %d %d n , i + 1, (i + 2) % n + 1); int k = 3...
#include <bits/stdc++.h> using namespace std; int main() { int n, m, p; cin >> n >> m; if (n < m) p = n; else p = m; if (p % 2 == 0) cout << Malvika ; else cout << Akshat ; return 0; }
#include <bits/stdc++.h> const double EPS = 0.0000000001; const long long mod1 = 998244353; const long long mod2 = 1000000007; const long long mod3 = 1000000009; const long long mod4 = 228228227; const long long inf = 100000000000000; using namespace std; signed main() { long long t; cin >> t; ...
#include <bits/stdc++.h> using namespace std; long long mod = 1000000007; class Triplet { public: long long x; long long y; long long gcd; }; long long gcd(long long a, long long b) { if (b == 0) return a; return gcd(b, a % b); } Triplet extendedEuclid(long long a, long long b) { ...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int q; cin >> q; while (q--) { long long pos; cin >> pos; if (pos == 1) { cout << 1 << endl; continue; } long long total = 0; ...
#include <bits/stdc++.h> using namespace std; int n, m, x; long long f[1510], g[1510]; long long sum[1510]; int main() { memset(f, 0, sizeof(f)); scanf( %d%d , &n, &m); for (int i = 0; i < n; ++i) { scanf( %d , &x); sum[0] = x; for (int j = 1; j < m; ++j) { scanf( %d , &x...
#include <bits/stdc++.h> using namespace std; bool yes(int a, int b, bool vis[10]) { long long int temp = a; while (temp > 0) { int r = temp % 10; if (vis[r] == true) { return true; } temp /= 10; } return false; } int main() { ios_base::sync_with_stdio(false);...
#include <bits/stdc++.h> using namespace std; const int N = 14, M = 1 << N; int n, p[M]; char s[N][N]; vector<long long> f[M][N]; int main() { scanf( %d , &n); for (int i = 0; i < n; ++i) scanf( %s , s[i]); for (int i = 1; i < 1 << n; ++i) { p[i] = p[i >> 1] + (i & 1); for (int j = 0...
#include <bits/stdc++.h> using namespace std; queue<int> que; int n, k; int main() { while (cin >> n >> k) { if (k == 0) { cout << 1; for (int i = 2; i < 2 * n + 1; i++) cout << << i; cout << endl; continue; } cout << k + 1; for (int i = 1; i < 2 *...
#include <bits/stdc++.h> using namespace std; int arr[100000]; int brr[100000]; int crr[100000]; int main() { int n, l; cin >> n >> l; int flag = 0; for (int i = 0; i < n; i++) cin >> arr[i]; for (int j = 0; j < n; j++) cin >> brr[j]; for (int i = 0; i < n; i++) { crr[arr[i]] = 1...
#include <bits/stdc++.h> using namespace std; const int N = 5000 * 100 + 5; int n, m, a, b, c, av, bv, cv, t, h[N], cnt, par[N], y, ans[N], cntA, col, ca[N], o, uwu; vector<int> adj[N], pa; bool mark[N], vis[N], flag2, g[N]; void bfs(int v) { queue<int> q; par[v] = -1; q.push(v); flag2...
#include <bits/stdc++.h> using namespace std; int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); } int lcm(int a, int b) { return a * (b / gcd(a, b)); } int cx[] = {-1, 1, 0, 0, 1, 1, -1, -1}; int cy[] = {0, 0, -1, 1, -1, 1, -1, 1}; bool is_possible(long long left, long long rigth) { if (left <=...
#include <bits/stdc++.h> #pragma GCC optimize( O3 ) const long long INF = 0x3f3f3f3f3f3f3f3f; const long long llinf = LLONG_MAX; const int inf = INT_MAX; const int nmax = 1e6 + 5; const int mod = 1e9 + 7; using namespace std; int i, ans, x; string s; int main() { ios_base::sync_with_stdio(false)...
#include <bits/stdc++.h> using namespace std; int n, a[100100]; bool c; int main() { cin >> n; if (n == 1 || n == 2) { cout << 0; return 0; } for (int i = 1; i <= n; i++) cin >> a[i]; vector<int> cch; vector<int> chh; vector<int> aas; aas.push_back(a[1]); aas.push...
#include <bits/stdc++.h> using namespace std; int n, lst[3], mx[2]; long long ans, pos[300005]; char color; inline char get() { char in = getchar(); while (in != R && in != G && in != B ) { in = getchar(); } return in; } inline void did(int opt, int nowpos) { if (lst[opt] !=...
#include <bits/stdc++.h> using namespace std; int n; string s[6], S; bool F; int main() { cin >> S; for (int i = 1; i <= 5; ++i) cin >> s[i]; for (int i = 1; i <= 5; ++i) if (s[i][0] == S[0] || s[i][1] == S[1]) F = 1; puts(F ? YES : NO ); return 0; }
#include <bits/stdc++.h> using namespace std; const int MX_A = 1e7; const int N = 500000; bool sieve[MX_A + 1]; pair<int, int> pr[MX_A + 1]; int a1[N], a2[N], arr[N]; void handleven(int i) { int num = arr[i]; while (num % 2 == 0) num /= 2; if (num != 1) { a1[i] = 2; a2[i] = num; ...
#include <bits/stdc++.h> using namespace std; const int OO = 2e9; const int MOD = 1e9 + 7; const double Pi = 3.141592653589793; const int N = 3e5 + 5; long long c[N], v[N], g[N], a[N], n, k, s, t, m = 0, mx = 0, mn = -1, res = OO; bool check(long long cap) { long long time = 0; for (int i = (int)1...
#include <bits/stdc++.h> using namespace std; template <typename T> bool chkmax(T &x, T y) { return x < y ? x = y, true : false; } template <typename T> bool chkmin(T &x, T y) { return x > y ? x = y, true : false; } int readint() { int x = 0, f = 1; char ch = getchar(); while (ch < ...
#include <bits/stdc++.h> using namespace std; const long long INF = INT_MAX; void solve() { long long n; cin >> n; vector<long long> a(n); vector<long long> first(n, INF); vector<long long> last(n, -INF); for (long long i = 0; i < n; ++i) { cin >> a[i]; --a[i]; first[a[i]...
#include <bits/stdc++.h> using namespace std; const long long MOD = 1e9 + 7; const long long INF = 1e15; class LazySegmentTree { private: int n; vector<pair<long long, int>> node; vector<long long> lazy; public: LazySegmentTree(vector<long long> v) { n = 1; while (n < v.size...
#include <bits/stdc++.h> using namespace std; const int N = 100010; int inf = 1e9; int mod = 1e9 + 7; signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, m, k; cin >> n >> m >> k; int L[n], R[n]; for (int i = 0; i < n; i++) cin >> L[i] >> R[i]; map<int...
#include <bits/stdc++.h> using namespace std; int n, m, len; char p[1000]; int done[1000]; long long ans = 0; long long p2[1000]; int main() { int i, j; scanf( %s , p); p2[0] = 1; for (i = 1; i <= 200; ++i) p2[i] = (p2[i - 1] * 2) % 1000000007; len = strlen(p); for (i = 0; i < len;...
#include <bits/stdc++.h> using namespace std; bool sortbysec(const pair<int, bool> &a, const pair<int, bool> &b) { return (a.first < b.first || (a.first == b.first && a.second < b.second)); } int main() { ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); int n; cin >> n; int res = n; vec...
#include <bits/stdc++.h> using namespace std; priority_queue<int> lott; int main() { long long int xm, find = 0; cin >> xm; lott.push(100); lott.push(20); lott.push(10); lott.push(5); lott.push(1); while (xm) { while (lott.top() <= xm) { find++; xm -= lott.top...
#include <bits/stdc++.h> using namespace std; long long m[4], x, y, a; signed main() { ios::sync_with_stdio(false); cin.tie(NULL), cout.tie(NULL); for (long long i = 0; i < 10; ++i) { cout << i << i << i << i << endl; cin >> x >> y; if (x == 1) m[a++] = i; } for (long long i ...
#include <bits/stdc++.h> using namespace std; char str[200010]; int tim[200010]; int main() { memset(tim, 0x3f, sizeof(tim)); int n, k; scanf( %d %d , &n, &k); scanf( %s , str); for (int i = 0; i < n; i++) if (str[i] == str[(i + 1) % n] || str[i] == str[(i - 1 + n) % n]) tim[i]...
#include <bits/stdc++.h> using namespace std; string s1, s2, virus; pair<int, int> dp[105][105][105]; int l1, l2, lvirus; string ans = ; int pi[105]; void pf(string s) { memset(pi, 0, sizeof(pi)); int n = (int)s.length(); for (int i = 1; i < n; ++i) { int j = pi[i - 1]; while (j ...
#include <bits/stdc++.h> using namespace std; int main() { int n, k, i; cin >> n >> k; if (k == 1 || k == n) { cout << 3 * n << endl; return 0; } else { int sum = 0; if (k & 1) { if (k >= n / 2 + 1) { k = n - k + 1; } } else { if (k > n...
#include <bits/stdc++.h> using namespace std; struct Edge { int u, v; }; const int MAXN = 2e5 + 5; int p[MAXN]; vector<Edge> edges; vector<int> G[MAXN]; bool va[MAXN], vb[MAXN]; int find(int x) { return x == p[x] ? x : p[x] = find(p[x]); } int main() { memset(va, 0, sizeof(va)); memset(v...
#include <bits/stdc++.h> using namespace std; int dept[105], lend[105]; int main() { int n, m, a, b, c, sum = 0; scanf( %d%d , &n, &m); for (int i = 0; i < m; ++i) { scanf( %d%d%d , &a, &b, &c); lend[b] += c; dept[a] += c; } for (int i = 1; i <= n; ++i) { if (lend[i] < ...
#include <bits/stdc++.h> using namespace std; int n; int vis[601], co[601], fa[601], d[601]; int zb(int o, int l, int r) { int ans1 = 0, ans2 = 0; int sz = 0; for (int i = l; i <= r; i++) if (!vis[i]) sz++; if (sz > 0) { printf( ? %d n , sz + 1); for (int i = l; i <= r; i++) ...
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 10; char ch[N]; int a[N]; int main() { int n; cin >> n; stack<int> st; for (int i = 1; i <= n * 2; i++) { scanf( %c , ch + i); if (ch[i] == + ) { st.push(i); } else { if (st.empty()) { ...
#include <bits/stdc++.h> int main() { int i, n, k; int v[210]; scanf( %d %d , &n, &k); for (i = 0; i <= 2 * n; i++) scanf( %d , v + i); for (i = 1; k > 0 && i < 2 * n + 1; i += 2) { if (v[i] - 1 > v[i - 1] && v[i] - 1 > v[i + 1]) { k--; v[i]--; } } for (i = 0; i...
#include <bits/stdc++.h> using namespace std; const double esp = 0.00000001; const int N = 60; const int PSize = 100; const double PCross = 0.3; const double PMuta = 0.05; int a[200010], t[200010]; int n, T; vector<int> res; bool cmp(pair<int, int> a, pair<int, int> b) { return a.second < b.second; ...
#include <bits/stdc++.h> using namespace std; void err(istream_iterator<string> it) {} template <typename T, typename... Args> void err(istream_iterator<string> it, T a, Args... args) { cout << *it << = << a << n ; err(++it, args...); } const int MOD = 1e9 + 7, N = 2e5 + 5, B = 32; vector<in...
#include <bits/stdc++.h> using namespace std; const int inf = 1e9 + 7; const int N = 1e6 + 5; int main() { int n; cin >> n; for (int i = 0; i <= 2 * n; i++) { for (int j = 0; j < 2 * abs(n - i); j++) cout << ; int cnt = 0; for (int j = 0; j <= 2 * n - 2 * abs(n - i); j++) { ...
#include <bits/stdc++.h> using namespace std; struct station { int p, x, dir; station() {} station(int pp, int xx, int dirr) { p = pp; x = xx; dir = dirr; } }; bool cmp(station a, station b) { if (a.x != b.x) return a.x < b.x; return a.dir == 1; } int d, n, m; int...
#include <bits/stdc++.h> using namespace std; const int maxm = 20010, maxn = 10010, maxk = 1110; const int inf = 1e7; int to1[maxm], begin1[maxn], next1[maxm], w[maxm][maxk], cur[maxn], e = 1, W[maxm]; int d[maxn], q[maxn], g[maxk], ans[max...
#include <bits/stdc++.h> using namespace std; template <typename Arg1> void __f(const char* name, Arg1&& arg1) { cerr << << name << : << arg1 << n ; } template <typename Arg1, typename... Args> void __f(const char* names, Arg1&& arg1, Args&&... args) { const char* comma = strchr(names + 1,...
#include <bits/stdc++.h> const int N = 29; const int K = 10; const int MOD = 1e9 + 7; int n, m, k; int g[N][N]; int s[N][N][K]; int state[N][N]; int f[N]; bool ch[N]; int fac[N]; int inv[N]; int ans; inline void init() { scanf( %d%d%d , &n, &m, &k); if (n + m - 1 > k) { puts( 0 )...
#include <bits/stdc++.h> using namespace std; int a[1000006], g[1000006]; char str[1000006]; int sum1 = 0, sum2 = 0; int main() { int n, i; scanf( %d , &n); for (i = 0; i < n; i++) { scanf( %d %d , &a[i], &g[i]); } for (i = 0; i < n; i++) { int c = sum2 - (sum1 + a[i]); ...
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 5; map<int, int> f, val; int lastans; int read() { int x = 0, f = 1; char s; while ((s = getchar()) > 9 || s < 0 ) if (s == - ) f = -1; while (s >= 0 && s <= 9 ) x = (x << 1) + (x << 3) + (s ^ 48), s = getchar...
#include <bits/stdc++.h> using namespace std; int main() { int i, j, m, k, t, cs, n, mx, v; scanf( %d , &n), scanf( %d , &m); int cnt = 0, ppl = 0; for (i = 1; i <= n; i++) { scanf( %d , &v); if (ppl + v <= m) ppl += v; else { cnt++; ppl = v; } } ...
#include <bits/stdc++.h> using namespace std; int n, m, k, a[1000005], b[1000005]; int mi[1 << 20], mx[1 << 20], p[30], cs1[30], cs2[30], dp1[1 << 20], dp2[1 << 20], cs = 0; int main() { scanf( %d%d%d , &n, &m, &k); for (int i = 1; i <= k; ++i) scanf( %1d , &cs1[i]); for (int i = 1; i <= k; ++...
#include <bits/stdc++.h> using namespace std; template <class T> ostream &operator<<(ostream &os, const vector<T> &p) { os << [ ; for (auto &it : p) os << it << ; return os << ] ; } template <class S, class T> ostream &operator<<(ostream &os, const pair<S, T> &p) { return os << ( << p...
//#pragma GCC optimize( Ofast ) //#pragma GCC target( avx,avx2,fma ) #include <bits/stdc++.h> using namespace std; void __print(int x) {cerr << x;} void __print(long x) {cerr << x;} void __print(long long x) {cerr << x;} void __print(unsigned x) {cerr << x;} void __print(unsigned long x) {cerr << x;}...
#include <bits/stdc++.h> using namespace std; vector<int> a = vector<int>(10, 0); vector<int> b; int main() { srand(time(NULL)); for (int i = 0; i < 6; i++) { int x; cin >> x; a[x]++; } bool f = false; for (int i = 0; i < 10; i++) { if (a[i] != 0) { b.push_bac...
#include <bits/stdc++.h> struct DSU { private: int32_t* parents; int32_t* sizes; std::vector<std::pair<int32_t, int32_t> > actions; int32_t get_root(int32_t v) { if (parents[v] == v) return v; return get_root(parents[v]); } public: DSU(int32_t n) { parents = new int3...
#include <bits/stdc++.h> std::mt19937 rnd(time(0)); const int N = 200005; int n, m, a[N], c[N]; int v; int ans; int p[N << 1]; void updAns(int x) { if (v == x) { return; } for (int i = 0; i <= 2 * n; ++i) { p[i] = -1; } int now = n; p[now] = 0; for (int i = 1; i <= ...
#include <bits/stdc++.h> int main(void) { int x1, y1, x2, y2, temp; int n; int x[1001], y[1001], r[1001]; int i, j; int people, blanket = 0; scanf( %d%d%d%d%d , &x1, &y1, &x2, &y2, &n); for (i = 0; i < n; i++) { scanf( %d%d%d , &x[i], &y[i], &r[i]); r[i] = r[i] * r[i]; } ...
#include <bits/stdc++.h> using namespace std; const int inf = 1e8 + 10; bool ok = 0; int n, maxy, miny, maxx, minx; struct point { int x, y; }; bool cmp(point a, point b) { return a.x < b.x; } point jilu[100050]; int bfy[100050], afy[100050], bfmaxy[100050], bfminy[100050], afminy[100050], a...
#include <bits/stdc++.h> using namespace std; pair<int, int> a[300005]; int n, x, y; void resi(int x, int y, bool naopako) { int z = 0, j = -1, k = -1, c = 0; for (int i = 1; i <= n; i++) { z = a[i].first; c++; if (j == -1 && z * c >= x) { j = i; z = c = 0; } ...
#include <bits/stdc++.h> using namespace std; int N, M; const double EPS = 1E-9; double solve(int r, int c) { vector<double> res(M, 0); for (int y = N - 2; y >= r; y--) { if (M == 1) { res[0] = 2 + res[0]; } else { vector<double> a(M), b(M); a[0] = 1 / 2.0; b[...
#include <bits/stdc++.h> using namespace std; int n, k, s; int dp[2][155][155 * 155 / 4]; int num[155]; int main() { while (~scanf( %d%d%d , &n, &k, &s)) { for (int i = 1; i <= n; i++) { scanf( %d , &num[i]); } int all = (n - k) * k; if (s >= all) { sort(num + 1, nu...
#include <bits/stdc++.h> using namespace std; const int maxn = 100010; int n, a[maxn], deep[maxn], head[maxn], to[maxn * 2], nextt[maxn * 2], tot = 1, ans[maxn], anss; void add(int x, int y) { to[tot] = y; nextt[tot] = head[x]; head[x] = tot++; } void dfs(int u, int fa) { deep[u] = dee...
#include <bits/stdc++.h> using namespace std; int main() { long long int n, k, m, p, t = 0; cin >> n >> m >> k; vector<long long int> v; for (long long int i = 0; i < m; i++) { cin >> p; v.push_back(p); } sort(v.begin(), v.end()); long long int c = 0, s = 0; while (s != m...
#include <bits/stdc++.h> clock_t t = clock(); namespace my_std { using namespace std; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); template <typename T> inline T rnd(T l, T r) { return uniform_int_distribution<T>(l, r)(rng); } template <typename T> inline bool chkmax(T& x, ...
#include <bits/stdc++.h> int s[401000], lazy[401000]; int b[401000], N; int n, s1, s2; int v[401000]; int Abs(int x) { return x > 0 ? x : -x; } void add(int x) { s[x] = 0; lazy[x] = 1; } void pd(int x) { if (lazy[x]) add(x << 1), add(x << 1 | 1), lazy[x] = 0; } void pu(int x) { s[x] = s[...
#include <bits/stdc++.h> using namespace std; int main() { long long t; t = 1; while (t--) { long long n, m; cin >> n; cin >> m; string s[n]; for (long long i = 0; i < n; i++) { string cur = ; for (long long i = 0; i < m; i++) { long long k; ...
#include <bits/stdc++.h> using namespace std; int main() { long long n; cin >> n; queue<long long> qR, qD; string second; cin >> second; for (int i = 0; i < second.length(); i++) { if (second[i] == R ) qR.push(i); else qD.push(i); } while (1) { if (...
#include <bits/stdc++.h> using namespace std; const int Nmax = 1e5 + 5; const long long inf = 1e18; int n, k, nr, st[Nmax], A[Nmax], nextBigger[Nmax]; long long dp[Nmax], old[Nmax]; struct Ec { int a; long long b; long long operator()(int x) { return (long long)a * x + b; } }; Ec interv[Nmax...
#include <bits/stdc++.h> using namespace std; #pragma GCC optimize( Ofast ) #pragma GCC optimize( unroll-loops ) #pragma GCC optimize( -ffloat-store ) #pragma GCC optimize( -fno-defer-pop ) long long int power(long long int a, long long int b, long long int m) { if (b == 0) return 1; if (b == 1) ret...
#include <bits/stdc++.h> int main() { int n, i, a = 0; scanf( %d , &n); for (i = n; i > a; i--) { if (n % i == 0) { printf( %d , i); n = i; } } return 0; }
#include <bits/stdc++.h> using namespace std; char ini[101], des[101]; int main() { int i, L = strlen(ini), j; gets(ini); gets(des); for (i = 0; ini[i]; i++) { for (j = i + 1; ini[j]; j++) { if (ini[i] > ini[j]) { swap(ini[i], ini[j]); } } } for (i = 0...
#include <bits/stdc++.h> using namespace std; int N, M; long double DP[1010][1010]; int i, j; int total, X; int main() { cin >> N >> M; DP[0][0] = 1.0; for (int i = 1; i <= N; i++) for (int j = 0; j <= M && j <= N; j++) { total = N * M - (i - 1); X = M - j; DP[i][j]...
#include <bits/stdc++.h> using namespace std; long long n, m, c, p, y, k, x, h, t, q; string s; vector<long long> v; map<long long, long long> ma; void input() {} struct node { map<string, node*> child; map<string, long long> ispresent; string name; bool isfile = 0; }; pair<long long, ...
#include <bits/stdc++.h> #pragma GCC optimize( Ofast ) using namespace std; long long a[100005], b[100005], l[100005], l2[100005]; signed main() { ios::sync_with_stdio(0); cin.tie(0); long long n; cin >> n; for (long long i = 1; i <= n; i++) cin >> a[i]; for (long long i = 1; i <= n; i++...
#include <bits/stdc++.h> using namespace std; signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(0); ; string s; long long m, x = 0, k = 0; long long a[3]; for (long long i = 0; i < 3; i++) { cin >> a[i]; } sort(a, a + 3); k = a[2] - a[1] + a[...
#include <bits/stdc++.h> using namespace std; template <typename T, typename U> inline void smin(T &a, U b) { if (a > b) a = b; } template <typename T, typename U> inline void smax(T &a, U b) { if (a < b) a = b; } template <typename T> inline void gn(T &first) { char c, sg = 0; while (...
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; const long long inf = 2e18 + 5; vector<long long> adj[1000001]; signed main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); long long r, c; cin >> r >> c; vector<string> a(r); for (long long...
#include <bits/stdc++.h> using namespace std; int v[200100], cnt[200020]; int n, s; int main(void) { ios::sync_with_stdio(false); cin >> n >> s; --s; int er = 0; int ans = 0; for (int(i) = (0); (i) < (n); ++(i)) { cin >> v[i]; cnt[v[i]]++; } if (v[s] != 0) { ans...
#include <bits/stdc++.h> using namespace std; const int MAXN = 2e3 + 7; const int MOD = 1e9 + 7; const int D = 4e3 + 7; int n, m, A[MAXN], cnt, L, R; vector<int> G[MAXN]; void add(int &x, int y) { x += y; if (x >= MOD) x -= MOD; } bool vis[MAXN]; int dfs(int u) { vis[u] = true; for (...
#include <bits/stdc++.h> using namespace std; char s[100010]; int n; int main() { scanf( %d , &n); scanf( %s , s + 1); sort(s + 1, s + n + 1); printf( %s n , s + 1); }
#include <bits/stdc++.h> int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); } int lcm(int a, int b) { return ((a * b) / gcd(a, b)); } using namespace std; long long ara[1000006]; int main() { int b, c, i, j, k, tc, t; int m, cnt = 0; long long one = 1, two = 2, a, n; cin >> n >> m; ...
#include <bits/stdc++.h> using namespace std; int n, A[200010], L[200010], R[200010], ans = 1; int main() { scanf( %d , &n); for (int i = 1; i <= n; i++) { scanf( %d , &A[i]); L[i] = R[i] = 1; } for (int i = 2; i <= n; i++) { if (A[i - 1] < A[i]) L[i] = L[i - 1] + 1; ans = ...
#include <bits/stdc++.h> using namespace std; pair<int, int> pts[1001]; int n; int main() { cin >> n; for (int i = 0; i <= n; i++) { scanf( %d%d , &pts[i].first, &pts[i].second); } int ans = 0; char last = U ; for (int i = 1; i < n; i++) { char cur; if (pts[i].first ==...
#include <bits/stdc++.h> using namespace std; template <typename T> T sqr(T x) { return x * x; } template <typename T> T abs(T x) { return x < 0 ? -x : x; } template <typename T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; } int f[1 << 20]; int g[1 << 20]; void upd_min(int &x, ...
#include <bits/stdc++.h> using namespace std; const int MAXN = 3000 + 10; int A[MAXN]; int B[MAXN]; long long dp[MAXN][MAXN]; int main() { int n; scanf( %d , &n); for (int i = 0; i < n; i++) { scanf( %d , &A[i]); A[i] -= i; } memcpy(B, A, n * sizeof(int)); sort(B, B + n);...
#include <bits/stdc++.h> using namespace std; const int maxn = 1000001; vector<int> g[maxn]; int st[maxn], top, num; int col[maxn]; void dfs(int s) { col[s] = 1; num++; for (int i = 0; i < (int)g[s].size(); i++) { if (!col[g[s][i]]) { dfs(g[s][i]); } } } int main() { ...
#include <bits/stdc++.h> using namespace std; char s1[101]; int cnt[1000]; int main() { scanf( %s , s1); int lower = 0; int upper = 0; for (int i = 0; i < strlen(s1); i++) { if (s1[i] == tolower(s1[i])) lower++; else upper++; } if (upper > lower) { for (...
#include <bits/stdc++.h> using namespace std; const int N = 300005; int n, m; int win[N]; bool seg[4 * N]; void update(int node, int start, int end, int l, int r, int w) { if (seg[node]) return; if (start == end) { if (w == start) return; seg[node] = 1; win[start] = w; } else {...
#include <bits/stdc++.h> using namespace std; int n, j; int main() { cin >> n; j = n * n; for (int i = 1; i <= n * n; i++) { cout << i << << j << ; if (i == j - 1) break; j--; } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n, i, a, b, s = 0; char s1[10001], s2[10001]; cin >> n; cin.ignore(10000, n ); cin.get(s1, 10001, n ); cin.ignore(10000, n ); cin.get(s2, 10001, n ); cin.ignore(10000, n ); for (i = 0; i < n; ++i) { if...
#include <bits/stdc++.h> using namespace std; int n, m; int i, j, k, l; struct point { long long x, y; point(long long X = 0, long long Y = 0) { x = X; y = Y; } double dist(point &p) { return sqrt(0. + ((p.x - x) * (p.x - x)) + ((p.y - y) * (p.y - y))); } }; bool operat...
#include <bits/stdc++.h> using namespace std; bool found(vector<string> v, string perm) { for (int i = 0; i < v.size(); i++) if (v[i] == perm) return true; return false; } int main() { string word, perm; bool newWord; int n, ans, freq[27]; vector<string> v; ans = 0; scanf( ...
#include <bits/stdc++.h> using namespace std; const int MAX = 1e6 + 100, MOD = 1e9 + 7; int dp[MAX], n, tmp, cnt; int cal(int n) { if (n == 0 || n == 1) return 1; if (dp[n] != -1) return dp[n]; return dp[n] = (cal(n - 1) + 1LL * cal(n - 2) * (n - 1)) % MOD; } int main() { memset(dp, -1, size...
#include <bits/stdc++.h> using namespace std; template <class T> void print_array(T a[], int size) { for (int i = 0; i < size; i++) cout << a[i] << ; cout << endl; } template <class T> void print_array_v(T &a) { int size = a.size(); for (int i = 0; i < size; i++) cout << a[i] << ; ...
#include <bits/stdc++.h> const int MAXN = 3e5 + 5; const int INF = 0x3f3f3f3f; const int MOD = 1e9 + 7; using namespace std; struct node { int v, p; bool operator<(const node& n) const { return v > n.v; } } a[MAXN]; int n, k, ans[MAXN]; bool vis[MAXN << 2]; int main() { scanf( %d %d , &n, ...
#include <bits/stdc++.h> using namespace std; const int inf = (int)1e9 + 7; const long long INF = (long long)1e18 + 7; const int N = 200007; bool c; int chkp(string x) { int ans = 0; if ((int)x.size() % 2) c = 1; for (int i = 0, j = (int)x.size() - 1; i < j; i++, j--) { if (x[i] == x[j]) c...