func_code_string
stringlengths
59
71.4k
#include <bits/stdc++.h> #pragma GCC optimize ( O3 ) #pragma GCC optimize ( Ofast ) using namespace std; #define int int64_t #define SQ(a) (a)*(a) const int INF = 1e15; int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n, m; cin >> n >> m; vector<vect...
#include <bits/stdc++.h> using namespace std; int main(int argc, const char* argv[]) { int n; cin >> n; int a[n]; int b[n]; for (int i = 0; i < n; i++) { cin >> a[i]; } for (int i = 0; i < n; i++) { cin >> b[i]; } long long mx = 0; for (int i = 0; i < n; i++) { ...
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const int mod = 1e9 + 7; const int N = 1e5 + 5; long long a[N], b[N]; long long n, h; bool cmp(int a, int b) { return a > b; } long long judge(int index) { for (int i = 0; i <= index; i++) { b[i] = a[i]; } sort(b...
#include <bits/stdc++.h> using namespace std; signed long long int a[100000 + 5], b[100000 + 5]; int n, m; signed long long int func(signed long long int x) { signed long long int ans = 0; for (int i = 1; i <= n; ++i) { if (a[i] < x) ans += x - a[i]; } for (int i = 1; i <= m; ++i) { ...
#include <bits/stdc++.h> using namespace std; int n; int a[120000]; void query(int L, int R) { int M = (L + R) / 2; printf( ? %d n , M); fflush(stdout); printf( ? %d n , n / 2 + M); fflush(stdout); scanf( %d %d , a + M, a + M + n / 2); if (a[M] == a[n / 2 + M]) { printf( ! %d n...
#include <bits/stdc++.h> using namespace std; long long readi() { long long input = 0; char c = ; while (c < - ) { c = getchar(); } bool negative = false; if (c == - ) { negative = true; c = getchar(); } while (c >= 0 ) { input = 10 * input + (c - 0 ); ...
#include <bits/stdc++.h> void mergesort(char z[], int left, int right) { char temp[1000]; if (left >= right) { return; } int mid = (left + right) / 2; mergesort(z, left, mid); mergesort(z, mid + 1, right); int lenl = mid; int lenr = right; int i = left, j = mid + 1, k = left;...
#include <bits/stdc++.h> using namespace std; int n, m; string s; vector<int> q; int mo[] = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; int h, w; int data(int x, int y) { int tmp = 0; for (int i = 0; i < x - 1; i++) tmp += mo[i]; return tmp + y; } int cal(int x, int y, int z) { retur...
#include <bits/stdc++.h> template <typename _Tp> void read(_Tp &x) { char ch(getchar()); bool f(false); while (!isdigit(ch)) f |= ch == 45, ch = getchar(); x = ch & 15, ch = getchar(); while (isdigit(ch)) x = x * 10 + (ch & 15), ch = getchar(); if (f) x = -x; } template <typename _Tp, ty...
/* Author: QAQAutoMaton Lang: C++ Code: C.cpp Mail: lk@qaq-am.com Blog: https://www.qaq-am.com/ */ #include<bits/stdc++.h> #define debug(...) fprintf(stderr,__VA_ARGS__) #define DEBUG printf( Passing [%s] in LINE %d n ,__FUNCTION__,__LINE__) #define Debug debug( Passing [%s] in LINE %d n ,__FUNCTION...
#include <bits/stdc++.h> using namespace std; int main() { int n, bx, x; long long X = 0; cin >> n >> bx; for (int i = 1; i <= n; i++) { cin >> x; X += x * pow(bx, n - i); } int m, by, y; long long Y = 0; cin >> m >> by; for (int i = 1; i <= m; i++) { cin >> y; ...
#include <bits/stdc++.h> using namespace std; int main() { long long x; cin >> x; while (x--) { string str; cin >> str; long long n, b, m, v, finl, finl2; finl2 = 0; v = 0; b = 0; m = 0; v = 0; for (n = 0; n < str.size(); n++) { finl = (int)s...
#include <bits/stdc++.h> using namespace std; int main() { int n, si, mi, t; cin >> n; for (int i = 0; i < n; i++) { cin >> t; if (t == 1) { si = i; } if (t == n) { mi = i; } } if (si < mi) { cout << max(mi, n - 1 - si); } else { cout...
#include <bits/stdc++.h> using namespace std; const int maxn = 50005; long long num[maxn]; int main() { long long sum = 0, ans = 0; int n; scanf( %d , &n); for (int i = 0; i < n; i++) cin >> num[i], sum += num[i]; if (n == 0) { cout << 0 << endl; return 0; } sum = sum /...
#include <bits/stdc++.h> using namespace std; void mohammed() { ios::sync_with_stdio(0); ios_base::sync_with_stdio(0); cin.tie(0), cout.tie(0); } int main() { mohammed(); int n, x, y; map<int, int> mp; cin >> n; for (int i = 0; i < n; i++) { cin >> x >> y; mp[x]++; ...
#include <bits/stdc++.h> using namespace std; int n, k; long long l; long long mo = 998244353; long long A[4005][4005][2]; long long B[4005]; long long a, b; long long f(long long x, long long y) { long long mid = 1; while (y) { if (y & 1) { mid = mid * x % mo; } x = x ...
#include <bits/stdc++.h> using namespace std; const int MAX_N = (int)2e5 + 7; long long dp[MAX_N]; long long num[MAX_N][2]; long long dist[MAX_N][2]; vector<int> a[MAX_N]; long long ans = 0; void go(int v, int pr = -1) { ++num[v][0]; for (int to : a[v]) { if (to == pr) continue; go(t...
#include <bits/stdc++.h> using namespace std; const int maxlongint = 2147483647; const int inf = 1000000000; int main() { int a, b, c, d, e, f, ans = 0, k = -1, n1, n2; cin >> a >> b >> c >> d >> e >> f; ans = a * b + c * d + e * f; for (n1 = 1; n1 <= 1000; n1++) if (n1 * n1 == ans) { ...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> v(n); multiset<int> list; for (int i = 0; i < n; i++) { cin >> v[i]; } for (int i = 0; i < n; i++) { int x; cin >> x; list.insert(x); } for (int i = 0; i < n; ++i) { ...
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 10; struct edge { int u, v; int adj(int x) { return u + v - x; } }; int n, c[N]; vector<int> adj[N]; vector<edge> e; int lvl[N], pre[N], root; vector<int> cycle; void dfs1(int u) { for (auto ind : adj[u]) if (ind != ...
#include <bits/stdc++.h> using namespace std; int main() { cout << setprecision(10); ios_base::sync_with_stdio(0); cin.tie(0); int n; cin >> n; for (int i = 1; i <= n; i++) { int x; cin >> x; if (x == 1) { cout << HARD n ; return 0; } } cout <...
#include <bits/stdc++.h> using namespace std; const int N = 41, K = 11; bitset<40> a[N]; vector<int> steps[K]; int n, k; bool ok = true; void go(int pos, bitset<40> is_one, bitset<40> is_question) { if (pos == k) { if (is_question != 0) { ok = false; return; } int one...
#include <bits/stdc++.h> using namespace std; int main() { long long xmax, ymax, sx, sy, i, j; cin >> xmax >> ymax >> sx >> sy; cout << sx << << sy << endl; for (i = sx - 1; i >= 1; i--) cout << i << << sy << endl; i++; for (j = sy + 1; j <= ymax; j++) cout << i << << j << endl; ...
#include <bits/stdc++.h> using namespace std; long long i, m, n, x, y; set<long long> a, b; int main() { cin >> n >> m; for (i = 0; i < m; i++) { cin >> x >> y; a.insert(x); b.insert(y); cout << (n - a.size()) * (n - b.size()) << ; } return 0; }
#include <bits/stdc++.h> using namespace std; const int INF = 1000000000; const int MAX = 1000007; int n; long long a, b; vector<int> primes(int x) { vector<int> p; for (int i = 2; i * i <= x; ++i) if (x % i == 0) { p.push_back(i); while (x % i == 0) { x /= i; ...
#include <bits/stdc++.h> using namespace std; int a[55][55]; int query(int xa, int ya, int xb, int yb) { if (xa > xb || ya > yb) swap(xa, xb), swap(ya, yb); cout << ? << xa + 1 << << ya + 1 << << xb + 1 << << yb + 1 << endl; int p; cin >> p; return p; } int h[2]; ...
#include <bits/stdc++.h> using namespace std; char a[100][40]; char b[100][40]; int at[1445], use[100], ok[100], idx[100], pos[100], sum[100], cnt; int dp[43205], ans_dd, ans_hh, ans_mm; int pt[43205][100]; void run_to(int t) { while (1) { int next_dd = ans_dd; int next_hh = ans_hh; ...
#include <bits/stdc++.h> using namespace std; const int inf = 0x3f3f3f3f; const long long INF = 2e18; const int N = 11234; int n, m; set<string> st; char s[N]; int dp[N][4]; void dfs(int pos, string pre, int len) { if (pos - 1 < 5) return; if (dp[pos][len]) return; dp[pos][len] = 1; st...
#include <bits/stdc++.h> template <class C, class E> inline bool contains(const C &container, const E &element) { return container.find(element) != container.end(); } template <class T> inline void checkmin(T &a, T b) { if (b < a) a = b; } template <class T> inline void checkmax(T &a, T b) { ...
#include <bits/stdc++.h> using namespace std; long long tc, n, m, a, b, k; string str; char c; set<long long> s; map<long long, long long> mp; int main() { int k2, k3, k5, k6, ans = 0; cin >> k2 >> k3 >> k5 >> k6; int x = min(k2, k5); x = min(x, k6); ans += 256 * x; k2 -= x; x ...
#include <bits/stdc++.h> using namespace std; string inp[100005]; int num[100005]; int tl; int ch[1200005][27]; int fail[1200005], len[1200005], elen[1200005]; long long cost[1200005]; int rt = 1, tot = 1, last = 1; void add(int x, int c, int _elen) { int p = last; int np = ++tot; len[np] ...
#include <bits/stdc++.h> using namespace std; const int dx[] = {-1, 0, 1, 0}; const int dy[] = {0, -1, 0, 1}; inline int read() { int ans = 0; bool f = 1; char ch = getchar(); while (!isdigit(ch)) f ^= ch == - , ch = getchar(); while (isdigit(ch)) ans = ((ans << 2) + ans << 1) + (ch ^ 48), ...
#include <bits/stdc++.h> using namespace std; const long long N = 2e5 + 10; int col[N], par[N], to[N]; int num = 0; void dfs(int u, int from) { if (col[u] == 2) return; if (col[u] == 1) { ++num; return; } col[u] = 1; par[u] = from; dfs(to[u], u); col[u] = 2; } int m...
#include <bits/stdc++.h> using namespace std; int main() { long long int n, k, q; long long int i, j; cin >> n >> k >> q; long long int arr[n][2]; for (i = 0; i < n; i++) { cin >> arr[i][0] >> arr[i][1]; } long long int temp[200010]; for (i = 0; i < 200001; i++) { temp[i]...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int i, j; int arr1[n], arr2[n], p[n]; for (i = 1; i <= n; i++) cin >> arr1[i]; for (i = 1; i <= n; i++) cin >> arr2[i]; for (i = 1; i <= n; i++) p[arr1[i]] = arr2[i]; for (i = 1; i <= n; i++) cout << p[i] << ...
#include <bits/stdc++.h> using namespace std; int a, b, c, Count = 1; int main() { cin >> a >> b >> c; if ((a + b > c) && (a + c > b) && (b + c > a)) { cout << 0 << endl; return 0; } while ((a + b < c) || (a + c < b) || (b + c < a)) { ++Count; if (a + b < c) { if (a...
#include <bits/stdc++.h> using namespace std; int main() { long long n, k; cin >> n >> k; long long x = __builtin_popcount(n); if (k > n || k < x) { cout << NO << endl; } else { cout << YES n ; k = k - x; long long count[30] = {0}; int i = 0; int a = n; ...
#include <bits/stdc++.h> using namespace std; void solve() { long long n; cin >> n; vector<vector<long long>> adj(n + 1, vector<long long>(n + 1, 0)); for (long long i = 1; i <= n; i++) { for (long long j = 1; j <= n; j++) { cin >> adj[i][j]; } } vector<long long> del(n +...
#include <bits/stdc++.h> using namespace std; int main() { long long a, b; cin >> a >> b; if (b - a >= 5l) printf( 0 ); else { long long p = 1l, t = b; while (t > a && t > 0) { p *= t; p %= 10; t--; } printf( %I64d , p); } }
#include <bits/stdc++.h> int n; int p[512]; int c[512][512]; int a[512]; int main() { int i, j, k; scanf( %d , &n); for (i = 1; i <= n; i++) { for (j = 1; j <= n; j++) { scanf( %d , &c[i][j]); } } for (i = 1; i <= n; i++) { scanf( %d , &p[i]); } for (i = 1...
#include <bits/stdc++.h> using namespace std; const long int m = 1000000007; int prsb(long long int n) { int pos = 0; long long int m = 1; while (!(n & m)) { m = m << 1; pos++; } return pos; } int main() { int t; cin >> t; while (t--) { long long int a, b; ...
#include <bits/stdc++.h> using namespace std; int main() { long long i, a, b, c, d, mn, mx; cin >> a >> b >> c >> d; mn = min(b, d); b -= mn; d -= mn; if (d > b) { for (i = 0; i < 1000; i++) { if (d % a == 0) { cout << d + mn; return 0; } d +...
#include <bits/stdc++.h> using namespace std; struct T { double x, y; }; T ball; double g1, g2, r, h; double ll, rr, eps = 1e-8; int main() { scanf( %lf%lf%lf%lf%lf%lf , &g1, &g2, &h, &ball.x, &ball.y, &r); ll = 0; rr = ball.x; while (rr - ll > eps) { double m = (ll + rr) / 2; ...
#include <bits/stdc++.h> using namespace std; const int NMax = 301000, MMax = 200; int N, A[NMax]; map<int, int> S; long long sum[NMax]; vector<int> R; int main() { scanf( %d , &N); for (int i = 1; i <= N; i++) { scanf( %d , A + i); S[A[i]] = max(S[A[i]], i); if (A[i] >= 0) ...
#include <bits/stdc++.h> using namespace std; inline long toInt(string s) { long v; istringstream sin(s); sin >> v; return v; } template <class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); } template <class T> inline T sqr(T x) { retu...
#include <bits/stdc++.h> using namespace std; const int mo = 998244353, M = 16; int n, m, a[35], x[10], y[10]; int f[31][M][M][M][M][2][2]; bool v[31][M][M][M][M][2][2]; int F(int bit, int JW1, int JW2, int JW3, int JW4, int fl1, int fl2) { if (bit == 30) return !JW1 && !JW2 && !JW3 && !JW4 && fl1 && fl...
#include <bits/stdc++.h> using namespace std; int deg[200040], erased[200500], depth[200040]; void dfs(int x, int d, vector<vector<int>>& adj, int pa) { for (auto u : adj[x]) if (u != pa) dfs(u, d + 1, adj, x); depth[x] = d; } int main() { int n; cin >> n; vector<vector<int>> adj(n +...
#include <bits/stdc++.h> using namespace std; int n, a[1005]; int main() { int i, t, mini = 1000000, s, val, tfin; cin >> n; for (i = 1; i <= n; i++) cin >> a[i]; for (t = 1; t <= 105; t++) { s = 0; for (i = 1; i <= n; i++) { val = abs(t + 1 - a[i]); val = min(val, abs(...
#include <bits/stdc++.h> using namespace std; long long md = 1000000007; long long bexp(long long a, long long b) { if (b == 0) return 1; if (b == 1) return a; long long r = bexp(a, b / 2); r = r * r; if (b % 2 == 0) return r; else return r * a; } int main() { ios_base:...
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5; const int P = 998244353; int n, m, a[N], pre[N], rec[N], f[N]; inline void add(int &x, int y) { x += y; if (x >= P) x -= P; } inline void sub(int &x, int y) { x -= y; if (x < 0) x += P; } struct BL { int bel[N], t...
#include <bits/stdc++.h> using namespace std; template <class T> T gcd(T a, T b) { return b <= 0 ? a : gcd(b, a % b); } template <class T> T lcm(T a, T b) { return (a * b) / gcd(a, b); } template <class T> T large(T a, T b) { return a > b ? a : b; } template <class T> T small(T a, T ...
#include <bits/stdc++.h> #pragma GCC optimize(2) using namespace std; const int maxn = 1e6; const int INF = 0x7fffffff; const int mod = 1e9 + 7; const double eps = 1e-7; const double Pi = acos(-1.0); inline int read_int() { char c; int ret = 0, sgn = 1; do { c = getchar(); } while ...
#include<bits/stdc++.h> using namespace std; int main(){ int t; cin >> t; while(t--){ int n; cin >> n; vector <int> a(n); int k = INT_MAX,z = -1; for(int i=0;i<n;i++){ cin >> a[i]; k = min(k,a[i]); if(k==a[i]){ z = i; } } cout << n-1 << endl; for(in...
#include <bits/stdc++.h> using namespace std; const int maxn = 1e6 + 999; vector<int> v[maxn]; vector<pair<int, int> > g[maxn]; int fa[maxn], dep[maxn], siz[maxn], Top[maxn], son[maxn], dfn[maxn], clk; void dfs1(int x) { siz[x] = 1; dfn[x] = ++clk; for (int y : v[x]) { if (y == fa[x]) cont...
#include <bits/stdc++.h> using namespace std; int main() { int a, b, c; cin >> a >> b >> c; map<int, vector<int> > vec; for (int i = 0; i < a; i++) { int g; cin >> g; vec[g % c].push_back(g); } for (int i = 0; i < c; i++) { if (vec[i].size() >= b) { cout << Y...
#include <bits/stdc++.h> using namespace std; const double EPS = 1e-4; const long double PI = acos((long double)-1.0); const long long int MOD = 1e9 + 7; long long int powmod(long long int a, long long int b, long long int mod) { long long int res = 1; a %= mod; for (; b; b >>= 1) { if (b & ...
#include <bits/stdc++.h> using ll = long long; using namespace std; void debugi(vector<int>& vec) { int n = (int)vec.size(); for (int i = 0; i < n; i++) { cout << vec[i] << ; } cout << endl; } void debugl(vector<ll>& vec) { int n = (int)vec.size(); for (int i = 0; i < n; i++) ...
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; const long long N = 200; long long c[N][N], dp[N][N * N + N], g[N][N]; long long modp(long long a, long long b) { if (b == 0) return 1; long long u = modp(a, b / 2); u = (u * u) % mod; if (b & 1) return (a * u) % mod;...
#include <bits/stdc++.h> using namespace std; const long long INF = 1LL * 1001 * 1001 * 1001 * 1001 * 1001 * 1001; const int N = 10000; struct edge { long long a, b, cap, flow; edge(long long a, long long b, long long cap) : a(a), b(b), cap(cap), flow(0) {} long long cap_to(long long u) { re...
#include <bits/stdc++.h> using namespace std; int main() { int a, b, n; cin >> a >> b >> n; if (abs(a) + abs(b) <= n) { if ((n - abs(a) - abs(b)) % 2 == 0) cout << Yes ; else cout << No ; } else { cout << No ; } }
#include <bits/stdc++.h> using namespace std; int l[100000], r[100000], u[100000], d[100000]; int dp[2], dp2[2]; int main() { int i; int n, m, q; char c; scanf( %d %d %d , &n, &m, &q); for (i = 0; i < n; i++) scanf( %c , &c), l[i] = (c == B ); for (i = 0; i < n; i++) scanf( %c , &c), ...
#include <bits/stdc++.h> using namespace std; int n, m, now; int a[3005], b[3005]; int vis[3005], f[3005], c[3005]; int ok[3005]; int findcir(int *a, int n) { int ret = 0; for (int i = 1; i <= n; i++) b[a[i]] = i; memset(vis, 0, sizeof(vis)); for (int i = 1; i <= n; i++) { if (vis[i]) ...
#include <bits/stdc++.h> using namespace std; const double eps = 1e-9; set<long long> s; set<int> si; set<long long>::iterator it; vector<long long> v; vector<int> vi; int n, m, q, k; int a[200005]; int main() { int i, j, t; int w, h; ; scanf( %d%d , &w, &h); ; int u1, d1, u2...
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; for (int i = 0; i < t; i++) { int x; cin >> x; cout << x / 2 << endl; } }
#include <bits/stdc++.h> using namespace std; long long int n, x; vector<int> a; long long int tarkib(long long int r, long long int n) { long long int a = 1; for (long long int i = n; i > (n - r); i--) a = a * i; for (long long int i = 2; i < r + 1; i++) a = a / i; return a; } int main() { ...
#include <bits/stdc++.h> using namespace std; int main(void) { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, m; cin >> n >> m; if (n <= 450 and m == n * (n - 1) / 2) { cout << NO n ; return 0; } vector<set<int>> g(n + 1); for (int i = 0; i < m; ++i) { ...
#include <bits/stdc++.h> const long long mod = 1e9 + 7; const long long maxn = 1e5 + 7; const double pi = acos(-1); using namespace std; long long t, n, m; long long hang; long long weizhi; long long temp; long long four = 1; long long weishu; long long weishu2; long long lie; int ans[50]; m...
#include <bits/stdc++.h> using namespace std; const long long MOD = LLONG_MAX; long long gcd(long long x, long long y) { if (y == 0) return x; else return gcd(y, x % y); } long long power(long long x, unsigned long long y) { long long res = 1; x = x % MOD; if (x == 0) return 0;...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long int t, n, hold; cin >> t; while (t--) { bool ans = false; cin >> n; long long int x; for (long long int i = 0; i < n; i++) { c...
#include <bits/stdc++.h> using namespace std; const long long MAXN = 200005; vector<long long> byk[MAXN]; long long pangkat(long long x, long long y) { long long ret = 1; for (long long i = 1; i <= y; i++) ret *= x; return ret; } int main() { ios_base::sync_with_stdio(false); cin.tie(NUL...
#include <bits/stdc++.h> long long mpow(long long a, long long n, long long mod) { long long ret = 1; long long b = a; while (n) { if (n & 1) ret = (ret * b) % mod; b = (b * b) % mod; n >>= 1; } return (long long)ret; } using namespace std; int n, m, s; pair<int, int> bug...
#include <bits/stdc++.h> using namespace std; int dir4[4][2] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}}; int dir8[8][2] = {{-1, 0}, {1, 0}, {0, 1}, {0, -1}, {-1, 1}, {1, -1}, {1, 1}, {-1, -1}}; int dir8h[8][2] = {{2, 1}, {-2, -1}, {-1, 2}, {1, -2}, {1, 2}, {-2, 1}, {2, -1}, ...
#include <bits/stdc++.h> using namespace std; const int N = 2010; int n, m1, m2; int tp1[N], tp2[N]; struct Graph { int in[N]; bitset<N> e[N]; void floyd() { for (int k = 2; k <= 2 * n + 1; k++) for (int i = 2; i <= 2 * n + 1; i++) if (e[i][k]) e[i] |= e[k]; } void ...
#include <bits/stdc++.h> using namespace std; const int N = 51; const long long inf = (long long)1e14; const long long real_inf = (long long)1e18; inline long long value(const pair<long long, long long>& task, long long t) { return task.first - t * task.second; } int main() { ios_base::sync_with_s...
#include <bits/stdc++.h> using namespace std; int power(int num1, int num2) { int ans = 1; for (int i = 0; i < num2; i++) { ans *= num1; } return ans; } int main() { string str; int num1, help = 0; cin >> num1 >> str; for (int i = 0; i < str.size(); i++) { help += pow...
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e5; vector<int> G[MAXN + 5]; int maxFrom[MAXN + 5], down[MAXN + 5], up[MAXN + 5]; int id[MAXN + 5], sz[MAXN + 5], diam[MAXN + 5]; bool flag[MAXN + 5]; int ID; int n, m, Q; map<int, int> cnt; vector<int> accSum[MAXN + 5]; vector<double...
#include <bits/stdc++.h> using namespace std; int a[105]; int main() { int n, k, x; cin >> n >> k; for (int i = 0; i < n; i++) cin >> a[i]; int ans = 0; bool yes = true; for (int i = 0; i < n; i++) if (a[i] < k) { yes = false; break; } while (!yes) { f...
#include <bits/stdc++.h> using namespace std; long long a[300005] = {0}; long long two[300005] = {0}; const long long mod = 1e9 + 7; int main() { two[0] = 1; for (int i = 1; i <= 300000; i++) { two[i] = (two[i - 1] * 2LL) % mod; } long long res = 0; int n; while (cin >> n) { ...
#include <bits/stdc++.h> using namespace std; int main(int argc, char* argv[]) { cin.sync_with_stdio(false); cout.sync_with_stdio(false); int N, M; cin >> N >> M; vector<string> data(N); for (int i = 0; i < N; i++) cin >> data[i]; vector<string> data_rev(M, string(N, . )); for (int ...
#include <bits/stdc++.h> using namespace std; int main() { int a, b, c, d; while (~scanf( %d%d%d%d , &a, &b, &c, &d)) { int t = d - c; if (c - b == t && b - a == t) { printf( %d n , d + t); } else if (a != 0 && b != 0 && c != 0 && d != 0 && b * b == a * c && c * c ...
#include <bits/stdc++.h> using namespace std; 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 = getchar(); } return x * f; } ...
#include <bits/stdc++.h> using namespace std; int main() { long long int n, k, i, j, mx, ans = 0; cin >> n >> k; long long int arr[n]; for (i = 0; i < n; i++) cin >> arr[i]; sort(arr, arr + n); for (i = 0; i < n / 2; i++) swap(arr[i], arr[n - 1 - i]); for (i = 0; i < n; i++) { mx =...
#include <bits/stdc++.h> using namespace std; int t, n, m; int tot; int op[1005 * 1005 * 3][7]; string s; int a[1005][1005]; int p[1005][1005]; int sum; void check(int x1, int x2, int x3, int x4, int x, int y, int add) { sum = x1 + x2 + x3 + x4; if (!sum) return; if (sum == 1) { if (...
#include <bits/stdc++.h> using namespace std; long long n, m; long long bin(long long l, long long h) { long long ans; while (l <= h) { long long mid = (l + h) / 2; if (n - (mid * (mid + 1)) / 2 <= 0) { ans = mid; h = mid - 1; } else l = mid + 1; } return ...
#include <bits/stdc++.h> int main() { char c; std::set<char> s; while (std::cin >> c) { if ((c >= a ) && (c <= z )) { s.insert(c); } } std::cout << s.size() << n ; }
#include <bits/stdc++.h> using namespace std; char c; string s; set<char> q; int i, sum; int main() { getline(cin, s); for (i = 0; i < s.size(); i++) if (isalpha(s[i])) q.insert(s[i]); cout << q.size() << endl; return 0; }
#include <bits/stdc++.h> using namespace std; vector<string> mas; int n, m; void input() { cin >> n >> m; mas.clear(); mas.resize(n); for (int i = 0; i < n; ++i) cin >> mas[i]; } void solve() { string ans = mas[0]; for (int i = 0; i < m; ++i) { char save = ans[i]; for (ch...
#include <bits/stdc++.h> using namespace std; vector<int> roda(int f, vector<int> valores) { vector<int> temp(valores); if (f == 0) { temp[17] = valores[5]; temp[18] = valores[6]; temp[21] = valores[17]; temp[22] = valores[18]; temp[13] = valores[21]; temp[14] = valores[2...
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e5 + 10; const int p = 1e9 + 7; struct edge { int l, r, uk; }; edge a[MAXN]; int dp[4 * MAXN]; int b[MAXN]; int n, m; void update(int k) { dp[k] = (dp[k * 2] + dp[k * 2 + 1]) % p; if (k > 1) update(k / 2); } long long ge...
#include <bits/stdc++.h> using namespace std; int a[200]; int main() { int n; scanf( %d , &n); for (int i = 1; i <= n; i++) scanf( %d , &a[i]); int res = 0, ans = 0; a[0] = -10; for (int i = 1; i <= n; i++) { if (a[i] == a[i - 1] + 1) res++; else res = 0; ...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n, m; cin >> n >> m; vector<long int> a[n + 1], b[n + 1]; vector<pair<int, int> > v; for (int i = 0; i <= n; i++) a[i].resize(m + 1), b[i].resize(m + 1); ...
#include <bits/stdc++.h> using namespace std; int main() { long long i, j, n, a, b, m, k, y, z, cos, pos, color; long long r[5005], c[5005], x[100009]; cin >> n >> m >> k; for (i = 1; i <= k; i++) { cin >> cos >> pos >> color; x[i] = color; if (cos == 1) r[pos] = i; e...
#include <bits/stdc++.h> using namespace std; int main() { int n, swaps = 0; vector<int> seq; cin >> n; seq.resize(n * 2); for (int i = 0; i < n * 2; i++) cin >> seq[i]; for (int i = 0; i < 2 * n - 1; i += 2) { int j = i + 1; while (seq[j] != seq[i]) j++; for (int k = j; k ...
#include <bits/stdc++.h> using namespace std; char s[2000][2000]; int n, m; bool h[300][300]; bool v[300][300]; const long long mod = 1000000007; void get(int x, int y, bool& h, bool& v) { int cnt = 0; for (int i = 0; i < 3; i++) for (int j = 0; j < 3; j++) { if (s[x + i][y + j] == ...
#include <bits/stdc++.h> using namespace std; const int N = 3e5 + 5; long long a[N]; long long dp[N][20]; int main() { int n, m, k; cin >> n >> m >> k; a[0] = 0; for (int i = 1; i <= m; i++) dp[0][i] = -1e10; long long ans = 0; for (int i = 1; i <= n; i++) { scanf( %lld , &a[i]);...
#include <bits/stdc++.h> using namespace std; int n; long long ar[100100]; int main() { cin >> n; for (int i = 0; i < n; i++) { cin >> ar[i]; } sort(ar, ar + n); long long dif1 = ar[1] - ar[0], dif2 = -1; int cnt1 = 0, cnt2 = 0; if (n == 1) { cout << -1 << endl; ret...
#include <bits/stdc++.h> using namespace std; long long a[100009], b[100009], s[100009]; signed main() { ios_base::sync_with_stdio(false), cin.tie(NULL); long long i, j, n, m, c; cin >> n >> m >> c; for (i = 1; i <= n; i++) cin >> a[i]; for (i = 1; i <= m; i++) cin >> b[i], s[i] = (b[i] + s[i ...
#include <bits/stdc++.h> using namespace std; long long mas[200004]; long long mas2[200004]; struct ver { long long abs; int number; long long maxabs; int masnumber; ver *l; ver *r; }; void build(ver *v, int l, int r, long long *m) { if (l == r) { v->abs = m[l]; v->nu...
#include <bits/stdc++.h> using namespace std; double x[100000]; int main() { ios_base::sync_with_stdio(false); int n, m; cin >> n >> m; for (int i = 1; i <= n; i++) cin >> x[i]; double ans = 0; for (int i = 1; i <= m; i++) { int fi, se, we; cin >> fi >> se >> we; ans = ma...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; while (n--) { string s; cin >> s; bool b = true, b1 = false, b2 = true, b3 = false; int sum = 0; for (int i = 0; i < s.size(); i++) { sum += (int)s[i] - 48; int x = (int)s[i] - 48; ...