func_code_string
stringlengths
59
71.4k
#include <bits/stdc++.h> using namespace std; const int N = (int)(1e2 + 5); int n, m, k; int grid[N][N]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> n >> m >> k; for (int(i) = (1); (i) <= (n); (i)++) for (int(j) = (1); (j) <= (m); (j)++) cin >> grid[i][j]; in...
#include <bits/stdc++.h> #pragma GCC optimize( O3 ) using namespace std; template <class c> struct rge { c b, e; }; template <class c> rge<c> range(c i, c j) { return rge<c>{i, j}; } template <class c> auto dud(c* x) -> decltype(cerr << *x, 0); template <class c> char dud(...); struct ...
#include <bits/stdc++.h> using namespace std; signed main() { long long n; cin >> n; char s; long long cnt = 0; while (cin >> s) { cnt += s == 8 ; } long long ans = 0; for (long long i = 0; i <= cnt; ++i) { if (min(i, (n - i) / 10) > ans) ans = min(i, (n - i) / 10); ...
#include <bits/stdc++.h> using namespace std; const int INF = (int)1e9; const int EPS = 1e-8; const int MOD = 1000000007; const long double PI = 3.14159265359; const int dx4[4] = {0, 1, 0, -1}; const int dy4[4] = {-1, 0, 1, 0}; const int dx8[8] = {-1, -1, -1, 0, 1, 1, 1, 0}; const int dy8[8] = {-1, 0,...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0), cout.tie(0); long long n, m, l; cin >> n >> m >> l; vector<long long> a(n); vector<pair<long long, long long>> lr(n); long long ans = 0, old = -1000; long long flag = 0; for (long...
#include <bits/stdc++.h> #pragma comment(linker, /STACK:200000000 ) using namespace std; char a[105][105]; int n, m; bool u[105][105]; int main() { memset(u, false, sizeof(u)); scanf( %d %d n , &n, &m); for (int i = 0; i < n; i++, scanf( n )) for (int j = 0; j < m; j++) scanf( %c , &a[i]...
#include <bits/stdc++.h> using namespace std; int v[1005][1005]; long long c[1005][1005], sum[1005][1005], t[1005][1005]; int main() { int n = 0, m = 0, a = 0, b = 0; scanf( %d%d%d%d , &n, &m, &a, &b); for (int i = 1; i <= n; ++i) { for (int j = 1; j <= m; ++j) { scanf( %d , &v[i][j]);...
#include <bits/stdc++.h> using namespace std; string a, p, s; bool suff[2002][2002]; bool pref[2002][2002]; long long int hash1[2002][2002]; long long int hash2[2002][2002]; set<pair<int, int> > ans; int main() { cin >> a >> p >> s; long long int mod1 = 1000000007; long long int mod2 = 10000...
#include <bits/stdc++.h> using namespace std; char str[100003]; struct Node { int val; int val2; Node* pt[26]; } node[100003]; int cnt; int mex(Node* node) { if (node->val != -1) return node->val; int f[30] = {}; for (int i = 0; i < 26; ++i) if (node->pt[i]) f[mex(node->pt[i])]...
#include <bits/stdc++.h> using namespace std; struct pairvar { int a; int b; int c; int max; }; bool isPrime(long long x) { if (x == 1) { return false; } long long a = (long long)x; for (int i = 2; i <= (long long)sqrt((double)a); i++) { if (a % i == 0) { retu...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long n, sum = 0; cin >> n; vector<long long> arr(n + 1); for (long long i = 1; i <= n; i++) cin >> arr[i], sum += arr[i]; map<pair<long long, long long>, l...
#include <bits/stdc++.h> inline int read() { register int x = 0; register char f = 1, ch = getchar(); for (; !isdigit(ch); ch = getchar()) if (ch == - ) f = !f; for (; isdigit(ch); ch = getchar()) x = (x << 1) + (x << 3) + (ch ^ 0 ); return f ? x : -x; } int n, d[250005], X, vis[250005...
#include <bits/stdc++.h> using namespace std; const bool testing = false; pair<long long, long long> d[100000]; int nf[100000], nb[100000]; pair<long long, long long> getmid(int a, int b) { long long y = d[b].second - d[a].second; long long x = d[b].first - d[a].first; pair<long long, long long> r...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int arr[n]; long long sum = 0; for (int i = 0; i < n; i++) { cin >> arr[i]; sum += arr[i]; } if (sum % 2 != 0) { sum++; } long long sum1 = 0; for (int i = 0; i < n; i++) { sum1...
#include <bits/stdc++.h> using namespace std; template <class T> T abs(T x) { if (x < 0) return -x; return x; } template <class T> T sqr(T a) { return a * a; } const double pi = acos(-1.0); const double eps = 1e-8; int a[100010]; int a1[100010]; int a2[100010]; int b; int ar[1000...
#include <bits/stdc++.h> using namespace std; ifstream in; ofstream out; const long long kk = 1000; const long long MOD = 10e9 + 7; long long a, b, x, y; long long GCD(long long n, unsigned long long m) { while (n != 0 && m != 0) { if (n > m) { n %= m; } else { m %= n; ...
#include <bits/stdc++.h> using namespace std; const int MAXN = 200000 + 5; int n, ex, ey; char s[MAXN]; struct node { int x, y; node() {} node(int _x, int _y) : x(_x), y(_y) {} } p[MAXN]; bool OK(int t) { for (int i = 0; i + t <= n; i++) { int px = p[i].x - p[0].x + p[n].x - p[i + t]...
#include <bits/stdc++.h> using namespace std; int main() { string s; int mod = 1e9 + 7; cin >> s; for (int i = 0; i < s.size(); i++) { if (s[i] == w || s[i] == m ) { cout << 0; return 0; } } int a, b = 1, c = 0; for (int i = 0; i < s.length(); i++) { ...
#include <bits/stdc++.h> using namespace std; long long mulMod(long long a, long long b, long long m = 1000000007) { long long x = 0, y = a % m; while (b > 0) { if (b % 2 == 1) x = (x + y) % m; y = (y * 2) % m; b /= 2; } return x % m; } long long expMod(long long b, long long e...
#include <bits/stdc++.h> using namespace std; const int Maxn = int(1e5); 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 ) { x = x * 10 + ch - 0 ; ch = getch...
#include <bits/stdc++.h> using namespace std; template <class T> void splitstr(const string &s, vector<T> &out) { istringstream in(s); out.clear(); copy(istream_iterator<T>(in), istream_iterator<T>(), back_inserter(out)); } template <class T> T read_value(string s) { T result; istringstr...
#include <bits/stdc++.h> using namespace std; char first[100001], second[100001], zero[100001]; int number1[10], number2[10]; int just_zero() { char *p1 = first, *p2 = second; while (number1[0]--) *p1++ = *p2++ = 0 ; return p1 - first; } int summary_ten(int count) { int min_rez = -1; in...
#include <bits/stdc++.h> using namespace std; const long long N = 2000; long long calcula(long long l, long long r, long long k) { long long d1 = -r; long long d2 = l - r; long long aum = d2 - d1; long long lim1 = d1; long long lim2 = d1 + (r * 1000000 - 1) * aum; if (lim1 <= k && k <= lim...
#include <bits/stdc++.h> using namespace std; int main() { int cakesneeded, timek, k, timeforoven; cin >> cakesneeded >> timek >> k >> timeforoven; int cyclesneeded = cakesneeded / k; if (cakesneeded % k != 0) { cyclesneeded++; } int totaltime = cyclesneeded * timek; int partialtim...
#include <bits/stdc++.h> using namespace std; int main() { long long a, b, c, d; cin >> a >> b >> c >> d; long long w, x, y, z; bool f = 1; if (a == c && f) { w = a + abs(d - b); x = b; y = a + abs(d - b); z = d; f = 0; } if (b == d && f) { w = a; ...
#include <bits/stdc++.h> using namespace std; long long gcd(long long a, long long b) { while (b) { swap(a %= b, b); } return a; } long long n, m, x, y, a, b, g; double dist1(long long curstep) { long long l1 = a / g * curstep; long long l2 = b / g * curstep; long long x1 = max(1...
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 100; long long n_r, n_g, n_b, r[maxn], g[maxn], b[maxn], ans; void cal(long long n_r, long long n_g, long long n_b, long long r[], long long g[], long long b[]) { long long x, y, z, i, j = 1, k = 1; for (i = 1; i <= n_g; ++i...
#include <bits/stdc++.h> using namespace std; vector<int> e[111]; int used[111], cnt, cnt2; void dfs(int x) { used[x] = 1; cnt += e[x].size(); cnt2++; for (int i = 0; i < e[x].size(); i++) if (used[e[x][i]] == 0) dfs(e[x][i]); } int main() { int i, j, k, n, m, stop = 0; scanf( ...
#include <bits/stdc++.h> using namespace std; queue<int> qx, qy; int d[2][110000]; char s[2][110000]; int n, k; int main() { gets(s[0]); sscanf(s[0], %d %d , &n, &k); gets(s[0]); gets(s[1]); memset(d, 63, sizeof(d)); d[0][0] = 0; qx.push(0); qy.push(0); for (; qx.size();...
#include <bits/stdc++.h> using namespace std; int t, n; int a[200001]; int main() { scanf( %d , &t); while (t--) { scanf( %d , &n); for (int i = 1; i <= n; i++) scanf( %d , &a[i]); bool flag = false; for (int i = 2; i <= n; i++) if (abs(a[i] - a[i - 1]) > 1) { f...
#include <bits/stdc++.h> using namespace std; int main() { int n; scanf( %d n , &n); set<int> in, x; long totalCost(0), cost(0); while (n--) { int a, b, c; scanf( %d %d %d n , &a, &b, &c); totalCost += c; if (in.count(a) || x.count(b)) { cost += c; x.inser...
#include <bits/stdc++.h> using namespace std; int n; vector<int> a; void printall(int x, int y, bool paren = false) { if (paren) printf( ( ); for (int i = x; i < y; i++) printf( %d-> , a[i]); printf( %d , a[y]); if (paren) printf( ) ); } int main() { scanf( %d , &n); a.resize(n); ...
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; long double PI = acosl(-1); const long long infl = 1e18; const int nmax = 1e6 + 5; const int MAXLG = log2(nmax) + 1; const int N = 2e4 + 5; struct Hopcroft_Karp { int NIL = 0, INF = (1 << 28), match[N], dist[N], n, m; v...
#include <bits/stdc++.h> using namespace std; double max(double a, double b) { return (a > b ? a : b); } int main() { std::ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; double A[n][n]; for (int i = 0; i < n; ++i) { for (int j = 0; j < n; ++j) { cin >> A[i][j]; ...
#include <bits/stdc++.h> int MakeTB(unsigned int *A, unsigned int *B, unsigned int *T, unsigned int N, unsigned int StartBit) { for (unsigned int i = 0; i < N - 1; i++) if (A[i] == 0) if (B[i] == 0) { if (i > 0 && T[i] != 0) return 0; T[i] = 0; T[i + 1] = 0...
#include <bits/stdc++.h> using namespace std; map<int, int> mp, x[1000005]; int main() { int t1; cin >> t1; while (t1--) { string s, t; cin >> s >> t; mp.clear(); for (int i = 0; i < s.size(); i++) mp[s[i]]++; bool q = true; for (int i = 0; i < t.size(); i++) { ...
#include <bits/stdc++.h> using namespace std; int a[10001]; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n, m, k; cin >> n >> m >> k; long long int x1 = 1, x2 = 1; int p = k; if (k % 2 == 0) { k -= 1; } int x = 1, y = 1, res = 0; for...
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e6 + 10; int n, a[MAXN], d[MAXN]; bool pic[MAXN]; int main() { scanf( %d , &n); for (int i = 0; i < n; i++) { int temp; scanf( %d , &temp); pic[temp] = 1; } fill(d, d + MAXN, 1); int ans = 0; for (int i =...
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 5; struct BIT { int n; vector<int> bit; BIT(int _n = 0) { n = _n; bit.assign(n + 5, 0); } void update(int pos, int val) { for (; pos <= n; pos += pos & -pos) bit[pos] += val; } int getsum(int pos) { ...
#include <bits/stdc++.h> using namespace std; struct ss { long long sur, x, y, z; ss() {} ss(long long a, long long b, long long c, long long d) { sur = a; x = b; y = c; z = d; } } ans; int n, tot, a[100], b[100]; long long x, uu, p[100], u[200000]; long long calc(lon...
#include <bits/stdc++.h> using namespace std; int depth[200005], dad[200005]; int dep = 0; void node_depth(vector<int> vec[], int i) { dep = depth[i] + 1; for (auto j : vec[i - 1]) { if (j != dad[i]) { depth[j] = dep; } } for (auto j : vec[i - 1]) { if (j != dad[i]) { ...
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 7, maxm = 35 * maxn; int nxt[maxm][2], tot, a[maxn]; long long ans = 0; void ins(int x) { int now = 0; for (int i = 29; i >= 0; i--) { int go = (x >> i) & 1; if (nxt[now][go] == 0) nxt[now][go] = ++tot; now = nxt[no...
#include <bits/stdc++.h> using namespace std; int main() { int a, b = 0; cin >> a; if (a % 2 == 1) { b += 16; } if ((a >> 1) % 2 == 1) { b += 2; } if ((a >> 2) % 2 == 1) { b += 8; } if ((a >> 3) % 2 == 1) { b += 4; } if ((a >> 4) % 2 == 1) { ...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); long long n; cin >> n; vector<long long int> v(n); for (long long int i = 0; i < n; i++) { cin >> v[i]; } sort((v).begin(), (v).end()); set<long long> s...
#include <bits/stdc++.h> #pragma comment(linker, /STACK:1024000000,1024000000 ) template <class T> bool scanff(T &ret) { char c; int sgn; T bit = 0.1; if (c = getchar(), c == EOF) return 0; while (c != - && c != . && (c < 0 || c > 9 )) c = getchar(); sgn = (c == - ) ? -1 : 1; ...
#include <bits/stdc++.h> using namespace std; const int M = 200010; int par[M]; int sz[M]; struct edge { int u, v, w; bool operator<(const edge &e) const { return w < e.w; } }; edge E[M]; pair<int, int> q[M]; long long out[M]; int f(int u) { return par[u] = par[u] == u ? u : f(par[u]); } i...
#include <bits/stdc++.h> using namespace std; int main() { int n; scanf( %d , &n); for (int i = 1, j = n; i <= n / 2; ++i, --j) printf( %d %d , i, j); if (n % 2 == 1) printf( %d , n / 2 + 1); return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int a, b; cin >> a >> b; if (a == b) cout << a << 0 << << b << 1 << endl; else if (a + 1 == b) { cout << a << 9 << << b << 0 << endl; } else if (a == 9 && b == 1) { cout << 9 10 << endl; } else { cou...
#include <bits/stdc++.h> using namespace std; const int maxn = 100123; const int lgn = 20; long long a[maxn], f[maxn][lgn], ans; vector<int> G[maxn]; void dfs(int u, int p, int x) { int w = a[u] >> x & 1; f[u][w] = 1, f[u][w ^ 1] = 0; for (auto& v : G[u]) { if (v != p) { dfs(v, u, ...
#include <bits/stdc++.h> using namespace std; int ans; char s[100]; int main() { cin >> s; for (int i = 0; i < strlen(s); i++) if (s[i] == a || s[i] == e || s[i] == i || s[i] == o || s[i] == u || s[i] == 1 || s[i] == 3 || s[i] == 5 || s[i] == 7 || s[i] == 9 )...
#include <bits/stdc++.h> using namespace std; int main() { int test, i, k, j, sum1, sum, n, p; cin >> test; for (i = 0; i < test; i++) { cin >> n >> k; sum = 0; sum1 = 0; vector<int> v1, v2; for (j = 0; j < n; j++) { cin >> p; v1.push_back(p); } ...
#include <bits/stdc++.h> using namespace std; int n, k; int query(int l, int r) { if (l < 1 || r > n) return false; string re; cout << 1 << << l << << r << endl; cin >> re; return re == TAK ; } int get(int l, int r) { if (l > r) return false; while (l < r) { int mid ...
#include <bits/stdc++.h> using namespace std; const double pi = acos(-1.0), eps = 1e-4; double fgcd(double a, double b) { return fabs(a) < eps ? b : (fabs(b) < eps ? a : fgcd(b, fmod(a, b))); } int main() { double a, b, c, d, e, f; cin >> a >> b >> c >> d >> e >> f; c -= a; e -= a; d -...
#include <bits/stdc++.h> using namespace std; struct Q { int l; int r; int num; Q(int _l, int _r, int _num) : l(_l), r(_r), num(_num) {} }; int cnt[100100]; int res[100100]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n, m; cin >> n >> m; vector<int> a(n); ...
#include <bits/stdc++.h> using namespace std; const int MAXN = 105000; const int INF = 2100000000; struct target { int mi_n[2], ma_x[2], z, n; }; struct point { int min, n, dot, d[2], fa, l, r; }; int n, m, root, now, txl, txr, tyl, tyr, ans[MAXN] = {0}; target rec[MAXN]; point t[MAXN]; vo...
#include <bits/stdc++.h> using namespace std; int n, m, q, ans; map<int, int> boss[100010]; map<pair<int, int>, int> mp; vector<pair<int, int> > vt[100010]; int findf(int x, int col) { if (!boss[col].count(x) || x == boss[col][x]) { boss[col][x] = x; return x; } return boss[col][x] =...
#include <bits/stdc++.h> using namespace std; using ll = long long; template <typename T> using PQ = priority_queue<T>; template <typename T> using GPQ = priority_queue<T, vector<T>, greater<T>>; template <class L, class R> ostream& operator<<(ostream& os, pair<L, R> p); template <class T> ostream& ...
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; int n = s.length(); vector<vector<int> > pos( z - a + 1); for (int i = 0; i < n; i++) pos[s[i] - a ].push_back(i); int good = 0; for (int c = 0; c <= z - a ; c++) { if (pos[c].empty()) continue; ...
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; const double PI = acos(-1.0); const int MAXN = 2e5 + 5; long long int freq[MAXN]; long long int pref_sum(int l, int r) { return (l ? freq[r] - freq[l - 1] : freq[r]); } void cp() { int n; long long int k; cin >> n >> ...
#include <bits/stdc++.h> using namespace std; const int MAX = 35005; struct segtree { segtree *left, *right; int start, end, v, m; int lazy; segtree(int start, int end) : start(start), end(end), v(0), lazy(0) { if (start == end) { left = right = NULL; } else { m = (star...
#include <cstdio> #include <cstring> #include <algorithm> #define rep(a,b,c) for(int a=b;a<=c;a++) #define per(a,b,c) for(int a=b;a>=c;a--) #define int long long const int inf=0x3f3f3f3f; template<class T>inline void read(T &x) { T f=1;x=0;char s=getchar(); while(s< 0 ||s> 9 ){if(s== - )f=-1;s=getch...
#include <bits/stdc++.h> using namespace std; int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long int t, a, b, diff, n; cin >> t; while (t--) { cin >> a >> b; diff = abs(a - b); n = ceil((-1 + sqrt(1 + 8 * diff)) / 2); if (((n + 1) / 2) % 2 != diff...
#include <bits/stdc++.h> using namespace std; int n, Q; string s[100005]; int L[100005], R[100005], K[100005]; long long ans[100005]; vector<int> in[100005], ot[100005], G[100005 << 1]; long long sm[100005]; int last, fa[100005 << 1], tr[100005 << 1][26], len[100005 << 1], tot, f[100005 << 1], sa[...
#include <bits/stdc++.h> template <typename T, typename U> static inline void amin(T &x, U y) { if (y < x) x = y; } template <typename T, typename U> static inline void amax(T &x, U y) { if (x < y) x = y; } using namespace std; const int N = 2e5 + 5; int par[N], r[N]; int find(int a) { i...
#include <bits/stdc++.h> struct Solution { int n, k; std::vector<std::vector<int>> as; std::vector<int> pows; int64_t calcPair(int ind1, int ind2) { std::vector<int> left; left.reserve(as[ind1].size()); for (int v : as[ind1]) { left.push_back((int64_t(k - v) * pows[ind2 + 1])...
#include <bits/stdc++.h> using namespace std; int pai[1000010]; int find(int x) { if (pai[x] == x) return x; return pai[x] = find(pai[x]); } void join(int a, int b) { pai[find(a)] = find(b); } int main() { int n, m, q; cin >> n >> m >> q; for (int i = 1; i <= n + m; i++) pai[i] = i; ...
#include <bits/stdc++.h> using namespace std; void solve() { long long n; long long k; cin >> n; cin >> k; vector<long long> d(n); vector<long long> afterd(n); for (long long i = 0; i < n; i++) cin >> d[i]; for (long long i = 0; i < n; i++) cin >> afterd[i]; vector<pair<long long...
#include <bits/stdc++.h> using namespace std; const int N = 10005; const int P = 998244353; struct edge { int u, v, len; inline edge() {} inline edge(int _u, int _v, int _len) { u = _u; v = _v; len = _len; } } a[N], Q[N], res[N]; struct node { int l, r; vector<int> ...
#include <bits/stdc++.h> using namespace std; const long long MOD = 1e9 + 9; const long long INF = 1e18; const int MAXN = 1e6 + 10; const int MAXM = 1e4 + 500; const int N = 2000 + 15; const double EPS = 1e-9; int dx[] = {1, 0, 0, -1}; int dy[] = {0, 1, -1, 0}; double len(complex<long long> a) { ...
#include <bits/stdc++.h> using namespace std; int n, k; int p[55]; string t; void getp() { int j = 0; p[0] = p[1] = 0; for (int i = 1; i < t.length(); ++i) { while (j && t[j] != t[i]) j = p[j]; if (t[j] == t[i]) j++; p[i + 1] = j; } } void build() { getp(); string...
#include <bits/stdc++.h> using namespace std; int n, u, r; vector<long long> k; vector<int> a, b, p, tmp; vector<vector<int> > v; vector<int> w; void read(); int main() { ios_base::sync_with_stdio(false); read(); v.push_back(a); w.push_back(1); long long s = 0; if (u & 1) s...
#include <bits/stdc++.h> using namespace std; const int maxN = 2005; int d[maxN][maxN], c[maxN][maxN], D[maxN], C[maxN], dx[maxN][maxN], cx[maxN][maxN]; int main() { ios::sync_with_stdio(0); cin.tie(0); int n, k; cin >> n >> k; char cur; for (int i = 1; i <= n; ++i) for (int ...
#include <bits/stdc++.h> using namespace std; int n, a[500010], x, sz; long long ans; int main() { scanf( %d , &n); for (int step = 1; step <= n; step++) { scanf( %d , &x); while (a[sz - 1] > a[sz] && a[sz] <= x && sz >= 2) { ans += min(a[sz - 1], x); sz--; } a[++...
#include <bits/stdc++.h> using namespace std; int n; vector<int> v; vector<int> ans_lis; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); cin >> n; for (int i = 1; i <= n; i++) { int x; cin >> x; v.emplace_back(x); } sort(v.begin(), v...
#include <bits/stdc++.h> using namespace std; const int N = 100010; const int M = 4; int now[2], dila[2]; int vis[N][4], n, m, cnt, ans_cnt; char s[4]; long long ans; int main() { int i, j, k, *p; bool lose = false; scanf( %d%d%d%d%s , &n, &m, &now[0], &now[1], s); if (s[0] == U ) ...
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 5; long long mx, mi; int t, head[N], len, k, vis[N]; struct edge { int v, w, next; } e[N * 2]; void add(int u, int v, int w) { e[len].v = v; e[len].w = w; e[len].next = head[u]; head[u] = len++; } void dfs(int u, int...
#include <bits/stdc++.h> using namespace std; int n, cnt = 0; long long sum = 0; bool flag = false; struct Node { int num; int pos; } a[200005]; bool cmp(const Node &a, const Node &b) { return a.num < b.num; } vector<int> v; int main() { cin >> n; for (int i = 1; i <= n; i++) { c...
#include <bits/stdc++.h> using namespace std; string itosm(long long x) { if (x == 0) return 0 ; string ans = ; while (x > 0) { ans += ((x % 10) + 0 ); x /= 10; } reverse(ans.begin(), ans.end()); return ans; } long long stoim(string str) { long long ans = 0; long ...
#include <bits/stdc++.h> using namespace std; string s; string name, host, sour; int main() { ios::sync_with_stdio(false); cin >> s; int i = 0; while (i < s.size() && s[i] != @ ) { name.push_back(s[i]); i++; } i++; while (i < s.size() && s[i] != / ) { host.push_ba...
#include <bits/stdc++.h> using namespace std; int min(int a, int b) { if (a < b) return a; else return b; } int main() { int n, len, a[100010], f[100010], dai, max = 0, vitri = 0; char s[100010]; char si[13][13]; bool kt; scanf( %s , s); len = strlen(s); for (int ...
#include <bits/stdc++.h> using namespace std; template <class T> void chmax(T &x, T y) { x = x > y ? x : y; } template <class T> void chmin(T &x, T y) { x = x < y ? x : y; } const int maxn = 205; int n, k; int d[maxn], ans[maxn], choice[maxn]; int dp[maxn][maxn]; int dist[maxn][maxn]; ...
#include <bits/stdc++.h> using namespace std; int n, x, y; int a, b; int diff; void ask(int mask) { int sz = 0; for (int i = 0; i < n; ++i) { if ((i & mask) > 0) { ++sz; } } if (sz == 0) { return; } printf( ? %d , sz); for (int i = 0; i < n; ++i) { i...
#include <bits/stdc++.h> using namespace std; const int inf = ~0U >> 1; const long long INF = (long long)1e18; const double pi = acos(-1.0); template <class T> inline T sqr(T a) { return a * a; } template <class T> inline T min(T a, T b, T c) { return min(min(a, b), c); } template <class T...
#include <bits/stdc++.h> using namespace std; int x, y; long long s; int main() { cin >> x >> y >> s; if (abs(x) + abs(y) <= s && (s - (abs(x) + abs(y))) % 2 == 0) cout << Yes ; else cout << No ; return 0; }
#include <bits/stdc++.h> using namespace std; int t, n; string str; int main() { cin >> t; while (t--) { cin >> n >> str; int x = n, res = n; for (int i = 0; i < n; i++) if (str[i] == 1 ) { res = max(res, max(n + 1, 2 * max(i + 1, n - i))); } cout << re...
#include <bits/stdc++.h> using namespace std; int n, m; string grid[105]; int check_bomb(int i, int j) { if ((i > 0 && grid[i - 1][j] == * ) || (i < n - 1 && grid[i + 1][j] == * ) || (j > 0 && grid[i][j - 1] == * ) || (j < m - 1 && grid[i][j + 1] == * ) || (i > 0 && j > 0...
#include <bits/stdc++.h> using namespace std; int n; long long a, b, T; char s[500010]; long long pref[500010]; long long suff[500010]; int main() { cin >> n >> a >> b >> T; for (int i = 1; i <= n; ++i) { cin >> s[i]; } pref[1] = 0; for (int i = 2; i <= n; ++i) { pref[i] = ...
#include <bits/stdc++.h> using namespace std; const int N = 60; const int M = 40010; const int OFF = 20005; int n, m; int lt[N], rt[N]; set<int> cnt; bitset<N> ll[M], rr[M]; int main() { cin >> n >> m; for (int i = 0; i < n; i++) { cin >> lt[i]; } for (int i = 0; i < m; i++) { ...
#include <bits/stdc++.h> using namespace std; const int inf = 1e9 + 5; const long long linf = 1e18 + 5; class point { public: int x, y; double m; point() {} point(int x, int y) { this->x = x; this->y = y; this->m = atan2(y, x); } bool operator<(point other) const { r...
#include <bits/stdc++.h> using namespace std; int a[2010]; long long C[2010][2010]; long long A[2010]; bool use[2010]; int n, m, N; void init() { memset(use, 0, sizeof(use)); C[0][0] = 1; for (int i = 1; i <= 2000; ++i) C[i][0] = 1; for (int i = 1; i <= 2000; ++i) for (int j = 1; j <...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); long long n, m, ta, tb, k, res = 0; cin >> n >> m >> ta >> tb >> k; if (k >= n || k >= m) { cout << -1; return 0; } vector<long long> a(n), b(m); for (int i = 0; i < n; i+...
#include <bits/stdc++.h> using namespace std; long long n, k; int arr[400009]; map<int, int> mp; vector<int> v; int sum[400009]; int main() { cin >> n >> k; for (int i = 0; i < n; i++) { scanf( %d , &arr[i]); if (mp[arr[i]] == 0) { v.push_back(arr[i]); } mp[arr[i]]+...
#include <bits/stdc++.h> using namespace std; int main() { int tt = 120; int test[6] = {0, 1, 3, 5, 2, 4}; int n = 5; int p[2001], s[2001]; int p_l[2001], s_l[2001]; int ans = 0; vector<pair<int, int> > v_ans; scanf( %d , &n); for (int i = 1; i <= n; i++) { scanf( %d , &p[i...
#include <bits/stdc++.h> using namespace std; int H, M, K; int NonZeroDigit(int x) { int res = 0; while (x) { if (x % 10) res++; x /= 10; } return res; } int Get(int x, int p) { for (int i = 1; i < p; ++i) x /= 10; return x; } long long Solve(int h, int m) { int d =...
#include <bits/stdc++.h> using namespace std; int a1, a2, a3, a4; int head; int b, c; int nott(int x) { if (x == 4) return 7; return 4; } int main() { cin >> a1 >> a2 >> a3 >> a4; if (abs(a3 - a4) > 1) { cout << -1 << endl; return 0; } if (a3 > a4) head = 4; if (a4 ...
#include <bits/stdc++.h> using namespace std; string st, t; vector<string> a; int p; int main() { ios_base ::sync_with_stdio(false); cin >> st; for (auto i : st) { t += i; if (i == > ) { a.push_back(t); t = ; } } for (auto i : a) { if (i[1] == / ...
#include <bits/stdc++.h> using namespace std; int a[110][110], row[110], col[110], ansrow[110], anscol[110], n, m, tans, ans; bool flag; int main() { scanf( %d%d , &n, &m); for (int i = 1; i <= n; i++) for (int j = 1; j <= m; j++) scanf( %d , &a[i][j]); ans = 10000000; for (int i = 0; i <=...
#include <bits/stdc++.h> using namespace std; int a[1000050]; vector<int> vec[1000050]; int pos[1000050]; int main() { int n, x; scanf( %d%d , &n, &x); for (int i = 0; i < n; i++) { scanf( %d , a + i); vec[a[i]].push_back(i); } pos[x + 1] = n; int st = 1; for (int i = x...
#include <bits/stdc++.h> using namespace std; void solve() { int n, k; cin >> n >> k; priority_queue<pair<int, int> > p; set<int> s; for (int i = 1; i <= n; i++) { int in; cin >> in; p.push({in, i}); s.insert(i + k); } long long ans = 0; vector<int> v(n); ...
#include <bits/stdc++.h> using namespace std; string arf[1005], ars[1005]; string ans[1005]; void solve() { int n; cin >> n; map<string, vector<int> > f, s; int done[n]; memset(done, 0, sizeof(done)); ; for (int i = 0; i < (int)(n); i++) { string s1, s2; cin >> s1 >> s2; ...