func_code_string
stringlengths
59
71.4k
#include <bits/stdc++.h> using namespace std; template <typename P, typename Q> ostream& operator<<(ostream& os, pair<P, Q> p) { os << ( << p.first << , << p.second << ) ; return os; } template <typename P, typename Q> istream& operator>>(istream& is, pair<P, Q>& p) { is >> p.first >> p.sec...
#include <bits/stdc++.h> using namespace std; const int MAXN = 105; int n; string s[MAXN]; string ans = ; vector<int> g[MAXN]; bool has[MAXN]; bool used[MAXN]; vector<int> tp; void dfs(int v) { used[v] = true; for (int i = 0; i < g[v].size(); i++) { int to = g[v][i]; if (!used[...
#include <bits/stdc++.h> int n; long long l[100001], r[100001], ans = 0; int main() { scanf( %d , &n); for (int i = 1; i <= n; i++) scanf( %I64d%I64d , &l[i], &r[i]); std::sort(l + 1, l + n + 1); std::sort(r + 1, r + n + 1); for (int i = 1; i <= n; i++) { ans += l[i] > r[i] ? l[i] : r[i]...
#include <bits/stdc++.h> using namespace std; int n, a, b, men, may; vector<pair<int, int> > arr; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n; men = 1000000009; for (int i = 0; i < n; i++) { cin >> a >> b; arr.push_back(make_pair(a, b)); ...
#include <bits/stdc++.h> using namespace std; const long long Max = 2e5 + 9, inf = 1e18; long long A[Max], B[Max], d[Max]; int find_nxt(long long id, long long x) { if (A[id] - B[id] >= x) return B[id] += x, id; d[id] = find_nxt(d[id], x - A[id] + B[id]), B[id] = A[id]; return d[id]; } int main(...
#include <bits/stdc++.h> using namespace std; const int MAXN = 100005; int c1[MAXN], c2[MAXN]; vector<pair<int, int> > ans; int main() { int n; scanf( %d , &n); int in, winner; for (int i = 1; i <= n; i++) { scanf( %d , &in); if (i == n) winner = in; c1[i] = c1[i - 1] + (in =...
#include <bits/stdc++.h> using namespace std; int32_t main() { int n, m; char x; cin >> n >> m; cin >> x; vector<vector<char> > c(n + 1); char gar; vector<char> u1(m + 1, . ); for (int j = 0; j < (n + 1); ++j) c[j] = u1; bool b[n][m]; stack<pair<int, int> > s, t; for (in...
#include <bits/stdc++.h> using namespace std; struct Rect { int x1, y1, x2, y2; long long area() { return (long long)(x2 - x1) * (y2 - y1); } }; long long intersect(const Rect&, const Rect&); Rect intersectingRect(const Rect&, const Rect&); int main() { Rect white, black1, black2, b1Inside, b2In...
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; const int N = 2e5 + 10; const int INF = 0x3f3f3f3f; const long long LINF = 0x3f3f3f3f3f3f3f3f; inline int read() { static char buf[1000000], *p1 = buf, *p2 = buf; register int x = false; register char ch = p1 == p2 &&...
#include <bits/stdc++.h> using namespace std; int const maxn = 4e6; int tr01[maxn][2], x; int len, check[maxn], n, tot; void insert(int x) { int ex, v = 0; for (int i = 29; i >= 0; i--) { ex = !!(x & (1 << i)); if (tr01[v][ex]) v = tr01[v][ex]; else { tr01[v][ex] = ++...
#include <bits/stdc++.h> using namespace std; string s; inline void YES() { puts( Yes ); exit(0); } inline void NO() { puts( No ); exit(0); } int main() { cin >> s; int n = (int)s.length(); string baru = ; int score = 0; int pl = -1, mn = 1; for (int i = n - 1; i ...
#include <bits/stdc++.h> using namespace std; int main() { int l, r, a; cin >> l >> r >> a; int total = 0; while (l > 0 && r > 0) { l--, r--, total += 2; } while (l > 0 && a > 0) { l--, a--, total += 2; } while (r > 0 && a > 0) { r--, a--, total += 2; } if (...
#include <bits/stdc++.h> using namespace std; long mod(long int a) { return (a > 0 ? a : (-a)); } long min(long int a, long int b) { return (a) > (b) ? (b) : (a); } long max(long int a, long int b) { return (a) < (b) ? (b) : (a); } bool sortbyff(const pair<int, int> &a, const pair<int, int> &b) { return (...
#include <bits/stdc++.h> using namespace std; const int N = 200 + 5; int n, m, p[N]; double dp[N][N][N]; int main() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); cout << fixed << setprecision(10); cin >> n >> m; for (int i = 0; i < n; i++) cin >> p[i]; for (int i = 0; i < n; i++...
#include <bits/stdc++.h> using namespace std; char s[100002]; int main() { cin.getline(s, 100002); int l = strlen(s), flag; for (int i = 0; i < l; i++) { char c = s[i]; if (s[i] == s[l - i - 1] && (c == A || c == H || c == I || c == M || c == O || c == T || ...
#include <bits/stdc++.h> using namespace std; struct res { double l, r, w; } T[800000]; double x[210000], s[210000], p, c, ans, w; int N, M, i, l, r; int init(int i, int l, int r, int x, double w) { if (x < l || r < x) return 0; if (l == r) { T[i].w = T[i].l = T[i].r = w; return 0; ...
#include <bits/stdc++.h> int n; int m; char str[3000100]; int preveri(int x) { int stevec = 0; if (x - 1 >= 0 && str[x - 1] == . ) { stevec++; } if (x + 1 < n && str[x + 1] == . ) { stevec++; } return stevec; } int main() { scanf( %d , &n); scanf( %d , &m); ...
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 10, Mod = 1e9 + 7; int n, m, k, A[N], P[N]; map<int, int> M; long long tot; int main() { scanf( %d%d , &n, &k); m = (1 << k) - 1; for (int i = 1; i <= n; i++) scanf( %d , &A[i]), P[i] = P[i - 1] ^ A[i], M[min(P[i], m - P[i])...
#include <bits/stdc++.h> using namespace std; const int mod = 1000000007; struct Interval { long long a, b, ind; bool operator<(const Interval& ano) const { return b < ano.b; } } a[200010]; bool used[200010]; set<long long> st; struct SEG { long long sum[1600010], tg1[1600010], tg2[1600010]; ...
#include <bits/stdc++.h> using namespace std; class TaskD { public: void solve(std::istream &in, std::ostream &out) { long long n; in >> n; vector<long long> a(n), b(n), sa(n), sb(n); for (auto &i : a) in >> i; for (auto &i : b) in >> i; for (long long i = 0; i < n; ++i) {...
#include <bits/stdc++.h> using namespace std; int a[400][400]; int main() { int n; cin >> n; long long k = n * n; for (int j = 1; j <= n; j++) { if (j % 2 != 0) { for (int i = 1; i <= n; i++) { a[i][j] = k--; } } else { for (int i = n; i >= 1; i--) { ...
#include <bits/stdc++.h> using namespace std; int a[20][110], b[20][110], c[20][110]; vector<int> res; int main() { int n, m, k; scanf( %d%d%d , &n, &m, &k); for (int i = 0; i < n; i++) { char st[15]; scanf( %s , st); for (int j = 0; j < m; j++) scanf( %d%d%d , &a[i][j], &b[i][j], ...
#include <bits/stdc++.h> using namespace std; vector<int> sorted; vector<set<int> > v; set<int> solve(int lf, int rg) { if (lf == rg) { return v[lf]; } int md = (lf + rg) >> 1; set<int> x = solve(lf, md); set<int> y = solve(md + 1, rg); for (int val : y) { v[md + 1].insert(va...
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 5; const int N = 1e12; string a[105]; int dp1[105], dp2[105], dp3[105]; int main() { int n, m, i, j, k; cin >> n >> m; for (i = 0; i < n; i++) { cin >> a[i]; dp1[i] = maxn; dp2[i] = maxn; dp3[i] = maxn; ...
#include <bits/stdc++.h> struct T { int l, h, a; void scan() { scanf( %d%d%d , &l, &h, &a); } }; const int INF = 1e9; T Map[6][6]; int F[6]; int minF, maxC; int cost; int N; void check() { for (int i = 1; i < N - 1; ++i) { if (F[i] != 0) return; } if (F[N - 1] < minF || F[N -...
#include <bits/stdc++.h> using namespace std; long long A[1000000]; long long ncr(int n, int k) { long long ans = 1; k = k > n - k ? n - k : k; int j = 1; for (; j <= k; j++, n--) { if (n % j == 0) { ans *= n / j; } else if (ans % j == 0) { ans = ans / j * n; } el...
#include <bits/stdc++.h> using namespace std; const int MX = 1000001; const int MI = 100001; const int MT = 10001; int main() { long long int n, ans = 0; cin >> n; ans = (n * (n + 1)) / 2; n--; for (int i = 0; i < n; ++i) { int x; scanf( %d , &x); ans -= x; } cout...
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; const long long inf = 1e15; const int N = 1e6 + 6; int n, q, b[N], t; queue<int> even, odd, ans; int main() { scanf( %d%d , &n, &q); for (int i = 1; i <= n; i++) { if (i % 2) odd.push(i); else ...
#include <bits/stdc++.h> using namespace std; long n, ar[500000], ps[500000], q, tp, a, b, bd[500000], sb[500000]; long res, fb; long gs(long v) { fb = v / 200; res = 0; for (int i = 0; i < fb; i++) res += sb[i]; for (int i = fb * 200; i <= v; i++) res += bd[i]; return res; } int main() ...
#pragma GCC optimize( O3 ) #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx ) #include <iostream> #include <cstdio> #include <vector> #include <set> #include <map> #include <string> #include <cstring> #include <cstdlib> #include <algorithm> #include <cassert> #include <cmath> #i...
#include <bits/stdc++.h> #pragma GCC optimize( 3 , inline , Ofast ) using namespace std; template <class T> inline void read(T &x) { x = 0; T f = 1; char ch = getchar(); while (!isdigit(ch)) { if (ch == - ) f = -1; ch = getchar(); } while (isdigit(ch)) x = x * 10 + ch - 48...
#include <bits/stdc++.h> using namespace std; signed main() { ios::sync_with_stdio(NULL); cin.tie(0); cout.tie(0); int a, b, c; cin >> a >> b >> c; c -= 2; b -= 1; int ans = min({a, b, c}); if (ans < 0) { cout << 0; } else { ans = ans * 3 + 3; cout << ans; ...
#include <bits/stdc++.h> using namespace std; pair<int, int> _e[600005], ex[600005]; vector<int> ee[600005]; int nt, rr = 0, dn = 1, colnum, dfnn, _enum, nn, mm, n, m, ca, idnum, num, top, hd[600005], dfn[600005], low[600005], instk[600005], a[600005], b[600005], col[600005], dffn[600005], d...
#include <bits/stdc++.h> using namespace std; const long long int mod = 998244353; const long long int mxn = 1e5 + 7; long long int a[mxn]; long long int power(long long int a, long long int b); long long int flcm(long long int n, long long int m); long long int fgcd(long long int n, long long int m); l...
#include <bits/stdc++.h> using namespace std; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); const int N = 3123; int n, m; vector<tuple<int, int, int>> g[N]; vector<int> lpos, rpos; bool vis[N]; bool dfs(int u, int l, int r) { vis[u] = 1; if (u == n) return 1; bool ret ...
#include <bits/stdc++.h> using namespace std; int main() { int n, sum = 0; string s; cin >> n; for (int i = 0; i < n; i++) { cin >> s; if (s == Tetrahedron ) { sum += 4; } else if (s == Cube ) { sum += 6; } else if (s == Octahedron ) { sum += 8; ...
#include <bits/stdc++.h> using namespace std; vector<long long> start_years; vector<long long> start_numbers; vector<long long> mods; void init() { long long start = 1989; start_years.resize(10); start_numbers.resize(10); mods.resize(10); start_years[0] = start; start_numbers[0] = 9; ...
#include <bits/stdc++.h> using namespace std; using int64 = long long; constexpr int64 P = 1000000007; struct FiniteField { private: int64 x; public: FiniteField(int64 x) : x(x) { if (x > P || x < 0) { cerr << Invalied FiniteField! << endl; exit(1); } } Fin...
#include <bits/stdc++.h> using namespace std; int main() { string com; map<string, bool> mp; int ans = 0; while (getline(cin, com)) { if (com[0] == + ) { com.erase(com.begin(), com.begin() + 1); mp[com] = 1; } else if (com[0] == - ) { com.erase(com.begin(), com....
#include <bits/stdc++.h> namespace { using namespace std; template <typename T> istream &operator>>(istream &is, vector<T> &v) { for (T &t : v) is >> t; return is; } template <typename T> bool space(vector<T>) { return false; } template <typename T> bool space(T) { return true; } ...
#include <bits/stdc++.h> using namespace std; long long n, m, v, k, cnt; signed main() { scanf( %lld%lld%lld , &n, &m, &v), k = (v == 1) ? 2 : 1; if (m < n - 1 || m > n - 1 + (n - 2) * (n - 3) / 2) puts( -1 ), exit(0); for (long long i = 1; i <= n; i++) if (i != v) printf( %lld %lld n , i, v); ...
#include <bits/stdc++.h> using namespace std; long long fac(long long n) { long long m = 1; for (long long i = 1; i <= n; i++) { m = m * i; } return m; } long long gcd(long long x, long long y) { if (x > y) swap(x, y); long long md; while (1) { md = y % x; if (md ==...
#include <bits/stdc++.h> using namespace std; const int MAX_N = int(1e6) + 10; int n; char buffer[MAX_N]; int main() { gets(buffer); n = strlen(buffer); reverse(buffer, buffer + n); vector<pair<char, int> > v; for (int i = 0, j, l = -1; i < n; i = j) { for (j = i; j < n && buffer[j] ...
#include <bits/stdc++.h> using namespace std; void solve() { int N; cin >> N; string s1, s2; cin >> s1 >> s2; int num_different = 0; vector<pair<bool, int>> differences; int num_s1_has_a = 0; int num_s1_has_b = 0; for (int i = 0; i < N; ++i) { if (s1[i] != s2[i]) { ...
#include <bits/stdc++.h> using namespace std; const long long INF = 1e9 + 7; int main() { ios::sync_with_stdio(0); ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, m; cin >> n >> m; vector<pair<int, int> > ans; if (n == 1) { if (m == 1) { printf( 1 1 ); ...
#include <bits/stdc++.h> using namespace std; struct __s { __s() { srand(time(NULL)); if (1) { ios_base::Init i; cin.sync_with_stdio(0); cin.tie(0); } } ~__s() { if (!1) fprintf(stderr, Execution time: %.3lf s. n , (double)clock() ...
#include <bits/stdc++.h> using namespace std; const int _ = 2e5 + 7; const int __ = 8e5 + 7; const long long inf = 1e17; int n, m, q; long long wgt[2][_], cst[_], minx[__], tag[__]; struct edge { int x, y; long long w; } e[_]; void build(int k, int l, int r, bool id) { tag[k] = 0; if (...
#include <bits/stdc++.h> using namespace std; inline void file_handling() { ios_base::sync_with_stdio(0); cin.tie(0); } void solve() { string dish; cin >> dish; long long b, c, s; b = s = c = 0; for (long long i = 0; i < dish.size(); ++i) if (dish[i] == B ) b++; ...
#include <bits/stdc++.h> using namespace std; const long long int mxn = 0; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long int t = 1; while (t--) { long long int i, j, k, n, m, x; cin >> n >> x >> k; vector<long long int> a(n); for (i = 0; i < n; i++...
#include<bits/stdc++.h> using namespace std; const int maxn=1e5+10; int a[maxn],b[maxn],c[maxn]; vector<int> v1[maxn],v2[maxn],app[maxn]; int ans[maxn]; int main() { int t; cin>>t; while(t--) { memset(ans,-1,sizeof(ans)); int n,m; cin>>n>>m; for(int i=1;i<=n;i++) { v1[...
#include <bits/stdc++.h> using namespace std; int main() { long long n, step, smallest, count = 0; bool possible = true; cin >> n >> step; vector<long long> p(n); cin >> p[0]; smallest = p[0]; for (int i = 1; i < n; i++) { cin >> p[i]; if (p[i] < smallest) { smallest ...
#include <bits/stdc++.h> using namespace std; const int dx[] = {0, 1, 0, -1}; const int dy[] = {1, 0, -1, 0}; inline int read() { int x = 0, f = 1; char ch = getchar(); while (ch < 0 || ch > 9 ) { if (ch == - ) f = -1; ch = getchar(); } while (ch >= 0 && ch <= 9 ) { ...
#include <bits/stdc++.h> int n, sum, ans[6050]; bool isprime(int x) { if (x < 2 || (x & 1) == 0) { return 0; } for (int i = 2; i * i <= x; ++i) { if (x % i == 0) { return 0; } } return 1; } int main() { scanf( %d , &n); sum = n * (n + 1) / 2; if (isprime...
#include <bits/stdc++.h> using namespace std; string s[2005]; char str[2005][2005]; int a[2005][2005]; int v[2005][2005]; long long dp[8005][2005]; int pool[8005], top = 0; int child[8005]; int ID = 0, n; int getID() { return pool[--top]; } void pre() { for (int i = 8000; i >= 0; i--) pool[top...
#include <bits/stdc++.h> #pragma comment(linker, /STACK:256000000 ) using namespace std; const int maxN = 110; int n, k, a[maxN]; void solve() { vector<vector<double> > d[2]; int u = 0, v = 1; d[u].assign(maxN, vector<double>(maxN, 0.0)); for (int i = 1; i <= n; ++i) { for (int j = i + ...
#include <bits/stdc++.h> using namespace std; int q[100010], t, n; bool cmp(int a, int b) { return a < b; } int main() { scanf( %d , &t); for (int i = 1; i <= t; i++) { scanf( %d , &n); for (int j = 1; j <= n; j++) { scanf( %d , &q[j]); } int flag = 1; sort(q + 1, q...
#include <bits/stdc++.h> int main() { long int n, m; int t; scanf( %d , &t); while (t--) { scanf( %ld%ld , &n, &m); if (n == 1) printf( 0 n ); else if (n == 2) { printf( %ld n , m); } else { printf( %ld n , 2 * m); } } return 0; }
#include <bits/stdc++.h> using namespace std; int n; struct particle { int x, v; } particles[500002]; bool possible(long double time) { long double maxRightyX = -1e19; for (int i = 1; i <= n; i++) { if (particles[i].v > 0) { maxRightyX = max(particles[i].x + particles[i].v * time, ma...
#include <bits/stdc++.h> using namespace std; vector<vector<int>> adj; vector<int> a; vector<int> dep; vector<int> ret; unordered_map<int, vector<int>> pmp; unordered_map<int, vector<int>> mp; vector<int> primeFactors(int num) { vector<int> ret; for (int i = 2; i * i <= num; i++) { while (...
#include <bits/stdc++.h> using namespace std; bool prime(int x) { if (x % 2 == 0) return 0; for (size_t i = 3; i * i <= x; i += 2) { if (x % i == 0) return 0; } return 1; } void solve() { int n, x = 3; cin >> n; while (n) { if (prime(x)) { cout << x << ; ...
#include <bits/stdc++.h> using namespace std; const int N = 210000; int n, root, opt, Max[N << 6], lson[N << 6], rson[N << 6], lazy[N << 6]; void pushdown(int k, int l, int r) { if (!lazy[k]) return; if (l != r) { if (!lson[k]) lson[k] = ++opt; if (!rson[k]) rson[k] = ++opt; lazy[lson[...
#include <bits/stdc++.h> using namespace std; const int N = 6e5; const int oo = 1e9 + 5; int du[] = {-1, 0, 0, 1}; int dv[] = {0, -1, 1, 0}; const long long mod = 1e9 + 7; long long sqr(long long x) { return x * x; } int n, x, a[N + 5], ans; bool vis[N + 5]; int main() { ios_base::sync_with_stdi...
#include <bits/stdc++.h> using namespace std; const int MAXN = 5 * 100 * 1000 + 10; int arr[MAXN], nx[MAXN], bf[MAXN]; stack<int> st; pair<int, int> pr[MAXN]; int main() { int n, m, p; cin >> n >> m >> p; string second, w; cin >> second >> w; second = + second; int cntr = 1; ...
#include <bits/stdc++.h> using namespace std; int l, r, a, b, dif, t, x, lit, poz; bool uz[27]; char s[1001]; int main() { cin >> a >> b >> l >> r; dif = min(500, r - l); l = l % (a + b); if (l == 0) l = a + b; r = l + dif; if (l <= a) { for (int i = l; i <= min(a, r); i++) s[++p...
#include <bits/stdc++.h> using namespace std; long long pwr(long long base, long long p, long long mod = (1000000007LL)) { long long ans = 1; while (p) { if (p & 1) ans = (ans * base) % mod; base = (base * base) % mod; p /= 2; } return ans; } long long gcd(long long a, long lon...
#include <bits/stdc++.h> using namespace std; const long long iinf = 1e9 + 10; const long long inf = 1ll << 60; const long long MOD = 998244353; void GG() { cout << 0 n ; exit(0); } const long long maxn = 1e5 + 5; vector<pair<long long, long long> > here[maxn]; template <long long mod> stru...
#include <bits/stdc++.h> using namespace std; template <class T> inline void amin(T &first, const T &second) { if (second < first) first = second; } template <class T> inline void amax(T &first, const T &second) { if (first < second) first = second; } void solve() { int n; cin >> n; ...
#include <bits/stdc++.h> using namespace std; int years[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 28, 31, ...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); long long q; cin >> q; for (long long t = 0; t < q; t++) { long long n, k; cin >> n >> k; vector<vector<long long>> adj((size_t)n); map<pair<long long, long long...
#include <bits/stdc++.h> using namespace std; struct pt { unsigned long long x, y, v; }; int n; vector<unsigned long long> a, b; pt c[200005]; vector<vector<unsigned long long>> d; void sq(vector<unsigned long long>& v) { sort(v.begin(), v.end()); v.erase(unique(v.begin(), v.end()), v.end())...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; string s; cin >> s; map<char, int> mp; for (char c : s) mp[c]++; cout << 2 * min(mp[ L ], mp[ R ]) + 2 * min(mp[ U ], mp[ D ]) << endl; }
#include <bits/stdc++.h> using namespace std; int main() { string a, b, c; int n; cin >> n >> a; sort(a.begin(), a.end()); for (int i = 0; i < a.size(); i += n) b += a[i]; for (int i = 0; i < n; i++) c += b; b = c; sort(b.begin(), b.end()); if (b != a) cout << -1; else ...
#include <bits/stdc++.h> using namespace std; vector<int> v[100005]; vector<pair<int, int> > asdf; int n; int m; int cnt[100005]; vector<int> nxt[100005]; void build(int at, int num) { if (cnt[at] > 2) return; if (num == m) { while ((int)asdf.size()) { printf( %d %d n , 1 + asdf.ba...
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 4; vector<int> adj[N]; int deg[N]; int lv[N]; int decr[N]; int vis[N]; int main() { int n, k; scanf( %d%d , &n, &k); for (int i = 0; i < n - 1; i++) { int x, y; scanf( %d%d , &x, &y); adj[x].push_back(y); ...
#include <bits/stdc++.h> using namespace std; const int MAXN = 5000000; void solve1(char *S) { int lenS = strlen(S); for (int i = 0, j = lenS - 1; i < j; i++, j--) if (S[i] < S[j]) break; else if (S[i] > S[j]) { for (i = 0, j = lenS - 1; i < j; i++, j--) swap(S[i], S[j]); ...
#include <bits/stdc++.h> using namespace std; const int sz = 1e5 + 100; const int INF = 1e9; const double eps = 1e-7; void solve() { int n; cin >> n; vector<long long> a(n + 1, 0); for (int i = 0; i < n; i++) { cin >> a[i]; } sort(a.begin(), a.begin() + n); for (int i = n - 1...
#include <bits/stdc++.h> using namespace std; set<long long> hs, vs; multiset<long long> hms, vms; int main() { long long h, w, t, n, i, j, k, l; char c; cin >> w >> h >> n; hs.insert(0); hs.insert(h); vs.insert(0); vs.insert(w); hms.insert(h); vms.insert(w); for (i = 0; ...
#include <bits/stdc++.h> using namespace std; int main() { int i, n, a[101], d = 0, x = 0, y = 0, m = 0, p = 0; cin >> n; for (i = 0; i < n; i++) { cin >> a[i]; m = max(m, a[i]); p = min(p, a[i]); if (a[i] > 0) x++; else if (a[i] < 0) y++; } float z ...
#include <bits/stdc++.h> using namespace std; int m, n; char a[1005][1005]; int f[1005][1005]; int cc; int g[1000005]; bool ok[15]; vector<int> s[1000005]; int ki[4] = {0, 0, 1, -1}; int kj[4] = {1, -1, 0, 0}; int main() { scanf( %d%d , &m, &n); for (int i = 1; i <= m; i++) for (int ...
#include <bits/stdc++.h> using namespace std; template <class T> void pr1(T a) { cout << a; cout << n ; } template <class T, class T2> void pr2(T a, T2 b) { cout << a << << b; cout << n ; } template <class T, class T2, class T3> void pr3(T a, T2 b, T3 c) { cout << a << ...
#include <bits/stdc++.h> using namespace std; int in(char &c) { return scanf( %c , &c); } int in(char s[]) { return scanf( %s , s); } int in(int &x) { return scanf( %d , &x); } int in(long long &x) { return scanf( %lld , &x); } int in(double &x) { return scanf( %lf , &x); } int in(pair<int, int> &p) { ret...
#include <bits/stdc++.h> using namespace std; long long int par[4000]; long long int sub[4000]; long long int n; vector<long long int> adj[4000]; long long int dp[4000][4000]; long long int conec[4000][4000]; void dfsc(long long int node, long long int cur, long long int dir, long long int p...
#include <bits/stdc++.h> using namespace std; const long long MOD = 998244353; struct intmod { long long val; intmod(long long _val = 1) { val = _val % MOD; if (val < 0) val += MOD; } bool operator!=(intmod rhs) const { return val != rhs.val; } bool operator==(intmod rhs) const { r...
#include <bits/stdc++.h> long long int power(long long int x, long long int n) { long long int result = 1; while (n) { if (n % 2 == 1) result = result * x; n = n / 2; x = x * x; } return result; } long long int gcd(long long int a, long long int b) { if (!b) return a; ret...
#include <bits/stdc++.h> using namespace std; int main() { int n; char with[1005], make[1005]; int count1[26], count2[26], ans = 0; bool flag = false; scanf( %s , with); memset(count1, 0, sizeof(count1)); memset(count2, 0, sizeof(count2)); for (int i = 0; with[i]; i++) { count1...
#include <bits/stdc++.h> std::vector<int> a[500005]; int n, m, col[500005], ans[505][505], f[505][505]; int read() { char ch = getchar(); if (ch == . || ch == X ) return ch == X ; return read(); } int t(int x, int y) { return (x - 1) * m + y; } std::pair<int, int> it(int id) { return std...
#include <bits/stdc++.h> using namespace std; int n, m, x, y; string s; bool v[505][505]; bool judge(int x, int y) { return (x >= 1 && x <= n && y >= 1 && y <= m); } int dirx(char x) { if (x == L || x == R ) return 0; if (x == U ) return -1; return 1; } int diry(char x) { if (x == U...
#include <bits/stdc++.h> int v[1 << 20], n, L = 1048575; void R(int i) { if (~i) { int p; for (; v[p = L ^ i] || p > n; L /= 2) ; v[p] = 1; R(i - 1); printf( %d , p); } } int main() { scanf( %d , &n); printf( %lld n , 1LL * n * (n + 1)); R(n); }
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int a, b; cin >> a >> b; if (a == b) cout << 0 << endl; else if ((a < b && (b - a) % 2 == 1) || ((a > b) && (a - b) % 2 == 0)) { cout << 1 << endl; } else if ((a < b &&...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n; cin >> n; unordered_map<char, int> v; int cnt = 0; int j = 0; for (int i1 = 1; i1 <= n; ++i1) { char ch; string second; cin >> ch >> second; if (...
#include <bits/stdc++.h> using namespace std; const int MAXN = 100000; const int MAXM = 300000; struct node { int key, id, rev; int siz1, siz2, s; node *fa, *ch[2], *mx; } tree[MAXN + MAXM + 5], *ad[MAXN + MAXM + 5]; struct edge { int u, v, w, id; edge(int _u = 0, int _v = 0, int _w = 0,...
#include <bits/stdc++.h> using namespace std; long long ar[1000010]; int main() { long long n; cin >> n; long long ans = 0; if (n % 2 == 1) puts( 0 ); else { n = n / 2; n = (n - 1) / 2; cout << n << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 10; int n, m, k, par[maxn], ans[maxn]; bool arr[maxn]; pair<int, pair<int, int>> e[maxn]; int get_path(int v) { return par[v] < 0 ? v : (par[v] = get_path(par[v])); } void merge(int v, int u) { if ((v = get_path(v)) == (u = get_path(...
#include <bits/stdc++.h> using namespace std; long long a, b; int t; int main() { cin >> t; while (t--) { cin >> a >> b; cout << a + b << n ; } return 0; }
#include <bits/stdc++.h> using namespace std; void Yahia74() {} const int N = 1e5 + 74, M = 1e5 + 74, OO = 0x3f3f3f3f; int main() { Yahia74(); int n, cnt[N] = {}; cin >> n; for (int i = 0; i < n; i++) { int x; cin >> x; if (i < n / 2) { if (x - i >= 0) cnt[x - i]++; ...
#include <bits/stdc++.h> template <typename Sep, typename Head, typename... Tail> void fold_print(Sep sep, Head&& h, Tail&&... args) { ((std::cerr << h) << ... << (std::cerr << sep, args)); } std::mt19937_64 myrand( std::chrono::high_resolution_clock::now().time_since_epoch().count()); using namespa...
#include <bits/stdc++.h> using namespace std; long long int fact[200005]; long long int n; struct point { long long int x, y; }; bool cmp(struct point i1, struct point i2) { if (i1.x != i2.x) return i1.x < i2.x; else { return (i1.y < i2.y); } } long long int fact_(long long i...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); int N, M; cin >> N >> M; using Interval = pair<int, int>; vector<Interval> intervals(N); for (int i = 0; i < N; i++) { cin >> intervals[i].first >> intervals[i].second; } int i = 0; ...
#include <bits/stdc++.h> using namespace std; struct node { long long p; int d; } store[200005]; bool cmp(node& a, node& b) { return a.d < b.d; } bool check(int e, int full, int n) { if (store[0].d > full) return 1; for (int i = 0; i < (n - 1); ++i) if (store[i + 1].d - store[i].d > full...
#include <bits/stdc++.h> using namespace std; inline int getint() { static char c; while ((c = getchar()) < 0 || c > 9 ) ; int res = c - 0 ; while ((c = getchar()) >= 0 && c <= 9 ) res = res * 10 + c - 0 ; return res; } const int MaxN = 200000; int n; int col[MaxN + 1]; s...