func_code_string
stringlengths
59
71.4k
#include <bits/stdc++.h> using namespace std; mt19937 rnd(228); const int N = 404; int mod; int fact[N], d0[N], d[N], d2[N][N]; int main() { int qq; cin >> qq >> mod; fact[0] = 1; for (int i = 1; i < N; ++i) fact[i] = (1LL * fact[i - 1] * i) % mod; d[1] = 1; d0[1] = 1; for (int n...
#include <bits/stdc++.h> using namespace std; const int N = 2020; vector<tuple<int, int, int> > edges; vector<int> g[N]; vector<int> back_edge[N]; bool global; int num[N], low[N], low2[N], cnt, pai[N], pw[N], aux[N], prev_pai[N], prev_pw[N], sobe[N], prev_sobe[N]; int edg_used, edg_u, edg_v, edg_w...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int i, j, k; j = (n * 2) - 1; cout << j << << 2 ; cout << endl << 1 2 ; }
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5; vector<pair<int, int> > adj[N]; int ans[N]; int off[N]; int lvl[N], anc[N][25]; int n, a, b, k; void dfs(int u = 0, int par = 0, int l = 0) { lvl[u] = l; anc[u][0] = par; for (auto nxt : adj[u]) if (nxt.first != par) ...
#include <bits/stdc++.h> #pragma GCC optimize( Ofast ) using namespace std; struct Point { int x, y, type, index; } num[20005]; int ans[10005]; Point c; bool cmp(Point a, Point b) { return (a.x - c.x) * (b.y - c.y) - (a.y - c.y) * (b.x - c.x) > 0; } bool cmp2(Point a, Point b) { return (a.x < ...
#include <bits/stdc++.h> using namespace std; const int mn = 201000, inf = 1 << 30; struct node { int x, y; } pt[mn], sub[mn]; struct point { int k, x, y, r; } e[mn * 2]; int s1[mn * 2], s2[mn * 2]; int xs[mn * 2], dis[mn], sa[mn], L; int n, m, i, j, step, lo, hi, mid; bool cmp(node a, node ...
#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; } inline void gn(long long &first) { int sg = 1; char c; while (((c = ge...
#include <bits/stdc++.h> using namespace std; const int maxn = 35005; struct Node { int l, r; int lazy; int Max; } node[maxn << 2]; int n, k; int a[maxn]; int pre[maxn]; int dp[maxn]; void push_down(int root) { node[root << 1].lazy += node[root].lazy; node[root << 1 | 1].lazy += no...
#include <bits/stdc++.h> using namespace std; void small(long long m, long long s) { vector<long long> v; long long p = (s % 9 == 0) ? s / 9 - 1 : s / 9; for (long long i = 0; i < p; i++) { v.push_back(9); s -= 9; } if (m - p == 1) { v.push_back(s); } if (m - p >= 2) { ...
#include <bits/stdc++.h> using namespace std; long long int mod = 1e9 + 7; long long int inf = 1e9 + 7; void solve() { long long int n; cin >> n; if (n <= 2) { cout << -1 << endl; } else { long long int i; for (i = n; i >= 1; i--) { cout << i << ; } cou...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; string s, t; cin >> s >> t; int cost = 0; for (int i = 0; i < n;) { if (s[i] != t[i]) { if (i + 1 < n && s[i] != s[i + 1] && s[i + 1] != t[i + 1]) { i += 2; } else { i++; ...
#include <bits/stdc++.h> using namespace std; inline long long read() { long long x = 0, f = 1; char ch = getchar(); while (ch < 0 || ch > 9 ) { if (ch == - ) f = -1; ch = getchar(); } while (ch >= 0 && ch <= 9 ) { x = x * 10 + (ch ^ 48); ch = getchar(); } ...
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { string s; string t; cin >> s >> t; int ans = 1; int last = INT_MIN; vector<int> v[26]; int dp[2][26]; for (int i = 0; i < s.length(); i++) { v[s[i] - a ].pus...
#include <bits/stdc++.h> using namespace std; string s; stack<long long> num; stack<char> fuhao; vector<int> pos; void calc() { char cc = fuhao.top(); fuhao.pop(); long long a = num.top(); num.pop(); long long b = num.top(); num.pop(); long long ans; if (cc == * ) ans ...
#include <bits/stdc++.h> using namespace std; int dx[4] = {1, 0, -1, 0}; int dy[4] = {0, 1, 0, -1}; long long n, m, k; long long arr[300001]; long long arr2[300001]; int main() { std::ios_base::sync_with_stdio(false); cin.tie(NULL); int t; cin >> t; cin.ignore(); for (int test_case...
#include <bits/stdc++.h> using namespace std; const int mod = int(1e6 + 3); vector<vector<int> > v; char second[600000]; int n, m; int main() { scanf( %d%d n , &n, &m); v.resize(n); for (int i = 0; i < n; ++i) { gets(second); v[i].resize(m); for (int j = 0; j < m; ++j) { ...
#include <bits/stdc++.h> const int maxn = 1e5 + 5; using namespace std; int a[maxn]; int vis[maxn]; int step[maxn * 2]; int main() { int n; scanf( %d , &n); for (int i = 0; i < n; i++) { scanf( %d , &a[i]); int temp = a[i]; int step1 = 0, step2 = 0, step3 = 0; while (temp...
#include <bits/stdc++.h> using namespace std; template <typename Arg1> void __f(const char* name, Arg1&& arg1) { cerr << name << : << arg1 << std::endl; } template <typename Arg1, typename... Args> void __f(const char* names, Arg1&& arg1, Args&&... args) { const char* comma = strchr(names + 1, ...
#include <bits/stdc++.h> using namespace std; const double PI = 3.14159265358979323846264338327950288419716939937510582097494459230; void swaps(char *x, char *y) { char temp; temp = *x; *x = *y; *y = temp; } void swapi(int *a, int *b) { int temp; temp = *a; *a = *b; *b = ...
#include <bits/stdc++.h> long long int binpow(long long int a, long long int b) { if (b == 0) return 1; long long int res = binpow(a, b / 2); if (b % 2) return res * res * a; else return res * res; } using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(...
#include <bits/stdc++.h> using namespace std; const long long LLINF = 1e18; const int INF = 1e9; const int MOD = 20101009; const int HMOD = 999959; const int VMOD = 5000000; const int MAXN = 1e5 + 10; const int MAXM = 5e5 + 10; const int INV = 10050505; const long long LLINV = 1e18; const double e...
#include <bits/stdc++.h> using namespace std; int main() { int h, m; char c; cin >> h >> c >> m; while (1 > 0) { m++; h += (m / 60); m %= 60; h %= 24; if (h / 10 == m % 10 && h % 10 == m / 10) break; } cout << h / 10 << h % 10 << : << m / 10 << m % 10; ret...
#include <bits/stdc++.h> using namespace std; int n, m, q; int tt; int ss = n + m; int fa[400005]; bool vis[500005]; int ans; int find(int x) { if (fa[x] == x) return x; return fa[x] = find(fa[x]); } int main() { scanf( %d%d%d , &n, &m, &q); for (int i = 1; i <= n + m; i++) { f...
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; long long ans = 0; for (int i = (0); i < (n); ++i) { long long t, T, x, cost; cin >> t >> T >> x >> cost; if (t >= T) { ans += cost + m * x; continue; } long long aux1 = ...
#include <bits/stdc++.h> using namespace std; long long modulo(long long base, long long exponent, long long modulus); long long choose(long long n, long long k); long long inverse(long long a, long long m); void build(); void fileio(); long long ncr(long long n, long long r); const int nax = 1e6 + 10; ...
#include <bits/stdc++.h> using namespace std; void fastio() { cin.tie(nullptr); cin.sync_with_stdio(false); } using LL = long long; using LD = long double; const LL MOD = 1e9 + 7; const LL INF = LLONG_MAX; const LL N = 2e5 + 1; int main() { fastio(); LL n; cin >> n; vector<LL> ...
#include <bits/stdc++.h> using namespace std; int main() { int q, n, sum, a; cin >> q; while (q--) { sum = 0; cin >> n; for (int i = 0; i < n; i++) { cin >> a; sum += a; } cout << (sum + n - 1) / n << endl; } }
#include <bits/stdc++.h> using namespace std; const int N = 5000 + 20; const int maxn = 1e5 + 20; const int mod = 998244353; int cnt, head[maxn], pos[maxn]; long long ksm(long long a, long long b) { long long res = 1; while (b) { if (b & 1) res = (res * a) % mod; b >>= 1, a = a * a % mod...
#include <bits/stdc++.h> using namespace std; int query(int x, int y) { if (x == -1) return 0; cout << 1 << << x << << y << endl; string ret; cin >> ret; return ( TAK == ret); } int get(int l, int r) { if (l > r) return -1; while (l < r) { int m = (l + r) >> 1; i...
#include <bits/stdc++.h> using namespace std; int n, k, d, done[300005] = {0}; vector<int> graph[300005]; map<pair<int, int>, int> edge; set<int> p; void go() { queue<pair<int, int> > q; for (auto it : p) q.push({it, 0}); while (!q.empty()) { int x = q.front().first, P = q.front().second; ...
#include <bits/stdc++.h> using namespace std; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); const int N = 88; const int M = 100100; int dp[N][M][2]; pair<int, int> a[N]; int n, m; int main() { scanf( %d%d , &n, &m); for (int i = 0; i < n; i++) scanf( %d%d , &a[i].first, &a...
#include <bits/stdc++.h> using namespace std; int n, a[200010]; int main() { scanf( %d , &n); for (int i = 1; i <= n; i++) scanf( %d , &a[i]); sort(a + 1, a + n + 1); int p = 2e9 + 7, ans = 0; for (int i = 1; i < n; i++) p = min(p, a[i + 1] - a[i]); for (int i = 1; i < n; i++) ans += (a[i ...
#include <bits/stdc++.h> const long long mod = 1000000007; const long long Inf = 1e9; using namespace std; bool valid(string s) { for (int i = 0; i < s.length(); ++i) { if (s[i] == || s[i] == # ) { if (s[i] == # ) return true; } else return false; } return false; ...
#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 <class T> inline void gn(T &first) { char c, sg = 0; while (c =...
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; for (int ii = 0; ii < t; ii++) { int n; cin >> n; bool A[52]; char Aa[52][52]; for (int i = 0; i < n; i++) { char t; cin >> t; if (t == 1 ) A[i] = 0; else ...
#include <bits/stdc++.h> using namespace std; long long T; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> T; int a, b, c, d; while (T--) { cin >> a >> b >> c >> d; bool ok = 0; if (a == c) { if (d + b == a) ok = 1; } if ...
#include <bits/stdc++.h> using namespace std; vector<int> adjc[100005]; vector<int> cadj[100005]; struct edge { int u, v, c; }; class dsu { public: dsu(vector<int> vert) : vert(vert) { n = vert.size(); par.resize(n); iota(par.begin(), par.end(), 0); } int root(int u) { ...
#include <bits/stdc++.h> using namespace std; const int maxn = 20 + 5; const long long INF = 3e9; const char *cc = 0123456789abcdef ; int c[maxn][maxn], used[maxn]; long long dp[maxn][maxn]; char s[maxn]; long long solve(int t, int m, bool flag) { memset(dp[0], 0, sizeof(dp[0])); if (flag) { ...
#include <bits/stdc++.h> using namespace std; vector<pair<int, int> > inc[100010]; priority_queue<pair<double, int> > Q; long long A[100010]; int N, M, K; vector<pair<int, int> > mul; int sel[100010]; int typ[100010]; void compute() { int k; while (M-- && !(Q.empty() && mul.empty())) { k...
#include <bits/stdc++.h> using namespace std; char a[102]; char b[102]; char c[102]; int main() { gets(a); gets(b); int l = strlen(a); int i; for (i = l - 1; i >= 0; i--) { if (a[i] == z ) { a[i] = a ; } else { a[i] = a[i] + 1; break; } } ...
#include <bits/stdc++.h> using namespace std; const int N = 500005; int a[N]; int main() { int n; while (scanf( %d , &n) != EOF) { memset(a, 0, sizeof(a)); for (int i = 0; i < n; i++) { scanf( %d , &a[i]); } sort(a, a + n); int mid = (n - 1) / 2; int big = n -...
#include <bits/stdc++.h> using namespace std; int n, sol; multiset<int> S; multiset<int>::iterator p; int main() { scanf( %d , &n); for (int i = 1; i <= n; i++) { int val; scanf( %d , &val); S.insert(val); } long long s = 0; for (int i = 1; i <= n; i++) { p = S.lowe...
#include <bits/stdc++.h> using namespace std; long long bz = -10000000000; long long t[50001], ll[50001], rr[50001], dd[50001]; long long tu[50001]; int main() { long long n, m; cin >> n >> m; for (long long a = 1; a <= n; a++) tu[a] = bz; for (long long a = 1; a <= m; a++) cin >> t[a] >> ll[a...
#include <bits/stdc++.h> #pragma GCC optimize( Ofast ) const int N = 4040; using namespace std; int n, m; int l[N], s[N]; int cost[N]; int inf = -1e9; int d[N][N]; int f[N][N]; vector<int> v[N]; vector<int> pos[N]; vector<int> fut[N][14]; int main() { ios_base::sync_with_stdio(0); cin ...
#include <bits/stdc++.h> using namespace std; long long int XpowerY(long long int x, long long int y, long long int m) { long long int ans = 1; x = x % m; while (y > 0) { if (y % 2 == 1) ans = (ans * x) % m; x = ((x % m) * (x % m)) % m; y = y >> 1; } return ans % m; } vecto...
#include <bits/stdc++.h> using namespace std; const int ALPHA = 26 + 1; struct Trie { Trie() { nodes.resize(2); } struct Node { Node() { memset(next, 0, sizeof(next)); } int next[ALPHA]; int finish = -1; }; int alloc() { nodes.push_back(Node()); return nodes.size() - ...
#include <bits/stdc++.h> using namespace std; long long x, y, m, cnt = 0; int main() { scanf( %lld%lld%lld , &x, &y, &m); if (x >= m || y >= m) { printf( 0 ); return 0; } if (x <= 0 && y <= 0) { printf( -1 ); return 0; } while (x < m && y < m) { if (x > y) swa...
#include <bits/stdc++.h> #pragma comment(linker, /STACK:256000000 ) using namespace std; const int maxN = 2000; const int S_CNT = 9; const int M_CNT = 25; const int DIST = 60 * 60; int n, m; int a[maxN][maxN]; int t[maxN][maxN]; int used[maxN][maxN]; int rc[maxN][maxN]; int is_in(int x, int y) ...
#include <bits/stdc++.h> char Src[1000001], Dst[1000001]; int main() { int i, j, Cnts, Cntd, Lens, Lend; scanf( %s %s , Src, Dst); if (strlen(Src) != strlen(Dst)) { puts( NO ); return 0; } if (strcmp(Src, Dst) == 0) { puts( YES ); return 0; } if (strlen(Src) == 1)...
#include <bits/stdc++.h> using namespace std; template <class T, class L> bool smax(T &x, L y) { return x < y ? (x = y, 1) : 0; } template <class T, class L> bool smin(T &x, L y) { return y < x ? (x = y, 1) : 0; } const int maxn = 5e5 + 17; list<int> a; list<int>::iterator per[maxn]; int n...
#include <bits/stdc++.h> int main() { int t; scanf( %d , &t); while (t--) { int n; scanf( %d , &n); std::vector<int> a(n); for (int i = 0; i < n; i++) { scanf( %d , &a[i]); } int minadd = 0; int cur = a[0]; for (int i = 1; i < n; i++) { if (c...
#include <bits/stdc++.h> using namespace std; struct Ans { long long maxm, maxp, lmr, rml; Ans() { maxm = maxp = lmr = rml = -(1ll << 60); } } node[100010 << 2]; void Union(Ans &o, Ans a, Ans b) { o.maxm = max(a.maxm, b.maxm); o.maxp = max(a.maxp, b.maxp); o.lmr = max(max(a.lmr, b.lmr), a.ma...
#include <bits/stdc++.h> using namespace std; int n, m, tot; long long ans; int main(int argc, char **argv) { scanf( %d%d , &n, &m); ++n; for (int i = m + 1; (i << 1) <= n && i < n - m; ++i) for (int j = m + 1; j < n - m; ++j) { tot = (-i * i * 2 + i * j + i * n * 2 - j * n - 1) / (i +...
#include <bits/stdc++.h> using namespace std; int A, B, C, N; int main() { scanf( %d%d%d%d , &A, &B, &C, &N); if (A < C || B < C || A + B >= N + C) puts( -1 ); else printf( %d n , N - (A + B - C)); }
#include <bits/stdc++.h> using namespace std; template <int mod> struct modulo { int w; operator int() const { return w; } modulo() {} modulo(int w) { this->w = w; fix(); } template <class type> modulo(type w) { this->w = w % mod; fix(); } void inline fi...
#include <bits/stdc++.h> using namespace std; int n, m; vector<int> prices[1010]; int allp[1010]; int all; int margin_price; int above_cnt[1010], margin_cnt[1010], cnt[1010]; double f[1010][1010], g[1010][1010]; double comb[1010][1010]; int main() { comb[1][0] = comb[1][1] = 1; for (int i = ...
#include <bits/stdc++.h> using namespace std; int INF = 1000000005; long long INFF = 1000000000000000005LL; int dirx[8] = {-1, 0, 0, 1, -1, -1, 1, 1}; int diry[8] = {0, 1, -1, 0, -1, 1, -1, 1}; double pi = 3.1415926536; int MOD = 1e9 + 7; long long power(long long x, long long n) { long long res = 1...
#include <bits/stdc++.h> int a[1000000], b[1000000], n, k, f[1000000], c[1000000], i, j; int max(int a, int b) { if (a > b) return a; return b; } int main() { scanf( %d%d , &n, &k); for (i = 1; i <= n; i++) scanf( %d , &a[i]); for (i = 1; i <= n; i++) { scanf( %d , &b[i]); b[i] =...
#include <bits/stdc++.h> using namespace std; void input() { int n; cin >> n; vector<int> v; int i = 1; int k = n - 1; while (k--) { cout << ? << i << << i + 1 << n ; fflush(stdout); int x; cin >> x; v.push_back(x); i++; } cout << ? << ...
#include <bits/stdc++.h> using namespace std; int an[101][21][21], n, k, md = 1e9 + 7, t[21][21]; vector<int> tr[101]; void go(int v = 1, int p = 0) { an[v][0][1] = an[v][1][0] = 1; for (int i = 0; i < (int)(tr[v].size()); ++i) { int u = tr[v][i]; if (u == p) continue; go(u, v); ...
#include <bits/stdc++.h> using namespace std; long long dp[100010]; int a[310], in[310]; long long tmp[310]; struct edge { int to; int next; } e[310]; int box[100010], cnt; long long T; void init() { memset(box, -1, sizeof(box)); memset(in, 0, sizeof(in)); memset(dp, 0, sizeof(dp))...
#include <bits/stdc++.h> using namespace std; int m[26]; int main() { float a, c, d, b; cin >> a >> b >> c >> d; float sa = max((3 * a) / 10.0, a - (a / 250.0) * c); float sb = max((3 * b) / 10.0, b - (b / 250.0) * d); if (sa > sb) cout << Misha ; else if (sb > sa) cout << Va...
#include <bits/stdc++.h> using namespace std; const int maxn = 3e5 + 5; int n, m; int first[maxn], second[maxn]; void solve() { cin >> n >> m; for (int i = 1; i <= m; ++i) cin >> first[i] >> second[i]; int a, b; a = first[1]; b = -1; for (int i = 1; i <= m; ++i) { if (first[i] !=...
#include <bits/stdc++.h> using namespace std; int main() { int x, y; cin >> x >> y; if (((x < y) ? x : y) % 2) cout << Akshat ; else cout << Malvika ; return 0; }
#include <bits/stdc++.h> using namespace std; const int P = 10, N = 1e5 + 10; int inverse(int a, int m) { int m0 = m, t, q; int x0 = 0, x1 = 1; if (m == 1) return 0; while (a > 1) { q = a / m; t = m; m = a % m, a = t; t = x0; x0 = x1 - q * x0; x1 = t; } ...
#include <bits/stdc++.h> using namespace std; long long a[101][101]; int main() { long long n, m; cin >> n >> m; long long mn = min(m, n); cout << mn + 1 << endl; for (long long i = 0; i <= mn; i++) cout << i << << (mn - i) % (mn + 1) << endl; }
#include <bits/stdc++.h> using namespace std; char _; long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); } long long fpow(long long b, long long exp, long long mod) { if (exp == 0) return 1; long long t = fpow(b, exp / 2, mod); if (exp & 1) return t * t % mod * b % mod; ...
#include <bits/stdc++.h> using namespace std; template <typename T> void maxE(T& a, const T& b) { a = max(a, b); } template <typename T> void minE(T& a, const T& b) { a = min(a, b); } template <typename T> ostream& operator<<(ostream& out, const vector<T>& t_) { out << [ ; for (auto i...
#include <bits/stdc++.h> using namespace std; long long read() { char x = getchar(); long long ans = 0; while (!isdigit(x)) x = getchar(); while (isdigit(x)) ans = ans * 10 + x - 0 , x = getchar(); return ans; } long long in[250005], now, n, vis[250005], dp[250005][2]; vector<pair<long lo...
#include <bits/stdc++.h> using namespace std; long long n, a[1024], b[1024], c[1024], t[4], dd, d, have[1024]; int main() { cin >> n; for (int i = 0; i < n; i++) { cin >> a[i]; } bool flag = 0; for (int i = 0; i < n; i++) { cin >> b[i]; if (b[i] != a[i]) { c[d] = i; ...
#include <bits/stdc++.h> using namespace std; const int maxn = 100005; int n, s; long long a[maxn], b[maxn], c[maxn]; vector<int> p[2]; bool cmp1(int i, int j) { return b[i] - c[i] > b[j] - c[j]; } bool cmp2(int i, int j) { return c[i] - b[i] > c[j] - b[j]; } int main() { scanf( %d%d , &n, &s); ...
#include <bits/stdc++.h> using namespace std; const double PI = 2.0 * acos(0.0); const int INF = 1000 * 1000 * 1000; const int maxn = 1100; int W, H, N, M, cnt, tot; char g[maxn][maxn]; int upp[maxn][maxn], lf[maxn][maxn]; bool can; void play(int x, int y) { if (x == N || y == M) return; bool ...
#include <bits/stdc++.h> using namespace std; int main() { int k; int l; cin >> k >> l; int u[k]; int y[l]; for (int i = 0; i < k; i++) { cin >> u[i]; } for (int i = 0; i < l; i++) { cin >> y[i]; } long long int h = 0; long long int v = 0; int f = 0; i...
#include <bits/stdc++.h> using namespace std; long long n, m, k, x = 1; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n >> k; m = k * (5 + (n - 1) * 6); cout << m << endl; while (n--) { cout << x * k << << (x + 1) * k << << (x + 2) * k << ...
#include <bits/stdc++.h> using namespace std; const int N = 3e5 + 5; const long double PI = 3.1415926535; const long double eps = 1e-07; const long long INF = 1e18; const int inf = 1e9; const long long M = 305; const string IO[2]{ NO n , YES n }; const string io[2]{ No n , Yes n }; struct STree { ...
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; vector<string> a(n); for (int i = 0; i < n; ++i) cin >> a[i]; for (int j = 0; j < m; ++j) { vector<int> indx; for (int i = 0; i < n; ++i) { if (a[i][j] == # ) indx.push_back(i); } ...
#include <bits/stdc++.h> using namespace std; const int maxn = 2 * 1e5 + 100; vector<int> Prime; int main() { Prime.clear(); int n, k; scanf( %d%d , &n, &k); int flag = 1; for (int i = 2; flag && i <= n; i++) { if (n % i == 0) { while (n % i == 0) { Prime.push_back(i)...
#include <bits/stdc++.h> using namespace std; char s[10]; int n; int notzero[12], cnt[12], ten[10], ans; int main() { ten[0] = 1; for (int i = 1; i < 8; ++i) ten[i] = 10 * ten[i - 1]; scanf( %d , &n); for (int i = 1; i <= n; ++i) { scanf( %s , s); int len = strlen(s); notzero...
#include <bits/stdc++.h> using namespace std; bool a[4]; int main() { int n; string s; int cz = 0; int c1 = 0; int c0 = 0; cin >> s; for (int i = 0; i < s.length(); ++i) if (s[i] == 0 ) ++c0; else if (s[i] == 1 ) ++c1; else if (s[i] == ? ) +...
#include <bits/stdc++.h> using namespace std; int main() { long long n, k; cin >> n >> k; long long v[n + 10]; for (long long i = 0; i < n; i++) { cin >> v[i]; } sort(v, v + n); k--; long long div = k / n; long long cnt = 0; long long val = v[div]; for (long long i ...
#include <bits/stdc++.h> using namespace std; struct atom { long long f, w, where; void scan() { scanf( %I64d%I64d , &f, &w); } } x[310000]; priority_queue<long long> A, B; int compare(atom k1, atom k2) { return k1.f > k2.f || (k1.f == k2.f && k1.where < k2.where); } int n, pre, ans, where; ...
#include <bits/stdc++.h> using namespace std; int n, m, x, y, z; string str[5][200]; int blcks[5], whites[5]; int ara[] = {0, 1, 2, 3}; int main() { cin >> n; for (int i = 0; i < 4; i++) { for (int j = 0; j < n; j++) cin >> str[i][j]; int tmp = 0; for (int j = 0; j < n; j++) { ...
#include <bits/stdc++.h> using namespace std; struct SegTree { int sz; vector<int> dat; SegTree(int _sz = 1) { sz = 1; while (sz < _sz) sz <<= 1; dat.resize(sz << 1); } void upd(int pos, int val) { pos += sz - 1; dat[pos] = val; while (pos > 1) { pos >...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); int n, k; cin >> n >> k; string s; cin >> s; string res = ; for (int i = 0; i < n; i++) { if ((s[i] - a ) >= ( z - s[i])) { if ((s[i] - a ) <= k) { k -= (s[i] - a );...
#include <bits/stdc++.h> using namespace std; int parent[300005], maxLen[300005]; int findRoot(int u) { int root = u; while (parent[root] != root) { root = parent[root]; } while (parent[u] != root) { int y = parent[u]; parent[u] = root; u = y; } return root; } v...
#include <bits/stdc++.h> int n, m; struct Matrix { long long a[2][2]; } mt[205]; Matrix mult(Matrix x, Matrix y) { Matrix c; for (int i = 0; i < 2; i++) for (int j = 0; j < 2; j++) c.a[i][j] = 0; for (int i = 0; i < 2; i++) for (int j = 0; j < 2; j++) for (int k = 0; k < 2; k...
#include <bits/stdc++.h> using namespace std; int sum[1000005]; int main() { int n, x; cin >> n; for (int i = 0; i < n; ++i) for (int j = 0; j < n; ++j) { scanf( %d , &x); if (i == j) sum[i] = x; } int all = 0; for (int i = 0; i < n; ++i) all += sum[i]; int q, t...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long int t; cin >> t; while (t--) { long long int n, s = 0; cin >> n; long long int* arr = new long long int[n]; for (long long int i = 0; i < n; i++) { ...
#include <bits/stdc++.h> using namespace std; const int N = 20, S = (1 << 16) + 10, V = 2048; bitset<V> dp[S]; int a[N], id[N]; priority_queue<pair<int, int> > q; int main() { int n, k, v = 0; scanf( %d%d , &n, &k); for (int i = 1; i <= n; ++i) scanf( %d , &a[i]), v += a[i]; dp[0][0] = 1; ...
#include <bits/stdc++.h> #pragma comment(linker, /stack:200000000 ) #pragma GCC optimize( Ofast ) #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native ) using namespace std; long long n, k, s, h[200005]; int main() { ios::sync_with_stdio(false); cin.tie(0); cin >> n >> k ...
#include <bits/stdc++.h> using namespace std; const int inf = 0x3f3f3f3f; inline int Read() { int x = 0, f = 1; char c = getchar(); while (c > 9 || c < 0 ) { if (c == - ) f = -1; c = getchar(); } while (c >= 0 && c <= 9 ) { x = x * 10 + c - 0 ; c = getchar(); ...
#include <bits/stdc++.h> using namespace std; pair<long long, long long> a[200005]; signed main() { long long n, j; cin >> n >> j; j %= 2 * n; long long x0, y0; cin >> x0 >> y0; for (long long i = 0; i < n; i++) { cin >> a[i].first >> a[i].second; } for (long long i = 1; i <=...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int T; cin >> T; while (T--) { long long x, y; cin >> x >> y; if (y % x == 0LL) { cout << x << n ; } else if (x > y) { cout << x + y << n ; ...
#include <bits/stdc++.h> using namespace std; const int maxn=1e5+10; int a[maxn]; int f[maxn]; int n,m,gcnt,ans; int main() { scanf( %d ,&n); for (int i=1;i<=n;i++) scanf( %d ,&a[i]),f[i]=n+1; gcnt=1; for (int i=2,prevmin=0;i<=n;i++) { if (a[i-1]!=a[i]) gcnt++; f[a[i-1]]=min(f...
#include <bits/stdc++.h> using namespace std; char s[2005]; const int mod = 1e9 + 7; int n, k, t[2005]; int a[2005][2005], b[2005][2005]; int mp(const int &a, const int &b) { return (int)(1ll * a * b % mod); } int add(const int &a, const int &b) { return (a + b) % mod; } int main() { scanf( %d %d %s...
#include <bits/stdc++.h> using namespace std; bool isPrime(int n) { if (n <= 1) return false; if (n <= 3) return true; if (n % 2 == 0 || n % 3 == 0) return false; for (int i = 5; i * i <= n; i = i + 6) if (n % i == 0 || n % (i + 2) == 0) return false; return true; } int nextPrime(int N...
#include <bits/stdc++.h> using namespace std; const int INF = (int)2e9; int main() { int k, n, m, q; cin >> k >> n >> m >> q; map<string, map<string, int>> rec; vector<string> art(n); map<int, map<string, int>> b; for (int(i) = (int)(0); (i) < (int)n; ++(i)) cin >> art[i]; sort(art.beg...
#include <bits/stdc++.h> using namespace std; const int mx = 3005; const int N = 100005; int n, a[mx][mx], b[mx][mx], ans[N]; pair<int, int> t[N]; inline int check(int lx, int rx, int ly, int ry) { int cnt = b[rx][ry]; if (lx) cnt -= b[lx - 1][ry]; if (ly) cnt -= b[rx][ly - 1]; if (lx && ly)...
#include<bits/stdc++.h> using namespace std; #ifndef ONLINE_JUDGE #include Mohit.h #endif typedef long long ll; typedef long double ld; #define endl n #define rep(i,n) for(ll i = 0; i < (n); ++i) #define repA(i, a, n) for(ll i = a; i <= (n); ++i) #define repD(i, a, n) for(ll i = a; i...
#include <bits/stdc++.h> using namespace std; void solve() { long long n, z = 0; cin >> n; long long a[n], b[n]; for (long long i = 0; i < n; i++) { cin >> a[i]; } for (long long i = 0; i < n; i++) { cin >> b[i]; } vector<long long> neg, pos; for (long long i = 0; i <...