func_code_string
stringlengths
59
71.4k
#include <bits/stdc++.h> using namespace std; const static int inf = 10000000; const static int mod = 1000000007; int check(const vector<string>& s, const vector<string>& t) { int n = s.size(); vector<int> idx(n); for (int i = 0; i < (int)(n); i++) { idx[i] = i; } int ret = 0; do {...
#include <bits/stdc++.h> using namespace std; int n, k; bool ask(int x, int y) { if (x < 0 || y > n) return 0; string s; cout << 1 << << x << << y << endl; cin >> s; return s == TAK ; } int solve(int l, int r) { if (l > r) return -1; int mid; while (l < r) { mid ...
#include <bits/stdc++.h> using namespace std; const int MAXN = 200200; const int INF = 1000000007; struct Ramp { int i, x, d, t, p; bool operator<(int o) const { return x < o; } bool operator<(const Ramp& o) const { return x < o.x; } } r[MAXN], rr; struct Edge { int a, b, c, t; Edge(int ...
#include <bits/stdc++.h> using namespace std; set<string> st; set<string>::iterator it; vector<long long> v, vv; int main() { int n, a[100000], cnt = 0, cnt2 = 0, k; cin >> n; for (int i = 0; i < n; i++) { cin >> a[i]; if (a[i] > 0) cnt++; else if (a[i] < 0) cnt2+...
#include <bits/stdc++.h> using namespace std; int a[12][12]; int main() { int n; scanf( %d , &n); for (int i = 1; i <= n; i++) for (int j = 1; j <= n; j++) scanf( %d , &a[i][j]); for (int k = 1; k <= n; k++) { for (int i = 1; i <= n; i++) { for (int j = 1; j <= n; j++) { ...
#include <bits/stdc++.h> using namespace std; int64_t ans; int n, m, ve, ts[1000001], nn[1000001], t, cut[1000001], p[1000001], vis[1000001], low[1000001]; vector<int> e[1000001]; void dfs(int i) { low[i] = ts[i] = ++t; vis[i] = 1; for (auto&& x : e[i]) if (!vis[x]) { p[x] = i;...
#include <bits/stdc++.h> using namespace std; void solve() { int n, l; cin >> n >> l; vector<int> flags(n + 2); flags[0] = 0, flags[n + 1] = l; for (int i = 0; i < n; ++i) { cin >> flags[i + 1]; } vector<double> s(n + 2); vector<double> e(n + 2); s[0] = 0; e[n + 1] = 0;...
#include <bits/stdc++.h> using namespace std; const int MOD = 1000000007; struct Sync_stdio { Sync_stdio() { cin.tie(NULL); ios_base::sync_with_stdio(false); } } _sync_stdio; int main() { int n, m, k; cin >> n >> m >> k; vector<vector<vector<int>>> v(n + 2, ...
#include <bits/stdc++.h> using namespace std; string str; int ss; int par[10001]; int ans[2][10001]; int root(int x) { if (par[x] != x) par[x] = root(par[x]); return par[x]; } map<string, int> m; int main() { while (getline(cin, str)) { char ty = str[0]; int k = 2; int z ...
#include <bits/stdc++.h> using namespace std; const unsigned long long maxn = 2e6 + 10; int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); string v; cin >> v; for (long i = 0; i < v.size(); i++) { if (v[i] != 1 && v[i] != 4 ) { cout << NO << endl; retu...
#include <bits/stdc++.h> using namespace std; const int MAXN = 100100; int n, m; int was[MAXN]; vector<int> g[MAXN]; bool was2[3][MAXN]; bool dfs(int v, int col = 1) { was[v] = col; for (int i = 0; i < (int)g[v].size(); ++i) { if (!was[g[v][i]]) { if (dfs(g[v][i], 3 - col)) { ...
#include <bits/stdc++.h> using namespace std; int longpre(string y) { string s = y + ? ; reverse(y.begin(), y.end()); s += y; int n = s.length(); int lps[n]; for (int i = 0; i < n; i++) lps[i] = 0; int i = 0; int j = 1; while (j < n) { if (s[i] == s[j]) { lps[j] = ...
#include<bits/stdc++.h> #define fort(i,a,b) for(long long i=a;i<=b;i++) #define forn(i,a,b) for(long long i=a;i>=b;i--) #define rep(i,a,b) for(long long i=a;i<b;i++) #define x first #define y second #define pb push_back #define MP make_pair using namespace std; const long long N=2e5+5; long long s...
#include <bits/stdc++.h> template <typename T> void MACRO_VAR_Scan(T& t) { std::cin >> t; } template <typename First, typename... Rest> void MACRO_VAR_Scan(First& first, Rest&... rest) { std::cin >> first; MACRO_VAR_Scan(rest...); } template <typename T> void MACRO_VEC_ROW_Init(int n, T& t) ...
#include <bits/stdc++.h> using namespace std; long long int power(long long int a, long long int b) { if (b == 0) return 1; if (b == 1) return a; long long int r = power(a, b / 2) % 1000000007; if (b % 2 == 0) return (r * r) % 1000000007; else return (((r * r) % 1000000007) * a) % 10...
#include <bits/stdc++.h> using namespace std; const int inf = 0x3f3f3f3f; int main() { ios::sync_with_stdio(false); cin.tie(NULL); int Q; cin >> Q; while (Q-- > 0) { int n; cin >> n; vector<int> dp(2001, inf); dp[0] = 0; for (int i = 0; i < n; ++i) { int a...
#include <bits/stdc++.h> using namespace std; int n; long long x[100007], y[100007], xx, yy, m, p, q; long long ans; int get(int p, int q) { while ((x[q] - x[p]) * (yy - y[p]) - (y[q] - y[p]) * (xx - x[p]) <= 0) q = q % n + 1; q = (q + n - 2) % n + 1; return q; } int main() { cin >> ...
#include <bits/stdc++.h> using namespace std; const int MaxN = 100010, Block = 500, TB = 300; struct query { int l, r, id; bool operator<(const query &a) const { if (l / TB != a.l / TB) return l / TB < a.l / TB; return r < a.r; } } q[MaxN]; long long ans[MaxN]; int cnt[MaxN], num[Max...
#include <bits/stdc++.h> using namespace std; int n, size[55]; double f[55][55], fac[55]; int cnt, head[55], to[110], nxt[110]; void add(int x, int y) { cnt++; to[cnt] = y; nxt[cnt] = head[x]; head[x] = cnt; } double c(int n, int m) { if (m < 0 || m > n) { return 0.0; } else ...
#include <bits/stdc++.h> using namespace std; const long long MOD = 1e9 + 7; const int SIZE = 1e6 + 5; const long long INF = 1LL << 58; const double eps = 1e-10; char d[2009][2009]; char a[2009][2009]; int dy[4] = {-1, 0, 1, 0}; int dx[4] = {0, 1, 0, -1}; int dy2[8] = {-2, -1, 0, 1, 2, 1, 0, -1}; ...
#include <bits/stdc++.h> using namespace std; vector<pair<int, int> > hop, top; int h, t, R; struct State { int h, t; int c; State() {} State(int h, int t, int c) : h(h), t(t), c(c) {} bool operator<(const State o) const { if (h != o.h) return h < o.h; return t < o.t; } }; ...
#include <bits/stdc++.h> using namespace std; int N; int K[1010]; pair<int, int> nex[1010][2520]; int P, Q; int num[1010][2520]; int vis[1010][2520]; class SCC { public: static const int MV = 1010 * 2520; vector<vector<int> > SC; int NV, GR[MV]; private: vector<int> E[MV], RE[MV...
#include <bits/stdc++.h> using namespace std; const long long mod = 998244353; void ingraph(vector<long long> graph[], long long m) { long long x, y; for (long long i = 0; i < m; i++) { cin >> x >> y; x--, y--; graph[x].push_back(y); graph[y].push_back(x); } } long long gcd...
#include <bits/stdc++.h> using namespace std; int main() { long long int t; cin >> t; while (t--) { string s; cin >> s; int n = s.length(); if (n < 3) { cout << 0 << endl; continue; } if (n == 3) { if (s == 101 || s == 010 ) cout <...
#include <bits/stdc++.h> using namespace std; int n, neg = 0; char s[1009]; int main() { vector<int> ans; scanf( %[^=]=%d , s, &n); ans.push_back(n); for (int i = 1; s[i]; i++) { if (s[i] == ) continue; if (s[i] == - ) neg = 1; else if (s[i] == + ) neg = 0;...
#include <bits/stdc++.h> using namespace std; int gcd(int x, int y) { if (y == 0) return x; return gcd(y, x % y); } int main() { int n; cin >> n; int ansx = 0, ansy = 0; for (int i = 1; i < n; i++) { int j = n - i; if (j <= i) break; if (gcd(i, j) != 1) continue; ...
#include <bits/stdc++.h> using namespace std; const int inf = 0x3f3f3f3f, N = 1005, MOD = 100000007; const double eps = 1e-6; int a[15], m, ans[N], ct; char b; int main() { ct = 0; for (int i = 1; i <= 10; i++) { scanf( %c , &b); if (b == 1 ) { a[ct++] = i; } } sca...
#include <bits/stdc++.h> using namespace std; const long long INF = 1e17; long long n, k, niv[200005]; vector<long long> muchii[200005]; bool isleaf[200005], used[200005]; long long red, blue, par[200005]; vector<long long> line; long long timp, in[200005], out[200005]; struct date { long long min...
#include <bits/stdc++.h> using namespace std; int g[65]{0, 1, 1, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 10}; const int MAXN = 1000007; int s[...
#include <bits/stdc++.h> using namespace std; void cline() { cout << n ; } template <typename T, typename... V> void cline(T t, V... v) { cout << t; if (sizeof...(v)) cout << ; cline(v...); } void cspc() { cout << ; } template <typename T, typename... V> void cspc(T t, V... v) { ...
#include <bits/stdc++.h> using namespace std; const int N = 1e3 + 3; int n, m, dp[N], vis[2][N]; vector<int> adj[2][N]; vector<pair<int, int>> e; void dfs(int u, int dir) { vis[dir][u] = 1; for (int v : adj[dir][u]) if (!vis[dir][v]) dfs(v, dir); } int main() { ios_base::sync_with_stdi...
#include <bits/stdc++.h> using namespace std; const long long maxn = 1e6 + 10; long long a[maxn], b[maxn], ans[maxn]; int32_t main() { long long n; cin >> n; for (long long i = 0; i < n; i++) { cin >> a[i]; b[i] = a[i]; } sort(b, b + n); if (b[0] == b[n - 1]) { if (b[0]...
#include <bits/stdc++.h> using namespace std; const int N = 105; long long l, r, dp[N]; long long gao(long long n) { long long m = n, ans = 0; int bit[N], len = 0; while (n) { bit[++len] = n % 2; n /= 2; } for (int i = 2; i < len; i++) { memset(dp, 0, sizeof(dp)); dp[...
#include <bits/stdc++.h> int setBit(int N, int pos) { return N = N | (1 << pos); } int resetBit(int N, int pos) { return N = N & ~(1 << pos); } bool checkBit(int N, int pos) { return (bool)(N & (1 << pos)); } using namespace std; const int maxn = 100000; int n, m, cost[maxn + 5], okayRoad[maxn + 5], par[max...
#include <bits/stdc++.h> using namespace std; int a[301][301], h, w, dp[301][301]; int used[601][601]; int dx[] = {0, 1, -1, 0, 0, 1, -1, 1, -1}; int dy[] = {0, 0, 0, 1, -1, 1, 1, -1, -1}; int read() { int x; scanf( %d , &x); return x; } bool check(int x, int y) { if (x >= 1 && x <= h &&...
#include <bits/stdc++.h> using namespace std; const int N = 22e4; char s[N * 2]; int l[N * 2], r[N * 2]; int main() { ios::sync_with_stdio(0); int n, k; cin >> n >> k >> s; for (int i = 0; i < n; i++) s[i + n] = s[i]; for (int i = 0, lx = -2e9; i < n * 2; i++) { if (s[i] == s[i + 1])...
#include <bits/stdc++.h> using namespace std; const double PI = 2.0 * acos(0.0); const double E = exp(1); template <class T1> void deb(T1 e) { cout << e << endl; } template <class T1, class T2> void deb(T1 e1, T2 e2) { cout << e1 << << e2 << endl; } template <class T1, class T2, class T3...
#include <bits/stdc++.h> using namespace std; int main() { long long int p, d; cin >> p >> d; long long int temp = 1; long long int po[19]; for (int i = 0; i <= 18; ++i) { po[i] = temp; temp *= 10; } int i = 1; temp = p; while (1) { long long int t = temp % po[i...
#include <bits/stdc++.h> using namespace std; int n, a[5005], dp[5005], b[5005]; int main() { scanf( %d , &n); for (int i = 1; i <= n; i++) scanf( %d , &a[i]); dp[0] = 0; for (int i = 1; i <= n; i++) { int p = i, s = a[i]; while (p > 0 && s < b[p - 1]) { s += a[p - 1]; ...
#include <bits/stdc++.h> using namespace std; const int inf = 0x3f3f3f3f; const int maxn = 1e5 + 5; vector<int> a[maxn]; int res[maxn]; int main() { int n, m; scanf( %d%d , &n, &m); for (int i = 0; i < n; i++) { int q, w; scanf( %d%d , &q, &w); a[q].push_back(w); } int ...
#include <bits/stdc++.h> using namespace std; long long s(long long x) { long long sum = 0; while (x) { sum += x % 10; x /= 10; } return sum; } int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long T; T = 1; while (T--) { ...
#include <bits/stdc++.h> using namespace std; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); const int N = 4000; const int INF = 1e9; struct edge { int to, c, f, back; edge(int to, int c, int f, int back) : to(to), c(c), f(f), back(back) {} }; vector<edge> g[N]; vector<int>...
#include <bits/stdc++.h> using namespace std; string A[18][18], s; int n, m, U[101], us, J[3][3]; bool B[1001]; int r1, c1, r2, c2, size; int tonum(char ch) { if (ch == C ) return 1; if (ch == D ) return 2; if (ch == H ) return 3; if (ch == S ) return 4; if (ch == T ) return 8; ...
#include <bits/stdc++.h> using namespace std; int main() { int t, n; int x; cin >> t; while (t--) { cin >> n; map<int, int> m; for (int i = 0; i < n; i++) { cin >> x; m[x] = 1; } cout << m.size() << endl; } }
#include <bits/stdc++.h> int comp(const void *a, const void *b) { return *(int *)a - *(int *)b; } int min(int a, int b) { return a < b ? a : b; } int max(int a, int b) { return a > b ? a : b; } int rev(int n) { int r = 0; for (int i = 0; i < 8; i++) r = r | (((n >> i) & 1) << (7 - i)); return r; }...
#include <bits/stdc++.h> using namespace std; const double EPS = 1e-9; const long long int mod = 1e9 + 7; long long int pow(long long int x, long long int y) { long long int sum = 1; for (long long int i = 0; i < y; ++i) { sum *= x; sum %= mod; } return sum; } int main(void) { ...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; long long sum1 = 0, sum2 = 0; vector<long long> one, two; int last = 0; for (int i = 0; i < n; i++) { int temp; scanf( %d , &temp); if (temp < 0) { two.push_back(abs(temp)); sum2 += ...
#include <bits/stdc++.h> using namespace std; const int MXN = 300300; int n, a[MXN], match[MXN], cnt[MXN]; map<int, int> prevMatch[MXN]; int main() { int T; scanf( %d , &T); for (int t = 1; t <= T; ++t) { scanf( %d , &n); for (int i = 1; i <= n; ++i) { scanf( %d , &a[i]); ...
#include <bits/stdc++.h> using namespace std; long long mod = 998244353; long long power(long long x, long long y) { long long z = 1; while (y > 0) { if (y % 2) z = z * x; x = x * x; y /= 2; } return z; } long long gcd(long long a, long long b) { if (a < b) return gcd(b, ...
#include <bits/stdc++.h> inline int lb(int a) { return a & (-a); } long long a[100100], bit[7][15][100100]; int n, m, t; inline void adj(int z, int zm, int pos, long long val) { for (int i = pos; i <= n; i += lb(i)) bit[z][zm][i] += val; } inline long long qry(int z, int zm, int pos) { if (pos <= 0)...
#include <bits/stdc++.h> using namespace std; const long long mod = 1000000007; const long long MAX = 1e6 + 5; bool cmp(const pair<long long, long long> &a, const pair<long long, long long> &b) { if (a.first < b.first) return true; else if (a.first == b.first) { if (b.second > a.s...
#include <bits/stdc++.h> int n, fa[200005][2], sz[200005][2]; long long ans; int find(int x, int c) { return fa[x][c] == x ? x : (fa[x][c] = find(fa[x][c], c)); } void merge(int x, int y, int c) { x = find(x, c), y = find(y, c); if (x == y) return; fa[y][c] = fa[x][c], sz[x][c] += sz[y][c]; ...
#include <bits/stdc++.h> using namespace std; double dot(complex<double> a, complex<double> b) { return (conj(a) * b).real(); } double cross(complex<double> a, complex<double> b) { return (conj(a) * b).imag(); } int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); long doub...
#include <bits/stdc++.h> using namespace std; const signed long long Infinity = 1000000001; const long double Epsilon = 1e-9; template <typename T, typename U> ostream& operator<<(ostream& os, const pair<T, U>& p) { return os << ( << p.first << , << p.second << ) ; } template <typename T> ostre...
#include <bits/stdc++.h> using namespace std; int N; char S[500050]; int Aint[4 * 500050]; int pa, pb, pv; long long A[500050]; void update(int k, int st, int dr) { if (pa <= st && dr <= pb) { Aint[k] += pv; return; } int m = (st + dr) / 2; if (pa <= m) { update(2 * k, st...
#include <bits/stdc++.h> using namespace std; const int maxn = 300009; map<short, int> f[maxn]; int a[maxn], n, K, p, q, d; int sum[maxn], i, j, k; int main() { scanf( %d%d , &n, &K); d = n / K; for (i = 1; i <= n; i++) scanf( %d , &a[i]); sort(a + 1, a + n + 1); for (i = 2; i <= n; i++)...
#include <bits/stdc++.h> using namespace std; long long abs(long long, long long); double dis(long long x1, long long y1, long long x2, long long y2) { double d = (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2); d = sqrt(d * 1.0); return d; } void solve() { long long w, h; cin >> w >> h; ...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long n, x, t, m, y, z, k; cin >> t; while (t--) { cin >> n >> m; vector<vector<long long> > a(n, vector<long long>(m)); string s; for (int i = 0; i < n; i++) {...
#include <bits/stdc++.h> int main() { long long n, d, m, l, i, le, ri, step; while (~scanf( %I64d%I64d%I64d%I64d , &n, &d, &m, &l)) { for (i = 0; i < n; i++) { le = i * m + l; ri = (i + 1) * m; step = (le + d) / d; if (step * d < ri) break; } printf( %I64d n ,...
#include <bits/stdc++.h> using namespace std; int n, x[1000009], y[1000009], id[1000009]; int main() { scanf( %d , &n); for (int i = 1; i <= n; i++) scanf( %d %d , x + i, y + i), id[i] = i; sort(id + 1, id + 1 + n, [](int a, int b) { if (x[a] / 1000 != x[b] / 1000) return x[a] / 1000 < x[b] / 10...
#include <bits/stdc++.h> using namespace std; int q, n; long long k; long long len[100004]; string s1 = What are you doing while sending , s2 = ? Are you busy? Will you send , s3 = ? , f0 = What are you doing at the end of the world? Are you busy? Will you ...
#include <bits/stdc++.h> using uint64 = unsigned long long; const int N = 100, seed = 65537; char s[N]; std::unordered_map<uint64, int> words; std::unordered_set<uint64> mark; int dfs(int d, uint64 hs) { if (s[d] == 0) { if (mark.count(hs)) return 0; mark.insert(hs); auto it = words.fi...
#include <bits/stdc++.h> using namespace std; int dq[4040]; int st = 0; int dr = 0; int m[3030][3030]; int mn[3030][3030]; int N, M, K, L, X, Y, Z; long long ret = 0; void make() { for (int i = 1; i <= N; ++i) { int ind = 0; st = dr = 0; for (int j = 1; j <= M; ++j) { whi...
#include <bits/stdc++.h> const double pi = acos(-1); const int MOD = 1e9 + 7; const int INF = 1e9 + 7; const int MAXN = 1e6 + 5; const double eps = 1e-9; using namespace std; int main() { for (int i = 0; i < 9; i++) printf( %d ? ?<>%d n , i, i + 1); printf( 9 ? ?>> ? ?0 n ? ?<>1 n ); for (int ...
#include <bits/stdc++.h> using namespace std; long long w, m, k; long long comp; long long getpre(long long a) { long long tmp = 1, ct = 0; while (a >= tmp) tmp *= 10, ++ct; tmp /= 10; long long t = 1; long long ans = 0; for (long long i = 1; i < ct; ++i) ans += i * 9 * t, t *= 10; a...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); ; int t; cin >> t; while (t--) { long long n, k; cin >> n >> k; long long a[n]; for (int i = 0; i < n; i++) { cin >> a[i]; } if (k...
#include <bits/stdc++.h> using namespace std; long long f[500005]; int main() { string s; cin >> s; for (int i = 1; i <= s.size(); i++) f[i] = (s[i - 1] == I || s[i - 1] == O || s[i - 1] == E || s[i - 1] == A || s[i - 1] == U || s[i - 1] == Y ); for (int i = 1; i <= ...
#include <bits/stdc++.h> using namespace std; int main() { long long n; long long t; cin >> n >> t; vector<long long> a, b; for (long long i = 0; i < n; i++) { long long x; cin >> x; x += t; a.push_back(x); } vector<int> breaks; bool poss = true; long long...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long int n; cin >> n; long long int a[n + 1]; for (long long int i = 1; i <= n; i++) { cin >> a[i]; } long long int f = 0; for (long long int i = 1; i <= n; i++)...
#include <bits/stdc++.h> using namespace std; int main() { int n, j = 0; cin >> n; vector<int> ai(n); if (n == 4) { cout << 4 << n ; cout << 3 << << 1 << << 4 << << 2 << n ; return 0; } for (int i = 1; i <= n; i += 2) { ai[j] = i; j++; } ...
#include <bits/stdc++.h> using namespace std; int main() { int n, m, k; cin >> n >> m >> k; if (m >= n && k >= n) { cout << Yes << endl; } else cout << No << endl; }
#include <bits/stdc++.h> using namespace std; int n, k, v[105], frec[105]; vector<int> ans; int main() { cin >> n >> k; for (int i = 1; i <= n; i++) cin >> v[i]; for (int i = 1; i <= n; i++) if (!frec[v[i]]) { frec[v[i]] = 1; ans.push_back(i); if (ans.size() == k) break...
#include <bits/stdc++.h> using namespace std; const long long int lg = 22; const long long int N = 2e5 + 5; const long long int INF = 1e18; const long long int mod = 1e9 + 7; const double PI = 3.14159265358979323846; template <typename T> T power(T x, T y, long long int m) { T ans = 1; while (y ...
#include <bits/stdc++.h> using namespace std; vector<set<int> > A; set<int>::iterator it; int main() { int n, m, a; cin >> n; A.resize(n); int D[101]; for (int i = 1; i <= 100; ++i) D[i] = 0; for (int i = 0; i < n; ++i) { cin >> m; for (int j = 0; j < m; ++j) { cin >>...
#include <bits/stdc++.h> int main() { int n, a[1010], temp, lamak, maxin, max, i, j; long int count; while (scanf( %d , &n) != EOF) { count = 0; for (i = 0; i < n; i++) { scanf( %d , &a[i]); } again: max = 0; for (i = 0; i < n; i++) { if (a[i] >= max) { ...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; char s[1007][1007]; for (int i = 1; i <= n; i++) { for (int j = 1; j <= n; j++) { cin >> s[i][j]; } } if (n < 3) { cout << 0 ; } else { int res = 0; for (int i = 1; i <= n; ...
#include <bits/stdc++.h> #pragma warning(disable : 4996) #pragma comment(linker, /STACK:336777216 ) using namespace std; int IT_MAX = 1 << 17; const long long MOD = 1000000009; const int INF = 0x3f3f3f3f; const long long LL_INF = 0x3f3f3f3f3f3f3f3f; const double PI = acos(-1); const double ERR = 1e-8...
#include <bits/stdc++.h> using namespace std; const int MXN = 1e5 + 1; const int MAXN = 1e3 + 1; const long long INF = 1e16; const int MOD = 65000; const int MAX = 1e2; const double EPS = 1e-9; long long n; long long a, b, c, d, e, first, g, h; int main() { ios_base::sync_with_stdio(0); stri...
#include <iostream> #include <vector> #include <algorithm> using namespace std; int main() { int testCase; cin >> testCase; while (testCase--) { vector<int> balls; int ball; cin >> ball; while (ball--) { int num; cin >> num; balls.push_back(num); } int maxNum ...
#include <bits/stdc++.h> using namespace std; const int INF = 2000000005; const long long INFLL = 1000000000000000009; const long long MOD = 1000000007; long long W[1005][1005], N, M, K; int main() { for (int i = (1); i <= (1000); i++) W[i][0] = 1; for (int j = (1); j <= (1000); j++) { long lo...
#include <bits/stdc++.h> #define int long long #pragma GCC target ( avx2 ) #pragma GCC optimization ( O3 ) #pragma GCC optimization ( unroll-loops ) /*#include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; #define ordered_set tree<int, null_type,l...
#include <bits/stdc++.h> using namespace std; const int N = 1004; int a[N]; int main() { int n; scanf( %d , &n); vector<pair<int, int> > vec; int i; for (i = 1; i <= n; i++) { scanf( %d , &a[i]); vec.push_back(make_pair(a[i], i)); } sort(vec.begin(), vec.end()); rever...
#include <bits/stdc++.h> using namespace std; int n, ms, type[5005], dp[5005]; int main() { scanf( %d %d , &n, &ms); for (int i = 1; i <= n; i++) { double x; scanf( %d %lf , type + i, &x); } for (int i = 1; i <= n; i++) { int j = type[i]; for (int k = j; k >= 1; k--) { ...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; char s[105]; cin >> s; vector<int> a; string ans = ; int j, ct = 0; for (int i = 0; i <= n - 1;) { if (s[i] == o && s[i + 1] == g && s[i + 2] == o && i <= n - 3) { ct = 0; for (j...
#include <bits/stdc++.h> using namespace std; int const N = 1e5 + 13; int n, m; set<int> e[N]; set<pair<int, int> > q; int p[N]; int tin[N], cnt, w[N], ans; int gcd(int a, int b) { return (!a ? b : gcd(b % a, a)); } void init() { for (int i = 0; i < N; ++i) p[i] = i; } int find(int u) { if...
#include <bits/stdc++.h> using namespace std; int sum(int a[], int size) { int sum = 0; for (int i = 0; i < size; i++) { sum = sum + a[i]; } return sum; } int main() { int n; cin >> n; int a1[n], a2[n - 1], a3[n - 3]; for (int i = 0; i < n; i++) { cin >> a1[i]; } ...
#include <bits/stdc++.h> using namespace std; int dir[8][2] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}, {1, 1}, {1, -1}, {-1, 1}, {-1, -1}}; int main() { int n, k, p, x, y; int cntY = 0, a[1100] = {0}, sum = 0; scanf( %d %d %d %d %d , &n, &k, &p, &x, &y); for (int i = 1; i <= k; i++) ...
#include <bits/stdc++.h> const double PI = acos(-1); const double EPS = 1e-6; const long long MOD = 998244353; const long long N = 30 + 10; template <typename T> inline T Abs(T x) { return x < 0 ? x * -1 : x; } template <typename T> inline T Max(T x, T y, T z) { return std::max(std::max(x, y),...
#include <bits/stdc++.h> using namespace std; int main() { double a, b, c; cin >> a >> b >> c; cout << (int)ceil(c * (a - b) / b); }
#include <bits/stdc++.h> inline int read() { int x = 0, w = 1; char ch = 0; while (ch < 0 || ch > 9 ) { ch = getchar(); if (ch == - ) w = -1; } while (ch <= 9 && ch >= 0 ) { x = (x << 1) + (x << 3) + ch - 0 ; ch = getchar(); } return x * w; } using names...
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; if (m == 3 && n > 4) { cout << -1 << endl; return 0; } int cnt = 0, ans = 0; for (int i = 0; i < m; i++) printf( %d %d n , i, ans += (cnt++)); if (m < n) cout << m + 100000 << << ans << ...
#include <bits/stdc++.h> const long long INF = 1e18; void swap(long long &a, long long &b) { long long temp; temp = a; a = b; b = temp; } using namespace std; void solve() { long long n, k, ans; cin >> n >> k; ans = n; for (long long i = 1; i <= sqrt(n); i++) { if (n % i ...
#include <bits/stdc++.h> using namespace std; int main() { int n, x; cin >> n >> x; int pos = 1; long long ans = 0; for (int i = 0; i < n; i++) { int l, r; cin >> l >> r; ans += 1LL * (l - pos) % x + (r - l + 1); pos = r + 1; } cout << ans << endl; return 0; ...
#include <bits/stdc++.h> using namespace std; int strike[10010]; bool isIn(long long x, long long y, long long cx, long long cr) { return (x - cx) * (x - cx) + y * y <= cr * cr; } int main() { int n, m; cin >> n; vector<pair<pair<long long, long long>, int> > mish(n + 2); for (int i = 1; i...
#include <bits/stdc++.h> using namespace std; const int inf = 2000000000; const int N = 300005; int p[N], sum[N], dp[N]; vector<int> g[N]; bool cmp(int q, int w) { return (sum[q] > sum[w]); } void dfs(int v, int pr = 0) { p[v] = pr; sum[v] = 1; if (pr && g[v].size() == 1) { dp[v] = v; ...
#include <bits/stdc++.h> using namespace std; long long mn = (long long)(1e9); long long n, ans, k, a[311111], near[2111111], x; bool mark[2111111]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> n >> k; for (int i = 1; i <= n; i++) { cin >> a[i]; mark[a[i]] = 1; ...
#include <bits/stdc++.h> using namespace std; const long long inf = 1e18; const long long mod = 1e9 + 7; unsigned long long power(long long x, unsigned long long y, long long p) { long long res = 1; x = x % p; while (y > 0) { if (y & 1) res = (res * x) % p; y = y >> 1; x = (x * x) ...
#include <bits/stdc++.h> int main() { std::ios_base::sync_with_stdio(0); std::cout.tie(0); std::cin.tie(0); int n; std::cin >> n; int a[n]; for (int i = 0; i < n; ++i) std::cin >> a[i]; std::sort(a, a + n); for (int i = n - 1; i >= 0; --i) { int t = sqrt(a[i]); if (t * ...
#include <bits/stdc++.h> typedef int arr[55][55]; char s0[55], s1[55], opr[9]; int x[55], y[55], z[55], f[55][55], n0, n1, m; bool b[55][55][55]; arr e0, e1; void work(int &n, char *s, arr &e) { n = strlen(s); memset(b, 0, sizeof(b)); for (int i = 0; i < n; i++) b[i][i + 1][s[i] - 97] = 1; f...
#include <bits/stdc++.h> using namespace std; int x, y, z, inf = 1e9, f[210][210], n, m, Max[210]; pair<pair<int, int>, int> p[40010]; pair<int, int> q[210]; void read(int &x) { char ch = getchar(); int mark = 1; for (; ch != - && (ch < 0 || ch > 9 ); ch = getchar()) ; if (ch == - ...