func_code_string
stringlengths
59
71.4k
#include <bits/stdc++.h> using namespace std; const int M = INT32_MAX; const int NMAX = 10007; int main() { cin.tie(0); cin.sync_with_stdio(0); cout.precision(30); string z[2]; cin >> z[0] >> z[1]; int n; cin >> n; cout << z[1] << << z[0] << endl; for (int i = 0; i < n; i...
#include <bits/stdc++.h> using namespace std; pair<int, int> arr[200000]; int ans[200000], tree[500000], lazy[500000]; set<int> s; int n; set<int>::iterator it; int main() { ios::sync_with_stdio(false); cin >> n; for (int i = 0; i < n; i++) { cin >> arr[i].first; arr[i].second = i;...
#include <bits/stdc++.h> using namespace std; const int inf = 1e9 + 7; int arr[200005]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; cin >> n; if (n % 2 == 0) { cout << NO n ; return 0; } int flag = 1, ct = 1; for (int i = 1; i <= n;...
#include <bits/stdc++.h> using namespace std; void out(vector<int>& v) { for (int i = 0; i < v.size(); ++i) cout << v[i] << ; cout << endl; } int main() { int n; cin >> n; vector<int> p(n + 1); p.back() = 1; vector<int> c(n); c[0] = 1; if (n == 2) { p[1] = 1; } ...
#include <bits/stdc++.h> using namespace std; int main() { int n, p, i, j, k, result; cin >> n >> p; int a[n + 1], b[n + 1]; for (i = 1; i <= n; i = i + 1) cin >> a[i]; i = 0; j = p - 1; result = p - 1; do { int m = (i + j) / 2; bool check = true; b[0] = 0; fo...
#include <bits/stdc++.h> using namespace std; int main() { int n, m; vector<int> a; scanf( %d%d , &n, &m); int min = n + 2; for (int i = 0; i < m; i++) { int t; scanf( %d , &t); if (t < min) { a.push_back(t); min = t; } if (t == 1) break; } s...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ; int t = 1; while (t--) { map<char, long long int> a, b; long long int n; cin >> n; string s, t; cin >> s >> t; for (long long int ...
#include <bits/stdc++.h> using namespace std; int f; vector<string> cur; void upd(string s, int x, int y, int o) { int dx = 0, dy = 1; if (o) swap(dx, dy); for (int i = 0; i < s.size(); i++) { int xx = x + dx * i; int yy = y + dy * i; if (cur[xx][yy] == . || cur[xx][yy] == s[i]) ...
#include <bits/stdc++.h> using namespace std; long long mod(long long a, long long b) { if (a % b < 0) { return a % b + b; } return a % b; } long long mod_exp(long long a, long long b, long long c) { long long res = 1; a = a % c; while (b > 0) { if (b % 2 == 1) { res ...
#include <bits/stdc++.h> using namespace std; const int N = 3e5 + 5; struct ACA { int pool[N], ptp; int stk[30], sz[N], rt[N], rtid, tp; int nxt[N][26], tran[N][26], fail[N], end[N], num[N], tot; inline int newnode() { return ++tot; } int merge(int x, int y) { if (!x || !y) return x | y;...
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 1, logN = 21 + 1, mod = 1e9 + 7; int fl(int n) { int ans = 0; while (n /= 2) ++ans; return ans; } int ord2(int n) { int ans = 0; while (n % 2 == 0) { n >>= 1; ++ans; } return ans; } long long binpow(l...
#include <bits/stdc++.h> using namespace std; int n, t, a[110]; int main() { scanf( %d%d , &n, &t); for (int i = 1; i <= n; i++) { scanf( %d , &a[i]); } for (int i = 1; i <= n; i++) { t = t - 86400 + a[i]; if (t <= 0) { printf( %d , i); break; } } re...
#include <bits/stdc++.h> using namespace std; int main() { int n; int a[100005]; int b[100005]; scanf( %d , &n); for (int i = 1; i <= n; i++) { scanf( %d%d , &a[i], &b[i]); } int flag = 1; if (n % 2 == 0) for (int i = 1; i < n / 2; i++) { if (a[i] + a[i + n / 2] !...
#include <bits/stdc++.h> using namespace std; long long po(long long a, long long b) { long long x = 1, y = a; while (b > 0) { if (b % 2) { x = x * y; x %= 1000000007; } y = y * y; y %= 1000000007; b /= 2; } return x; } int main() { if (0) { ...
#include <bits/stdc++.h> using namespace std; const int N = 1000100; int n, q, s[N / 2], f[N / 2], par[N / 2], timer; vector<int> g[N / 2]; void dfs(int x = 1, int pp = 0) { s[x] = ++timer; par[x] = pp; for (auto &it : g[x]) if (it != par[x]) { dfs(it, x); } f[x] = ++timer;...
#include <bits/stdc++.h> using namespace std; const int N = 200005; int n, k, root, col[N], sz[N]; vector<int> g[N], a[N]; int dfs(int v, int pr = -1) { int mx = col[v]; sz[v] = col[v]; for (auto& to : g[v]) { if (to == pr) continue; int root = dfs(to, v); if (root != -1) return ...
#include <bits/stdc++.h> using namespace std; #pragma comment(linker, /STACK:100000000 ) int matrix[900][900]; int tmp[900][900]; int dx[4] = {1, 0, -1, 0}; int dy[4] = {0, 1, 0, -1}; vector<pair<int, int> > all; void go(int x, int y) { queue<pair<int, int> > q; tmp[x][y] = 1; q.push(make_p...
#include <bits/stdc++.h> using namespace std; long long mod = 1e9 + 7; long long INF = 1e7; double EPS = 1e-12; double tick() { static clock_t oldt; clock_t newt = clock(); double diff = 1.0 * (newt - oldt) / CLOCKS_PER_SEC; oldt = newt; return diff; } long long int powP(long long int ...
#include <bits/stdc++.h> using namespace std; const int maxx = 2000010; const double pi = acos(-1.0); const double eps = 1e-15; map<pair<long long, long long>, long long> h, mk; map<pair<long long, pair<long long, long long> >, long long> hh; int t, n, m, k; long long ans = 0, total = 0, sum = 0, cnt = ...
#include <bits/stdc++.h> using namespace std; int N, M, K, P[105]; int main() { scanf( %d %d %d , &N, &M, &K); for (int i = 0; i < K; i++) scanf( %d , &P[i]); int ans = 0; for (int i = 0; i < N; i++) { for (int j = 0; j < M; j++) { int x; scanf( %d , &x); int idx; ...
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f, N = 2e5 + 5; const long long inf = 1e18; inline int read() { int sum = 0, f = 1; char c = getchar(); while (c > 9 || c < 0 ) { if (c == - ) f = -f; c = getchar(); } while (c >= 0 && c <= 9 ) sum = su...
#include <bits/stdc++.h> int main() { char s[51]; scanf( %s , s); int i, tf, na = 0, t1 = strlen(s); if (t1 >= 1 && t1 <= 50) { for (i = 0; i < t1; i++) { if (s[i] == a ) { na = na + 1; } } if (2 * na > t1) { tf = t1; } else { tf = (2 ...
#include <bits/stdc++.h> using namespace std; const int M = 131; int a[100002], rmp[100002], n, cnt, ans; unsigned int h[100002], p[100002]; vector<int> v[100002]; vector<pair<int, int> > del; map<int, int> mp; inline bool cmp(int x, int y) { int xe = y - 1, ye = 2 * y - x - 1; if (ye > n) retur...
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e5 + 5; int N, M; int arr[MAXN]; int dp[MAXN]; int main() { cin.tie(0); cin.sync_with_stdio(0); cin >> N >> M; int prv; cin >> prv; int lft = 1; for (int a = 2; a <= N; a++) { int cur; cin >> cur; i...
#include <bits/stdc++.h> using namespace std; int main() { int arr[100][100] = {0}; int n, x; cin >> n >> x; for (int i = 0; i < n; i++) { arr[i][i] = x; } for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { cout << arr[i][j] << ; } cout << endl; ...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int trn = 1 << (n + 1); trn--; int a[30000]; for (int i = 2; i <= trn; i++) cin >> a[i]; int q = 1 << n; int mx = 0; int leng[30000]; for (int i = q; i <= trn; i++) { leng[i] = 0; int j = ...
#include <bits/stdc++.h> using namespace std; const long long mod = 998244353; const int N = 1e5 + 5; 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; } voi...
#include <bits/stdc++.h> const int N = 1e5 + 5; int n, k, a[N]; int ans[N], top; int main() { scanf( %d%d , &n, &k); int sum = 0; for (int i = 1; i <= n; i++) scanf( %d , a + i), sum += a[i]; if (sum % k) return !printf( No ); int num = sum / k; top = 0; int now = 0, l = 1; for (...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); long long int n, m, t, q, a, b, c, h, d, x, y, z, i, j, k, ans = 0, ans2 = 0, cur = 0, cur2 = 0, sum = 0, sum2 = 0, maxn; string str = , str2, str3; cin >> t; while (t--) { cin >> ...
#include <bits/stdc++.h> using namespace std; long long A[100005], Nr[100005], Viz[100005]; vector<pair<long long, long long> > V[100005]; long long n; long long ans; long long DFSNR(long long x) { long long nrc = 1; Viz[x] = 1; for (auto i : V[x]) if (!Viz[i.first]) { nrc += DFSNR...
#include <bits/stdc++.h> int w, n, m, c[1 << 12], id[1 << 12], f[531441]; int dfs(char* g, int s, int t) { if (!*g) return c[s] * f[t]; s <<= 1; t *= 3; switch (*g++) { case A : return dfs(g, s, t + 2) + dfs(g, s | 1, t); case O : return dfs(g, s, t); case X : ...
/* AUTHOR: lz.askey CREATED: 23.07.2021 13:57:23 LANG: C++11 */ #include <assert.h> #include <algorithm> #include <bitset> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <deque> #include <iostream> #include <iterator> #include <map> #include <new> ...
#include <bits/stdc++.h> using namespace std; string s[102]; int main() { int n, i, cnt[27], j, k; cin >> n; for (i = 0; i < n; i++) cin >> s[i]; int ans = 0, temp, first, second, x, r; for (i = 1; i <= 26; i++) { for (j = 1; j <= 26; j++) { temp = 0; for (k = 0; k < n; k...
#include <bits/stdc++.h> using namespace std; string ans[10] = { , , 2 , 3 , 223 , 5 , 53 , 7 , 7222 , 7332 }; int main() { int n; string s, a = ; cin >> n; cin >> s; for (int i = 0; i < n; i++) { if (s[i] == 0 || s[i] == 1 ) continue; a += ans[(s[i] - 0 )]; } ...
#include <bits/stdc++.h> using namespace std; using ll = long long; void solve() { ll a, b, p; string s; cin >> a >> b >> p >> s; ll n = s.length(); s[n - 1] = s[n - 2]; vector<ll> cost(n, 0); if (s[n - 1] == A ) cost[n - 1] = a; else cost[n - 1] = b; for (int i = ...
#include <bits/stdc++.h> using namespace std; typedef struct { int sum, l; bool f[55]; } node; queue<node> qu; node x, y; map<int, int> m; map<int, int>::iterator pos; int main() { int n, k, a[55], i, j, t; while (scanf( %d %d , &n, &k) != EOF) { for (i = 0; i < n; i++) scanf( %d ,...
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 10; int a[maxn]; queue<int> q; queue<int> m; int main() { int n; scanf( %d , &n); int fu = 0; int maxfu = -0x3f3f3f3f; int idfu; for (int i = 1; i <= n; i++) { scanf( %d , &a[i]); if (a[i] < 0) { ...
#include <bits/stdc++.h> using namespace std; int main() { int T; cin >> T; string ans = / ; while (T--) { string s; cin >> s; if (s[0] == p ) { cout << ans << endl; continue; } cin >> s; if (s[0] == / ) ans = s + / ; else ...
#include <bits/stdc++.h> int deg[100000]; int xr[100000]; int edges[100000][2]; int main() { int n, t = 0; scanf( %d , &n); for (int i = 0; i < n; i++) { scanf( %d%d , &deg[i], &xr[i]); } for (int i = 0; i < n; i++) { if (deg[i] == 1) { int k = i; do { e...
#include <bits/stdc++.h> using namespace std; int main() { int n, L = 1; cin >> n; int *a = new int[n]; for (int i = 0; i < n; i++) { cin >> a[i]; if (i != 0) { if (a[i] > a[L - 1]) L = i + 1; } } if (a[0] > a[L - 1]) L = 1; sort(a, a + n); cout << L << ...
#include <bits/stdc++.h> using namespace std; const int N = 1e6; long long int n, m, ans, col; vector<long long int> v[N], par(N), cola(N); set<long long int> se[N]; void dfs(long long int s, long long int p) { par[s] = p; col = 1; set<long long int> no, used; for (auto ic : se[s]) { i...
#include <bits/stdc++.h> using namespace std; const long long inf = 0x3f3f3f3f3f3f3f3f; int32_t main() { long long n; cin >> n; vector<long long> v1, v2; long long i, j, ans = 0; for (i = 0; i < n; i++) { long long len; cin >> len; bool fg = true; long long mi = INT_MAX...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int t = 1; while (t--) { int n, k; cin >> n >> k; vector<int> m(n), c(k + 1), cnt(k + 1, 0); for (int i = 0; i < n; i++) { cin >> m[i]; cnt[m[i]]++; ...
#include <bits/stdc++.h> using namespace std; int main() { long long x, sum; while (~scanf( %lld , &x)) { if (x < 0) x = -x; if (x == 2) printf( 3 n ); else if (x == 0) printf( 0 n ); else { for (long long i = 1; i <= x; i++) { sum = i * (i + 1) / 2;...
#include <bits/stdc++.h> using namespace std; void solve() { long long x, y, ans; cin >> x >> y; ans = (x / 2) * y; if (x % 2) ans += y / 2; cout << ans; } int32_t main() { ios_base::sync_with_stdio(false); long long t = 1; while (t--) { solve(); } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); long long n, x, m = 1e18; cin >> n; vector<long long> v; for (int i = 0; i < n; i++) { cin >> x; v.push_back(x); } sort(v.begin(), v.end()); for (int i = 0; i < v.size(...
#include <bits/stdc++.h> using namespace std; const int MAXN = 1005; const int MAXM = 1e5 + 5; struct EC { vector<pair<int, int> > has[2][MAXN]; int deg[2][MAXN], color[MAXM], c[2]; void prep(int d) { for (int i = 0; i < 2; i++) for (int j = 0; j < MAXN; j++) has[i][j].resize(d + 1, {0...
#include <bits/stdc++.h> using namespace std; int main() { long long int n, k, sum = 0, curr = 0, j = 0; vector<long long int> a(100000), res; cin >> n >> k; for (long long int i = 0; i < n; i++) { cin >> a[i]; sum += a[i]; } if (sum % k) { cout << No ; } else { ...
#include <bits/stdc++.h> using namespace std; int main() { long long n, s = 2, ans = 0, i; cin >> n; if (n < 2) { cout << 0; return 0; } for (i = 1; i <= 1e6; ++i) { if (s > n) break; if ((n - s) % 3 == 0) ++ans; s += 3 * i + 2; } cout << ans; }
#include <bits/stdc++.h> using namespace std; struct point { double x, y; point() { x = y = 0.0; } point(double A, double B) { x = A, y = B; } double operator*(point B) { return x * B.x + y * B.y; } point turn(double A) { return point(x * cos(A) - y * sin(A), y * cos(A) + x * sin(A)); ...
#include <bits/stdc++.h> using namespace std; int a[1234567]; int w[1234567]; int main() { int n, m, q, i; while (scanf( %d%d , &n, &m) != EOF) { int k = 0; memset(a, 0, sizeof(a)); for (i = 0; i < n; i++) { scanf( %d , &q); if (q < 1234560) a[q] = 1; } i = ...
#include <bits/stdc++.h> using namespace std; const int mod = 1e9; int n, m; long long a[200100], fibo[200100], sumfibo[200100]; struct Segment_Tree { int left, right, len; long long s0, s1; } tree[200100 << 2]; struct Data { long long a[2][2]; } bb[200100], one, b; Data operator*(const Da...
#include <bits/stdc++.h> long a[2200]; long absl(long k) { if (k < 0) { k = 0 - k; } return k; } int main() { long i, j, n, ans, l, r; scanf( %ld , &n); for (i = 0; i < n; i++) { scanf( %ld , a + i); a[i] = absl(a[i]); } for (i = 0, ans = 0; i < n; i++) { ...
#include <bits/stdc++.h> using namespace std; char a[500001], b[500001]; int nxt[500000]; int c[2], la, lb; int kmp() { nxt[0] = -1; if (lb == 0) { return 0; } int no = -1; for (int i = 1; i < lb; i++) { while (no != -1 && b[no + 1] != b[i]) { no = nxt[no]; } ...
#include <bits/stdc++.h> using namespace std; const int N = 200005; struct node { int to, next; } p[N << 2]; int head[N], tot, n, now[N], du[N]; bool vis[N], isok; vector<pair<int, int> > a; void add(int x, int y) { p[++tot] = (node){y, head[x]}; head[x] = tot; p[++tot] = (node){x, head[...
#include <bits/stdc++.h> using namespace std; const int maxn = 1000005; const int mod = 998244353; long long f[5009]; long long c[5009][5009]; long long ch(int a, int b) { long long sum = 0; for (int i = 0; i <= a && i <= b; i++) { sum += ((c[a][i] * c[b][i] % mod) * f[i] % mod); } ret...
#include <bits/stdc++.h> using namespace std; const int N = 1000000; int k; int n; vector<int> v; int read() { scanf( %d %d , &n, &k); for (int i = 1; i <= n; i++) { int t; scanf( %d , &t); v.push_back(t); } sort(v.begin(), v.end()); printf( %d , v[n - k]); return 0...
#include <bits/stdc++.h> using namespace std; const int mod = 998244353; template <typename T> void chkmin(T &x, T y) { if (y < x) x = y; } template <typename T> void chkmax(T &x, T y) { if (y > x) x = y; } template <typename T> void upd(T &x, T y) { if ((x += y) >= mod) x -= mod; } ...
#include <bits/stdc++.h> #pragma comment(linker, /STACK:256000000 ) using namespace std; const int INF = (1 << 29) + 5; const long long int LLINF = (1ll << 59) + 5; const int MOD = 1000 * 1000 * 1000 + 7; int n, q; pair<string, string> arr[228]; map<string, bool> can; queue<string> now; int main() ...
#include <bits/stdc++.h> long long int fact[200010]; long long int power(long long int a, long long int b) { long long int ans = 1; long long int k = a; while (b) { if (b % 2 == 1) ans *= k, ans %= 1000000007; b /= 2; k *= k, k %= 1000000007; } return ans; } long long int i...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; for (int i = 0; i < n; ++i) { for (int j = 0; j < n; ++j) { if (i == j) cout << 0 << ; else if (min(i, j) == 0) cout << 2 * (i + j) % (n - 1) + 1 << ; else cout <...
#include <bits/stdc++.h> using namespace std; bool isprime(long long int n) { if (n <= 1) return false; if (n <= 3) return true; if (n % 2 == 0 || n % 3 == 0) return false; for (long long int i = 5; i * i <= n; i += 6) { if (n % i == 0 || n % (i + 2) == 0) return false; } return true; ...
#include <bits/stdc++.h> using namespace std; long long P(long long m, long long n); long long pi(long long x); long long phi(long long m, long long n); bool isprm[400005]; int cntprm[400005]; vector<long long> prm; void Init() { for (int i = 2; i <= 400000; ++i) { isprm[i] = true; } f...
#include <bits/stdc++.h> using namespace std; string numToBinary(int n, int digits) { string s; while (n) { int bil = n % 2; n /= 2; s += (bil + 0 ); } while (s.size() < digits) { s += 0 ; } reverse(s.begin(), s.end()); return s; } long long computeInv(const...
#include <bits/stdc++.h> using namespace std; const int maxn = 150000 + 7; const long long mod = 1e9 + 7; const long long INF = 5e18 + 7; const int inf = 1e9 + 7; const long long maxx = 1e6 + 700; int main() { int n, m, i; scanf( %d%d , &n, &m); i = max(2 * n, 3 * m); while (i / 2 + i / 3 ...
#include <bits/stdc++.h> using namespace std; const int N = 10010; const int M = 15; const double eps = 1e-7; const int INF = 1 << 30; int n; struct node { double x, y, z; node() { x = y = z = 0; } node(double xx, double yy, double zz) { x = xx; y = yy; z = zz; } } poy[...
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const long long LINF = 0x3f3f3f3f3f3f3f3f; const int MOD = 1e9 + 7; template <typename S, typename T> inline bool Min(S &a, const T &b) { return a > b ? a = b, true : false; } template <typename S, typename T> inline bool Ma...
#include <bits/stdc++.h> using namespace std; char q[7][50] = { Anka , Chapay , Cleo , Troll , Dracul , Snowy , Hexadecimal }; map<string, int> h; int a[3], u[7], v[3], w[7], r, rb, m[7][7]; void upd() { int i, mx, mn, j, k; for (i = 0; i < 3; v[i] = 0, i++) ; ...
#include <bits/stdc++.h> using namespace std; const int mxprime = 2750131; int prime[mxprime + 1], res; int func(int n) { for (int i = 2; i * i <= n; i++) if (n % i == 0) return n / i; } vector<int> ord(mxprime, false); int vc[500001]; int main() { int n; cin >> n; prime[1] = true;...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int c1 = 0, n, t; cin >> n; for (int i = 0; i < n; i++) { cin >> t; if (t % 2 == 1) { c1++; } } cout << min(c1, n - c1 + (2 * c1 - n) / 3) << n ; re...
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 10; int T, n, a, b, c; string s; int shi, bu, jian; int main() { cin >> T; while (T--) { shi = bu = jian = 0; cin >> n; cin >> a >> b >> c; cin >> s; for (int i = 0; i < s.length(); i++) { if (s[i...
#include <bits/stdc++.h> using namespace std; const int MAXN = 1000 * 100 + 3, inf = 1000 * 1000 * 100; int n, m, a[MAXN], b[MAXN], t[MAXN], ans = 0, y, z; int main() { cin >> n >> m >> y >> z; for (int i = 0; i < n; i++) cin >> a[i]; b[0] = -inf; b[m + 1] = inf; for (int i = 1; i <= m; i++)...
/* * yaswanth phani kommineni */ #include <bits/stdc++.h> using namespace std; typedef long long int ll; #define endl n ; void solve(){ ll n; cin >> n; n*=2; vector <ll> v(n); map <ll,ll> m; for(ll i=0;i<n;i++){ cin >> v[i]; m[v[i]]++; } sort(v.begin(),v.end()); ...
#include <bits/stdc++.h> using namespace std; int toDelete = 0, arr[1500010], N; int main() { cin.sync_with_stdio(0); cin.tie(0); cin >> N; for (int i = 0; i < N; ++i) { int x; cin >> x; arr[x]++; } int ans = 0; for (int i = 0; i <= 1500000; ++i) { int val = arr...
#include <bits/stdc++.h> using namespace std; template <class T> ostream& operator<<(ostream& out, vector<T>& v) { out << [ ; for (auto k : v) out << k << ; out << ] ; return out; } vector<int> g[500]; string color; bool posible = true; void DFS(int n, int p, char c) { if (color...
#include <bits/stdc++.h> using namespace std; vector<vector<pair<int, int> > > v(400005); int parent[400005], low[400005], disc[400005], TIME; bool visited[400005], road[400005]; set<int> bridge; int SIZE; pair<int, int> EDGE[400005]; void dfs(int a) { TIME++; visited[a] = true; disc[a] = TI...
#include <bits/stdc++.h> using namespace std; using ll = long long; const int INF = 0x3f3f3f3f; const ll LINF = 0x3f3f3f3f3f3f3f3fLL; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout << setprecision(10) << fixed; int n, k; cin >> n >> k; vector<double> p(n); for (auto& x...
#include <bits/stdc++.h> using namespace std; int dis[305][305], lca[305], val[305]; int main() { int n, x; scanf( %d , &n); for (int i = 1; i <= n; i++) { scanf( %d , &x); lca[x] = i; val[i] = x; } char s[305]; memset(dis, 0, sizeof dis); for (int i = 1; i <= n; i++)...
#include <bits/stdc++.h> using namespace std; const int maxn = 2e3 + 7; long long read() { long long res = 0, f = 1; char c = getchar(); while (!isdigit(c) && c != - ) c = getchar(); if (c == - ) f = -1, c = getchar(); while (isdigit(c)) res = (res << 1) + (res << 3) + c - 48, c = getchar();...
#include <bits/stdc++.h> using namespace std; int main() { int n = 0, l = 0, r = 0, x = 0, c[16]; cin >> n >> l >> r >> x; for (int i = 0; i < n; i++) cin >> c[i]; sort(c, c + n); int total = 0, cnt = 0, ret = 0, easy = 0, hard = 0; for (int i = 0; i < (1 << n); i++) { total = 0, cnt =...
#include <bits/stdc++.h> char putnb[20]; using namespace std; const long long mod = 1e9 + 7; const long long mod2 = 1999999973; const int infs = 1e8; const long long inf = 1e18; const int N = 200000; long long A[N + 5]; long long dp[N + 5][2]; bool vis[N + 5][2]; bool solved[N + 5][2]; long long...
#include <bits/stdc++.h> using namespace std; const int X = 1e5 + 9; const long long inf = (1ll << 60); int n, sum, a[109], b[109], c[109]; int main() { cin >> n; for (int i = 0; i < n; i++) { cin >> a[i]; b[a[i]]++; } for (int i = 0; i < n; i++) { cin >> a[i]; c[a[i]]+...
#include <bits/stdc++.h> using namespace std; const int MaxN = 200010, MaxB = 500, MaxA = 1000010, mod = 1000000007; struct Query { int l, r, id; bool operator<(const Query &a) const { return r < a.r; } } q[MaxN]; int n, m, a[MaxN]; vector<pair<int, int> > f[MaxN]; int last[MaxA]; int prime[MaxA...
#include <bits/stdc++.h> using namespace std; int main() { int t; long long x, y; cin >> t; for (int i = 0; i < t; i++) { cin >> x >> y; cout << x << << 2 * x << endl; } }
#include <bits/stdc++.h> using namespace std; inline void splay(int &v) { v = 0; char c = 0; int p = 1; while (c < 0 || c > 9 ) { if (c == - ) p = -1; c = getchar(); } while (c >= 0 && c <= 9 ) { v = (v << 3) + (v << 1) + c - 0 ; c = getchar(); } v *= ...
#include <bits/stdc++.h> using LL = long long; const int maxn = 1011000; const LL mod = 1e9 + 7; int seed = 29, n; char str[maxn]; LL base[maxn], Hash[maxn]; int ans[maxn]; void init() { memset(base, 0, sizeof(base)); base[0] = 1; for (int i = 1; i < maxn; i++) { base[i] = base[i - 1] ...
#include <bits/stdc++.h> using namespace std; inline long long read() { long long sum = 0, ff = 1; char ch = getchar(); while (!isdigit(ch)) { if (ch == - ) ff = -1; ch = getchar(); } while (isdigit(ch)) sum = sum * 10 + (ch ^ 48), ch = getchar(); return sum * ff; } const lo...
#include <bits/stdc++.h> using namespace std; long long gi() { char cc = getchar(); long long cn = 0, flus = 1; while (cc < 0 || cc > 9 ) { if (cc == - ) flus = -flus; cc = getchar(); } while (cc >= 0 && cc <= 9 ) cn = cn * 10 + cc - 0 , cc = getchar(); return cn * flus; ...
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 10; const int M = (1e5 + 10 + N) * 2; const int inf = 0x3f3f3f3f; int n, m, S, T; struct node { int u, v, w; } Edge[N]; bool cmp(node &a, node &b) { return a.w < b.w; } int h[N], tot, e[M], f[M], ne[M]; int d[N], cur[N]; void ad...
#include <bits/stdc++.h> using namespace std; const int NMAX = 1000 + 5; int n; int mat[NMAX][NMAX]; vector<pair<int, int> > sol; void DEI(int l, int r, int insert_type) { if (r - l + 1 < 3) return; int k; for (k = l + 1; k <= r - 1; ++k) if (mat[l][k] && mat[k][r]) break; if (insert_t...
#include <bits/stdc++.h> using namespace std; template <typename C> void ma(C& a, C b) { if (a < b) a = b; } template <typename C> void mi(C& a, C b) { if (a > b) a = b; } int cas, n, l[251], r[251], w[251], roz[251]; void licz_roz(int nr) { if (w[nr] == -1) { licz_roz(l[nr]); ...
#include <bits/stdc++.h> using namespace std; int cost[15][2][2]; string a[15]; int dp[15][2], topFloor; int memoize(int floor, int dir) { if (floor > topFloor) { return 0; } if (floor == topFloor) { return cost[floor][dir][dir]; } if (dp[floor][dir] != -1) return dp[floor][dir...
#include <bits/stdc++.h> using namespace std; set<string> S; string rotate1(string s) { string s1 = s; s1[1] = s[2]; s1[2] = s[4]; s1[4] = s[5]; s1[5] = s[1]; return s1; } string rotate2(string s) { string s1 = s; s1[0] = s[1]; s1[1] = s[3]; s1[3] = s[4]; s1[4] = s[...
#include <bits/stdc++.h> using namespace std; int INF = 0x3f3f3f3f; int INF2 = 0x7fffffff; long long LNF = 0x3f3f3f3f3f3f3f3f; long long LNF2 = 0x7fffffffffffffff; long long n, k, M, D; long long ans; int main() { scanf( %I64d%I64d%I64d%I64d , &n, &k, &M, &D); for (int i = (1); i <= (D); ++i) { ...
#include <bits/stdc++.h> using namespace std; int main() { int n, m, r; cin >> n >> m >> r; int min1 = 1001; int max1 = 0; int a, b; for (int i = 0; i < n; i++) { cin >> a; min1 = min(a, min1); } for (int i = 0; i < m; i++) { cin >> b; max1 = max(b, max1); ...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; float square = sqrt(n); float csquare = ceil(square); if ((csquare == square) || (csquare - square <= 0.5)) { cout << 4 * csquare; } else if (csquare - square > 0.5) { cout << 2 * (csquare + (csquare - 1)...
#include <bits/stdc++.h> const int Mod = (int)1e9 + 7; const int MX = 1073741822; const long long MXLL = 4611686018427387903; const int Sz = 2e5 + 1; using namespace std; inline void Read_rap() { ios_base ::sync_with_stdio(0); cin.tie(0); } int n; int a[Sz]; long long dp[Sz][20][2], lca[Sz][...
#include <bits/stdc++.h> using namespace std; int a[55][55]; int main() { int cs; scanf( %d , &cs); while (cs--) { int n, m; scanf( %d %d , &n, &m); int col = 0, row = 0; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { scanf( %d , &a[i][j]); ...
#include <bits/stdc++.h> using namespace std; int n, a[500000], o, ans; int main() { cin >> n; ans = 1; for (int i = 2; i <= n + 1; i++) { if (a[i] == 0) { a[i] = 1; o = 1; for (int j = i + i; j <= n + 1; j += i) { o = 2; ans = max(ans, o); a...
#include <bits/stdc++.h> using namespace std; int dat[2][2][2][2][2][2][2][2][2][2][2][2][2][2][2][2][2][2]; int main() { int t, i; scanf( %d , &t); long long var; char str[20]; char ch = + ; int arr[18]; while (t--) { cin >> ch; for (i = 0; i <= 17; i++) { arr[i] ...