solution
stringlengths
53
181k
difficulty
int64
0
27
#include <bits/stdc++.h> using namespace std; int main() { int T; cin >> T; while (T--) { long long n; long long ans = 0, p = 1; cin >> n; n++; while (p <= n) { ans += (n + p - 1) / p - 1; p *= 2; } cout << ans << endl; } }
6
#include <bits/stdc++.h> typedef long long ll; using namespace std; int T,n,K,p,a[1010][1010]; ll S[1010],sv,B[1010],sv2=0; ll sqr(ll x){ return x*x; } int main(){ scanf("%d%d",&n,&K); for(int i=0;i<K;i++){ for(int j=1;j<=n;j++) scanf("%d",&a[i][j]),S[i]+=a[i][j]; if(i) B[i-1]=S[i]-S[i-1]; } for(int i=0;i<K-2;...
22
#include <bits/stdc++.h> using namespace std; int reverse(int a) { int b = 0; for (int i = 0; i < 8; i++) { b <<= 1; b |= a & 1; a >>= 1; } return b; } int main(int narg, char **arg) { int prev = 0; int c; while ((c = getchar()) >= 0) { if (c < 32) break; int a = c; a = reverse(a);...
5
#include <bits/stdc++.h> using namespace std; int main() { int t, a, b, k; scanf("%d", &t); while (t--) { scanf("%d%d%d", &a, &b, &k); if (k % 2) { printf("%I64d\n", 1ll * (k / 2) * (a - b) + a); } else { printf("%I64d\n", 1ll * (k / 2) * (a - b)); } } return 0; }
0
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; bool isp[1123456]; void getprime() { memset(isp, 1, sizeof(isp)); isp[0] = isp[1] = 0; for (int i = 2; i < 1123456; i++) { if (!isp[i]) continue; for (int j = i + i; j < 1123456; j += i) { isp[j] = 0; } } } int n; int a[112...
6
#include <bits/stdc++.h> using namespace std; int n, a, b, g; vector<int> G[309]; bool v[309]; int P1[309], D[309], f[309], s[609], s1, C[309], sk[309], P[309][19]; void dfs(int cur, int prev) { P[cur][0] = P1[cur] = prev; if (cur != 1 && (int)G[cur].size() == 1) g++; for (int h = 0; h < (int)G[cur].size(); h++) ...
12
#include <bits/stdc++.h> using namespace std; int main() { long long n; int a; int b; int c; int d; cin >> n >> a >> b >> c >> d; int kol = 0; int vop1 = 1; int vop2; int vop3; int vop4; while (vop1 <= n) { vop2 = vop1 + b - c; vop3 = vop1 + b - c + a - d; vop4 = vop1 + a - d; if...
6
#include <bits/stdc++.h> using namespace std; const int MAXN = 105; int nTest; int r, c, k; char s[MAXN][MAXN], ans[MAXN][MAXN]; vector<char> ch; int main() { for (char c = 'a'; c <= 'z'; ++c) ch.push_back(c); for (char c = 'A'; c <= 'Z'; ++c) ch.push_back(c); for (char c = '0'; c <= '9'; ++c) ch.push_back(c); ...
9
/** * author: Taara Sinh Aatrey * created: 05.05.2021 20:58:34 **/ // #undef _GLIBCXX_DEBUG #include <bits/stdc++.h> using namespace std; template <typename A, typename B> string to_string(pair<A, B> p); string to_string(const string& s) { return '"' + s + '"'; } string to_string(const char* s) { return to...
14
#include <bits/stdc++.h> using namespace std; bool secdes(const pair<long long int, long long int>& a, const pair<long long int, long long int>& b) { if (a.second == b.second) { return a.first > b.first; } else { return a.second > b.second; } } bool sir(const pair<long long int, long long int>...
5
#include <bits/stdc++.h> using namespace std; int n, m, i, j, a, b, w, k, z; long long d[100005], p[100005]; map<pair<long long, long long>, long long> mp; priority_queue<long long> q; vector<long long> v[100005]; void f(long long i) { if (i != 1) f(p[i]); cout << i << ' '; } int main() { cin >> n >> m; while (...
11
#include <bits/stdc++.h> int N; int ansi[20005], ansj[20005], K; std::vector<int> e[1005]; bool f[1005]; void solve(int z) { for (int i = 0; i < N - 1; i++) e[i].push_back(i + 1); for (int i = 0; i < N - 3; i++) { int a, b; scanf("%d%d", &a, &b); a--; b--; if (a > b) std::swap(a, b); e[a].pu...
21
#include <bits/stdc++.h> using namespace std; int main() { int n, i, j, m, num, a, b; vector<int> rems; scanf("%d", &n); a = b = 0; for (j = 0; j < n; j++) { scanf("%d", &m); for (i = 0; i < m; i++) { scanf("%d", &num); if (i < m / 2) a += num; else if ((m % 2 == 1) && (i == ...
12
#include <bits/stdc++.h> using namespace std; template <typename T> struct Interval { Interval() : lo(0), hi(0) {} Interval(T lo, T hi) : lo(lo), hi(hi) {} T lo, hi; std::string debug() const { std::ostringstream oss; oss << "[" << lo << ", " << hi << ")"; return oss.str(); } }; template <typename...
26
#include <bits/stdc++.h> using namespace std; template <typename T1, typename T2> inline T1 max(T1 a, T2 b) { return a < b ? b : a; } template <typename T1, typename T2> inline T1 min(T1 a, T2 b) { return a < b ? a : b; } const char lf = '\n'; namespace ae86 { const int bufl = 1 << 15; char buf[bufl], *s = buf, *t ...
21
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); int tt; cin >> tt; while (tt--) { long long n; cin >> n; if (n & 1) { long long x = (n - 1) >> 1; cout << x << ' ' << x + 1 << '\n'; } else { cout << 1 - n << ' ' << n << ...
0
#include <bits/stdc++.h> using namespace std; int a[2005]; pair<int, int> b[2005]; int main() { int n, k; scanf("%d%d", &n, &k); for (int i = 1; i <= n; i++) { scanf("%d", &a[i]); b[i] = pair<int, int>(-a[i], i); } sort(b + 1, b + 1 + n); vector<int> v; int ans = 0; for (int i = 1; i <= k; i++) ...
4
#include <bits/stdc++.h> using namespace std; int mod = 1000000000 + 7; int addm(int& a, int b) { return (a += b) < mod ? a : a -= mod; } template <class T, class U> bool smin(T& a, U b) { return a > b ? (a = b, 1) : 0; } template <class T, class U> bool smax(T& a, U b) { return a < b ? (a = b, 1) : 0; } int a, b, ...
18
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 5; int n, cnt[N]; map<int, int> mp; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n; for (int i = 1; i <= n; i++) { int a; cin >> a; cnt[a]++; if (mp.find(a) == mp.end()) { mp[a] = 1; }...
10
#include <bits/stdc++.h> using namespace std; struct func { int a, b; func() : a(1), b(-1) {} func(int _a, int _b) : a(_a), b(_b) {} int operator[](int x) const { if (x < 0) return b; else return a; } func operator+(const func& q) const { func tmp; tmp.a = q[a]; tmp.b = q[b];...
16
#include <bits/stdc++.h> using namespace std; int yo1[1000000], yo2[1000000]; int main() { long long n; cin >> n; string arr; cin >> arr; yo1[0] = 0; for (int i = 1; i < n; i++) { if (arr[i] == arr[i - 1]) yo1[i] = yo1[i - 1]; else yo1[i] = i; } yo2[n - 1] = n - 1; for (int i = n -...
11
#include <bits/stdc++.h> using namespace std; const int MOD = 1000000007; const int INF = 1000000001; const long long int LLINF = 1000000000000000001LL; struct MinTree { vector<pair<int, int> > T; int p = 1; int par(int x) { return (x - 1) / 2; } MinTree(vector<int> &V) { int n = (int)(V).size(); while ...
14
#include <bits/stdc++.h> using namespace std; int n; struct quest { int time, type, num; bool operator<(quest b) const { if (time < b.time || time == b.time && type < b.type || time == b.time && type == b.type && num < b.num) { return true; } else { return false; } } }; vector<int>...
16
#include <bits/stdc++.h> using namespace std; const int maxn = 1e6 + 10; char s[maxn]; int q[maxn]; int main() { scanf("%s", s); int len = strlen(s); int l = 1, r = len; for (int i = 0; i < len; i++) { if (s[i] == 'l') q[r--] = i + 1; else q[l++] = i + 1; } for (int i = 1; i <= len; i++)...
4
#include <bits/stdc++.h> using namespace std; const int N = 100005; const int M = 7005; int n, q; bool bad[M]; bitset<M> divs[M]; bitset<M> muls[M]; bitset<M> a[N]; int main() { for (int i = 2; i < M; ++i) { for (int j = i * i; j < M; j += i * i) { bad[j] = true; } } for (int i = 1; i < M; ++i) { ...
17
#include <bits/stdc++.h> using namespace std; string can_split(int p[], int n) { for (int i = 0; i < n; i++) { if (p[i] != 0) break; if (i == n - 1) return "NO"; } return "YES"; } int split(int br_str, int pocetni[], int zavrsni[], int p[], int n) { int sum = 0; for (int i = 0; i < n; i++) { sum +...
4
#include <bits/stdc++.h> char str[1000000 + 1]; int main() { int n; scanf("%d\n", &n); scanf("%s", str); int depth = 0, total = 0, beginSeq = -1; for (int i = 0; i < n; i++) { if (str[i] == ')') { if (depth == 0) { beginSeq = i; } depth--; } else { depth++; if (de...
5
#include <bits/stdc++.h> using namespace std; int n; long long w, b; int main() { cin >> n; for (int a, i = 0; i < n; i++) { cin >> a; if (i & 1) { b += (a / 2); w += a - (a / 2); } else { b += a - (a / 2); w += (a / 2); } } cout << min(b, w) << "\n"; return 0; }
12
#include <bits/stdc++.h> using namespace std; bool isUpper(char c) { return (c >= 'A' && c <= 'Z'); } bool isLower(char c) { return (c >= 'a' && c <= 'z'); } bool isalpha(char c) { return (c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z'); } bool isalnum(char c) { return (c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z...
3
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int x, y, l, r; while (n--) { cin >> x >> y >> l >> r; long long num = 0; if (l % y == 0) num = 1; cout << (x / y) - (r / y - l / y) - num << endl; } return 0; }
3
#include <bits/stdc++.h> using namespace std; long long n, m, l, r, mid, i, ans, it1, it2, j, temp; bool check; signed main() { scanf("%d", &n); long long a[n]; for (i = 0; i < n; ++i) { scanf("%d", &temp); a[i] = temp; } scanf("%d", &m); long long b[m]; for (i = 0; i < m; ++i) { scanf("%d", &...
8
#include <bits/stdc++.h> using namespace std; int Day12[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; int prime100[] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103}; template <typename T> inline bool isLeap(T y) { return (y % ...
0
#include <bits/stdc++.h> using namespace std; vector<long long> lucky; void f(int i, long long value) { if (value > 3000000000) return; else { lucky.push_back(value); } if (i == 0) { for (int j = 1; j <= 9; j++) { f(i + 1, j); } } else f(i + 1, value * 10); } int main(void) { f(0, ...
1
#include <bits/stdc++.h> using namespace std; const int mx = 200005; struct node { int lx, ly, rx, ry; node operator+(const node b) const { node tmp; tmp.lx = max(lx, b.lx); tmp.ly = max(ly, b.ly); tmp.rx = min(rx, b.rx); tmp.ry = min(ry, b.ry); return tmp; } } p[mx], a[mx], b[mx]; int mai...
8
#include <bits/stdc++.h> int main() { char ch[104] = {'\0'}; scanf("%s", ch + 1); int cnt = 0, ot = 0; for (int i = 1; ch[i + 1] != '\0'; ++i) { if (ch[i] == 'V' && ch[i + 1] == 'K') cnt++; if (ch[i] == 'V' && ch[i + 1] == 'V' && ch[i + 2] != 'K') ot++; if (ch[i - 1] != 'V' && ch[i] == 'K' && ch[i +...
3
#include <bits/stdc++.h> int main() { int a, b, c, d, n, len; char str[100]; gets(str); len = strlen(str) - 2; while (str[len] == ' ') { len--; } if (str[len] == 'A' || str[len] == 'a' || str[len] == 'E' || str[len] == 'e' || str[len] == 'I' || str[len] == 'i' || str[len] == 'O' || str[len...
0
#include <bits/stdc++.h> using namespace std; template <typename T> inline T abs(T a) { return ((a < 0) ? -a : a); } template <typename T> inline T sqr(T a) { return a * a; } const int INF = (int)1E9 + 7; const long double EPS = 1E-9; const long double PI = 3.1415926535897932384626433832795; bool cmp(const pair<int...
10
#include <bits/stdc++.h> using namespace std; int asc[100005], des[100005], s[100005]; int main() { int a, b, i; cin >> a >> b; for (i = 1; i <= a + b + 1; i++) s[i] = i; if (a == 0) { for (i--; i >= 1; i--) printf("%d ", s[i]); return 0; } int k = 0; for (i = b + 2; s[i] != '\0'; i++) { asc[k...
2
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") #pragma GCC optimize("unroll-loops") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") using namespace std; const int N = 500005; vector<pair<int, int> > v[N]; int n, X, Y, x, y, z, Z, cnt, vis[N]; long long ans, sum; struct dui { int ...
20
#include <bits/stdc++.h> using namespace std; vector<int> l; vector<int> g[2010]; bool visited[2010]; void dfs(int v) { visited[v] = 1; for (int to : g[v]) if (!visited[to]) dfs(to); } int main() { int z; cin >> z; for (int i = 0, x, y; i < z; i++) { cin >> x >> y; g[x].push_back(y + 1000); g[...
4
#include <bits/stdc++.h> using namespace std; long long int MAX = 1000000000000000; long long int min(long long int a, long long int b) { if (a < b) return a; return b; } long long int max(long long int a, long long int b) { if (a > b) return a; return b; } long long int gcd(long long int a, long long int b) { ...
10
#include <bits/stdc++.h> using namespace std; int main() { int x, y, i, j = 0; char ch[200]; cin >> x >> y; int a[y + 1]; memset(a, 0, sizeof(a)); int b = -1; for (i = 0; i < y; i++) { scanf("%s", &ch); int s = 0; int i_1 = 0, i_0 = 0; for (int k = 0; k < strlen(ch); k++) { if (ch[k]...
0
#include <bits/stdc++.h> using namespace std; int color[105], n, k, num; int make(int l, int r) { int cnt; if (l < 0 || r >= n) { return 0; } if (color[l] != color[r]) { return 0; } if (l + 1 == r) { cnt = 3; } else cnt = 2; while (l > 0 && color[l - 1] == color[r]) { --l; ++cnt;...
6
#include <bits/stdc++.h> using namespace std; int main() { int v, count = 0, a, b; for (int i = 0; i < 5; i++) { for (int j = 0; j < 5; j++) { cin >> v; if (v == 1) { a = i; b = j; } } } if (a < 2) { while (a < 2) { a++; count++; } } else if (a > 2...
0
#include <bits/stdc++.h> using namespace std; int a[2001][2001], b[2001][2001], c[2001]; vector<int> g[8004]; void sete(int u, int v) { g[u].push_back(v); } int dfn[8004], low[8004], bel[8004], dfc, scc; bool inst[8004]; int scs[8004], *sct = scs; void scc_clr(int n) { fill(dfn + 1, dfn + n + 1, 0); } int dfs_scc(int u...
13
#include <bits/stdc++.h> using namespace std; const int inf = 1 << 30; const int MAXN = 3100; vector<int> par[MAXN]; vector<int> child[MAXN]; int backw; int maxsave; int minsave; int cursave; void go(int x, int from) { int prmin = minsave; minsave = min(minsave, cursave); maxsave = max(maxsave, cursave - minsave)...
13
#include <bits/stdc++.h> using namespace std; const int MAX = 100005; int N, M, X, Y; int A[MAX], B[MAX]; int legal(int a) { if (-X <= a and a <= Y) { return 0; } if (a <= -X) { return -1; } return 1; } vector<pair<int, int> > res; int main() { cin >> N >> M >> X >> Y; for (int i = 0; i < N; i++) ...
5
#include <bits/stdc++.h> using namespace std; bool ispal(int x) { int a = x, b = 0; if (x % 10 == 0) return false; while (x) { b = b * 10 + x % 10; x /= 10; } return (a == b); } int p, q, pi, rub, ans; bool s[2000000]; void solve() { scanf("%d %d", &p, &q); s[2] = true; for (int i = 3; i < 20000...
8
#include <bits/stdc++.h> #pragma GCC optimize(2) using namespace std; pair<int, int> a[1030], b[1030], c[1030]; int n; bool work(int tx, int ty) { for (int i = 1; i <= n; ++i) { c[i].first = tx - b[i].first; c[i].second = ty - b[i].second; } sort(c + 1, c + 1 + n); for (int i = 1; i <= n; ++i) if (a...
4
#include <bits/stdc++.h> using namespace std; namespace IO { const int MAXIOSIZE = 1 << 24 | 1; unsigned char buf[MAXIOSIZE], *p1, *p2; template <typename T> void read(T& x) { x = 0; char ch = (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 24, stdin), p1 == p2) ? EOF : *p1++); bool...
11
#include <bits/stdc++.h> using namespace std; long long power(long long x, 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) % p; } return res; } const int N = 1e3 + 7; const int xinc[] = {0, 0, 1, -1}; const int yinc[...
7
#include <bits/stdc++.h> using namespace std; struct Edge { int to, nxt; } e[2000005 << 1]; int head[2000005], tot, n, m; int c[2000005], out[2000005], cnt; int ind, dfn[2000005], low[2000005], stk[2000005], top, ins[2000005]; void tarjan(int x) { dfn[x] = low[x] = ++ind; stk[++top] = x; ins[x] = 1; for (int ...
16
#include <bits/stdc++.h> using namespace std; int mat[1001][1001]; int main() { int i, cur, x, l, j, k; char str[21]; scanf("%s", str); l = strlen(str); cur = 3; for (i = 0; i < l; i++) { mat[cur][1] = mat[1][cur] = 1; int x = str[i] - '0'; if (x) { for (j = i; j < l - 1; j++) { fo...
11
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:526000000") using namespace std; void init() {} int gogo[2][5000][5000]; vector<long long> cows[5000]; pair<long long, long long> ans[5004]; void solve() { long long n, m; scanf("%lld%lld", &n, &m); vector<long long> s; for (long long(i) = 0; (i) < (n); +...
17
#include <bits/stdc++.h> namespace IO { char cc; int C; template <class T> void read(T &x) { x = 0; cc = getchar(); C = 1; while (!('0' <= cc && cc <= '9')) { if (cc == '-') C = -1; cc = getchar(); } while (('0' <= cc && cc <= '9')) { x = x * 10 + cc - 48; cc = getchar(); } x *= C; } } ...
21
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int m = 3; while (m * (m + 1) / 2 <= n) ++m; cout << m << endl; int cnt = 1; vector<vector<int> > res(m); for (int i = 0; i < m; ++i) { for (int j = i + 1; j < m; ++j) { res[i].push_back(cnt); res[j].push_back(cn...
8
#include <bits/stdc++.h> using namespace std; long long a[200005]; int main() { long long n, m, i; scanf("%lld%lld", &n, &m); string s, t; cin >> s >> t; long long lens = s.size(); long long lent = t.size(); if ((lens - 1) > lent) { printf("NO\n"); return 0; } string x, y; for (i = 0; i < le...
4
#include <bits/stdc++.h> using namespace std; const double eps = 1e-10; const int MAXN = 1e7 + 6; const int MOD = 1e9 + 7; int dx[] = {1, -1, 0, 0}; int dy[] = {0, 0, 1, -1}; int n, k; vector<int> arr; bool cmp(int a, int b) { return (a % 10) > (b % 10); } int main() { cin >> n >> k; arr.resize(n); int rem = 0; ...
6
#include <bits/stdc++.h> using namespace std; void pause() {} int main() { ios::sync_with_stdio(false); int64_t i, n, f; cin >> n >> f; int64_t ans = 0; vector<int64_t> a; for (i = 0; i < n; i++) { int l, k; cin >> k >> l; ans += min(k, l); a.push_back(min(2 * k, l) - min(k, l)); } sort(...
5
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int a[n]; int chest = 0, bicep = 0, back = 0; for (int i = 0; i < n; i++) { cin >> a[i]; } if (n > 0) { chest += a[0]; } if (n > 1) { bicep += a[1]; } if (n > 2) { back += a[2]; } for (int i = 3; i < n;...
0
#include <bits/stdc++.h> using namespace std; const int MAXN = 5005; const int MOD = 1000000007; long long n, k, sol; int dp[MAXN][MAXN], p[MAXN], l[MAXN]; vector<int> v[MAXN]; long long add(long long a, long long b) { a += b; if (a >= MOD) return a - MOD; return a; } long long sub(long long a, long long b) { a...
16
#include <bits/stdc++.h> using namespace std; int n, cnt = 0, last = 0; char second[100005]; int isconsonant(char x) { if (x == 'a' || x == 'e' || x == 'i' || x == 'o' || x == 'u') return 0; return 1; } int main() { scanf("%s", second); n = strlen(second); for (int i = 0; i < n - 2; i++) { if (isconsonant...
7
#include <bits/stdc++.h> using namespace std; void task(); int main() { task(); return 0; } const int INF = 1 << 31; const int N = (int)2e5; const int MODULO = (int)1e8; vector<vector<pair<int, int> > > g; int dp[N + 10]; int ans; set<int> ansi; int dfs(int v, int from) { int tans = 0; for (int i = 0; i < g[v]....
9
#include <bits/stdc++.h> using namespace std; const long long inf = (long long)1e15 + 10; const int N = (int)1e6 + 10; void solve() { long long a; string s; cin >> a >> s; unordered_map<long long, long long> mp; for (int i = 0; i < (int)s.size(); i++) { int curr = 0; for (int j = i; j < (int)s.size();...
8
#include <bits/stdc++.h> using namespace std; int read() { int cnt = 0, f = 1; char ch = 0; while (!isdigit(ch)) { ch = getchar(); if (ch == '-') f = -1; } while (isdigit(ch)) cnt = cnt * 10 + (ch - '0'), ch = getchar(); return cnt * f; } void fail() { puts("no"); exit(0); } int n, m, a[1000050]...
27
#include <bits/stdc++.h> using namespace std; template <typename T> inline T read() { T x = 0, f = 0; char c = getchar(); while (!isdigit(c)) f = c == '-', c = getchar(); while (isdigit(c)) x = x * 10 + c - 48, c = getchar(); return f ? -x : x; } namespace run { const int N = 2e5 + 9; vector<int> ans[N], sd, ...
23
#include <bits/stdc++.h> using namespace std; struct Data { int l, r, w; Data(int a, int b, int c) { l = a; r = b; w = c; } Data(){}; }; bool cmp(Data a, Data b) { return a.w < b.w; } int tree[4 * 1000005], lazy[4 * 1000005]; void push(int indx) { tree[2 * indx] += lazy[indx]; tree[2 * indx + 1]...
13
#include <bits/stdc++.h> using namespace std; vector<vector<int> > g; pair<int, int> ifh[210]; pair<int, int> ift[210]; vector<int> p; vector<int> was; int bfs(int v) { was.resize(g.size(), -1); was[v] = 0; p.push_back(v); int l = 0; while (l < p.size()) { int v = p[l]; l++; if (v == 0) break; ...
13
#include <bits/stdc++.h> using namespace std; double a, b, c, A, B, C, f1, f2; int main() { cin >> a >> b >> c; cin >> A >> B >> C; if (a == 0 && b == 0 && c == 0) f1 = 1; else if (a == 0 && b == 0 && c != 0) f1 = -1; if (A == 0 && B == 0 && C == 0) f2 = 1; else if (A == 0 && B == 0 && C != 0) ...
12
#include <bits/stdc++.h> template <typename T> void read(T& _val) { std::cin >> _val; } template <typename T, typename... Args> void read(T& _val, Args&... _args) { std::cin >> _val; read(_args...); } template <typename T> void print(const T& _val) { std::cout << _val << std::endl; } template <typename T, typen...
1
#include <bits/stdc++.h> using namespace std; double Distance(int x1, int x2, int y1, int y2) { return (double)(pow(x1 - x2, 2) + pow(y1 - y2, 2)); } int main() { ios_base::sync_with_stdio(0), cin.tie(0); int n, m, d; cin >> n >> m >> d; vector<pair<char, pair<int, int>>> data; vector<pair<int, int>> shifts...
7
#include <bits/stdc++.h> using namespace std; char a[1005]; int isprime[1005]; int main() { string s; cin >> s; int l = s.length(); int i, j; isprime[0] = 0; isprime[1] = 0; int vis[1005] = {0}; for (i = 2; i <= sqrt(l); i++) { if (isprime[i] == 0) { for (j = i * i; j <= l; j = j + i) { ...
5
#include <bits/stdc++.h> using namespace std; int gcd(int a, int b) { int r = b % a; while (r != 0) { b = a; a = r; r = b % a; } return a; } int main() { int n; cin >> n; int a, b; a = n / 2 - 1 + n % 2; b = n / 2 + 1; while (gcd(a, b) != 1) { a--; b++; } cout << a << " " << ...
0
#include <bits/stdc++.h> using namespace std; int main() { string str; cin >> str; int n; cin >> n; string arr[150]; for (int i = 0; i < n; i++) { cin >> arr[i]; if (str == arr[i]) { cout << str; return 0; } } vector<string> s; int m = 0; for (int i = 0; i < n; i++) { for...
3
#include <bits/stdc++.h> using namespace std; long long gboss(string &s, long long l, long long r) { long long result = 0; for (long long i = l; i <= r; i++) { result *= 2; result += (s[i] == '1'); } return result; } void solve() { string s; cin >> s; long long n = s.size(); vector<long long> co...
9
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 10, mod = 479001599, p = 173; int hs[3][maxn], pp[maxn]; string s[3]; inline int add(int a, int b) { return a + b >= mod ? a + b - mod : a + b; } inline int sub(int a, int b) { return a - b < 0 ? a - b + mod : a - b; } inline int mul(int a, int b) { r...
14
#include <bits/stdc++.h> using namespace std; int n, m; int a[300005], b[300005]; vector<pair<int, int> > G[300005]; int q[300005], l, r, p[300005]; int main() { int x, y; scanf("%d%d", &n, &m); for (int i = 1; i <= (n); ++i) scanf("%d", a + i); for (int i = 1; i <= (m); ++i) scanf("%d%d", &x, &y), G[x].pus...
16
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 10, mod = 1e9 + 7; int fact[N], invfact[N]; inline int add(int x, int y) { x += y; if (x >= mod) x -= mod; return x; } inline int sub(int x, int y) { x -= y; if (x < 0) x += mod; return x; } inline int mul(int x, int y) { return (((long long)...
17
#include <bits/stdc++.h> using namespace std; struct node { int x, y; bool operator<(const node &a) const { return x < a.x; } } arr[200]; struct table { bool xt[200], yt[200]; } ft[200]; int father[200]; bool check[200]; vector<int> xtab, ytab; int getf(int id) { if (id == father[id]) return id; int nf = getf...
4
#include <bits/stdc++.h> using namespace std; #pragma comment(linker, "/STACK:17000000") const double eps = 1e-9; const double inf = 1e+9; int n, k; int a[100009]; int main() { scanf("%d%d", &n, &k); int t = n; for (int i = 0; i < n; i += 2) { a[i] = t--; } t = 1; for (int i = 0; i < n; i++) { if (!...
4
#include <bits/stdc++.h> using namespace std; int main() { long long n; cin >> n; long long a[n], b[n]; for (long long i = 0; i < n; i++) { cin >> a[i]; } for (long long i = 0; i < (n - 1); i++) { b[i] = a[i] + a[i + 1]; } b[n - 1] = a[n - 1]; for (long long i = 0; i < n; i++) { cout << " ...
0
#include <bits/stdc++.h> using namespace std; template <class T> int size(const T &a) { return int(a.size()); } template <class T> T sqr(const T &a) { return a * a; } int mlen(long long x) { int len = 0; while (x) { x /= 10; len++; } return len; } int main() { long long a, b; cin >> a >> b; in...
8
#include <bits/stdc++.h> using namespace std; long long N, L, R, U, V; int M; int mod; int calc(long long a1, long long d, long long &le, long long &ri) { long long an = a1 + (ri - le) * d; if (U > an || V < a1) return 0; long long kr = (V - a1) / d; if (kr > ri - le) kr = ri - le; long long kl = (U <= a1 ? 0...
17
#include <bits/stdc++.h> using namespace std; const long long LLINF = 1ll << 60; const int mx = 1e6 + 7; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout << setprecision(25); int T = 1; while (T--) { long long l, r; cin >> l >> r; long long rl = r - l; long long ans =...
9
#include <bits/stdc++.h> using namespace std; vector<int> tree[100001]; vector<long long> ch2[100001]; vector<long long> vch2[100001]; vector<bool> vis(100001, 0); vector<bool> v(100001, 0); vector<int> parent(100001); vector<int> p(100001); vector<int> num(100001); vector<int> l; vector<int> r; vector<double> ans; vec...
15
#include <bits/stdc++.h> using namespace std; const long long inf = 1e9; signed main() { long long n, l, r; cin >> n >> l >> r; long long mn = 0, mx = 0; for (long long i = 0; i < r; i++) mx += (1 << i); for (long long i = r; i < n; i++) mx += (1 << (r - 1)); for (long long i = 0; i < l; i++) mn += (1 << i)...
1
#include <bits/stdc++.h> using namespace std; int n, m, h[1005], l[1005]; string s[1005]; int tot; int main() { cin >> n >> m; for (int i = 1; i <= n; i++) cin >> s[i]; for (int i = 1; i <= n; i++) for (int j = 0; j <= m - 1; j++) { if (s[i][j] == '*') { l[i]++; h[j]++; tot++; ...
6
#include <bits/stdc++.h> using namespace std; const long long M = 100000; template <typename T> void read(T &x) { x = 0; char c = getchar(); bool f = 0; while (!isdigit(c) && c != '-') c = getchar(); if (c == '-') f = 1, c = getchar(); while (isdigit(c)) x = x * 10 + c - '0', c = getchar(); if (f) x = -x;...
20
#include <bits/stdc++.h> using namespace std; const long double eps = 1e-5; const long double PI = acos(-1); const int INF = (int)1e9; const long long INFF = (long long)1e18; const int mod = (int)1e9 + 7; const int MXN = (int)1e6 + 7; char s[MXN], s1[MXN], s2[MXN]; int sub[27], used[27]; int k, l; bool sp1(int st) { ...
15
#include <bits/stdc++.h> using namespace std; int main() { long long int n; cin >> n; vector<int> v; for (long long int i = 0; i < n; i++) { long long int p; cin >> p; v.push_back(p); } long long int prev = 0; for (long long int k = 1; k < n; k++) { long long int t = (int)(log2(n - k)); ...
2
#include <bits/stdc++.h> using namespace std; void solve() { int n; cin >> n; vector<int> a(n); for (auto &it : a) cin >> it; int l = 0, r = n - 1; int suml = 0, sumr = 0; int cnt = 0, ansl = 0, ansr = 0; while (l <= r) { if (cnt % 2 == 0) { int nsuml = 0; while (l <= r && nsuml <= sumr)...
5
#include <bits/stdc++.h> using namespace std; int main(int argc, char* argv[]) { int n, m, k; cin >> n >> m >> k; vector<string> M(n); for (auto& x : M) cin >> x; for (int j = 0; j < m; ++j) { long long cnt = 0; for (int i = 2; i < n; i += 2) if (M[i][j] == 'U') ++cnt; for (int i = 1; j + i ...
6
#include <bits/stdc++.h> #pragma GCC optimize(2) #pragma GCC optimize("Ofast", "unroll-loops", "omit-frame-pointer", "inline") using namespace std; const long long INF = 1e18; const int maxn = 6e5 + 6; const int mod = 100000000; const double eps = 1e-15; inline bool read(long long &num) { char in; bool IsN = false;...
14
#include <bits/stdc++.h> using namespace std; using ll = long long; using ull = unsigned long long; using pii = pair<int, int>; const int mod = 1e9 + 7; const int maxn = 1e6 + 5; string s[3]; bool isShun1(int i, int j) { return (s[i][1] == s[j][1] && s[i][0] == s[j][0] - 1); } bool isShun2(int i, int j) { return (s...
4
#include <bits/stdc++.h> using namespace std; int n; map<int, int> cnt; void input() { cin >> n; for (int i = 0; i < n; i++) { int x; cin >> x; cnt[x]++; } } void output() { return; } void lolicon() { vector<int> cnts; for (auto it : cnt) { cnts.push_back(it.second); } sort(cnts.begin(), c...
10
#include <bits/stdc++.h> using namespace std; long long S, Ans; long long F[60][120][2]; void DP(int a, int b, long long sum, long long cnt) { int i, j, k, p, q, n = max(a - 1, b) + 1; memset(F, 0, sizeof(F)); F[0][0][0] = 1; for (i = 0; i < n; i++) for (j = 0; j <= cnt; j++) for (k = 0; k < 2; k++) ...
24
#include <bits/stdc++.h> using namespace std; int check(int n) { int a; if (n == 0) a = 0; else a = check(n / 10) + n % 10; return a; } int main() { int n; cin >> n; int k = 0; int s = 0; if (n == 10000) { cout << "10800100"; return 0; } while (true) { k++; if (check(k) == ...
3
#include <bits/stdc++.h> using namespace std; long long a[10], ans, w; void dfs(long long i, long long sum) { if (i == 9) { ans = max(ans, sum); return; } for (long long k = 0, j = min(a[i], (w - sum) / i); k < 9 && j >= 0; k++, j--) dfs(i + 1, sum + i * j); } int main() { cin >> w; for (int i = 1...
15
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 50; int a[N]; long long BIT[N], BIT2[N]; void update(int idx, long long val, long long FT[] = ::BIT) { while (idx < N) { FT[idx] += val; idx += (idx & -idx); } } long long query(int idx, long long FT[] = ::BIT) { long long ans = 0; while ...
11
#include <bits/stdc++.h> using namespace std; const int MAXN = 55; int N, K, idx; int dp[MAXN][MAXN]; long long cum[MAXN]; long long A[MAXN]; vector<int> p; long long answer = 0; int rec(int ind, int kk) { if (kk == K && ind == (N + 1)) return 1; if (kk > K || ind > N) return 0; if (dp[ind][kk] != -1) return dp[i...
11