func_code_string
stringlengths
59
71.4k
#include <bits/stdc++.h> using namespace std; const int N1[] = {1, -1}, NINF = (int)0x80808080u, MAXN = 30000, MAXK = 200; long long int dp[MAXN][MAXK + 1][2][2], mdp[MAXN][MAXK + 1][2]; int arr[MAXN], cs[MAXN], n, k; inline long long int max(long long int a, long long int b) { return a > b ? a : b; } ...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long n, r, c, i, d, j = 0, a = 0, b = 0; string s; cin >> s; n = s.size(); r = 1; c = n; while (c > 20) { r++; c = ceil((float)n / (flo...
#include <bits/stdc++.h> using namespace std; int n, p, m; vector<vector<int> > g; vector<char> used; vector<long long> c, vs, es; pair<int, int> dfs(int v) { used[v] = true; pair<int, int> ans(1, (int)g[v].size()); for (int u : g[v]) { if (used[u]) { continue; } pair<i...
#include <bits/stdc++.h> using namespace std; int n, m, max; vector<int> a[100000]; bool visited[100000] = {0}; char col[100000] = { Z }; void f(int x) { queue<int> q; q.push(x); visited[x] = 1; char temp = A ; col[x] = temp; while (!q.empty()) { int p = q.front(); q.pop...
#include <bits/stdc++.h> using namespace std; const long long N = 1e6 + 1; const long long inf = 1e9 + 1; const long long mod = 1e9 + 7; const long double eps = 1e-6; mt19937 rnd(58); struct point { long double x, y; bool operator==(const point &right); }; bool point::operator==(const point &b...
#include <bits/stdc++.h> using namespace std; int main() { string s1, s2; int l; vector<int> v; cin >> s1 >> s2; for (int i = 0; i < s2.length(); i++) { if ((s2[i] - 0 ) > 0) v.push_back(s2[i] - 0 ); } sort(v.begin(), v.end()); int k = v.size() - 1; for (int i = 0; i < s1...
#include <bits/stdc++.h> using namespace std; map<long long int, int> mp; map<long long int, int> mpp; long long int a[100007]; long long int b[100007]; long long int bb[100007]; int main() { int m, p; scanf( %d %d , &m, &p); int i, j; for (i = 0; i < m; i++) scanf( %lld , a + i); for ...
#include <bits/stdc++.h> #pragma GCC optimize(2) using namespace std; const int inf = 1e9; const int NINF = 0xc0c0c0c0; const int maxn = 1e5 + 7; const int bas = maxn / 2; const int Maxn = 1e7 + 7; const double eps = 1e-6; const int mod = (1 << 31) - 1; template <typename T> void read(T &x) { ...
#include <bits/stdc++.h> using namespace std; long long n, l, r; inline long long query(long long l, long long r) { for (long long i = 62; i >= 1; i--) { if ((1ll << i) - 1 >= l && (1ll << i) - 1 <= r) return (1ll << i) - 1; } for (long long i = 62; i >= 0; i--) if (((1ll << i) & l) > 0 &&...
#include <bits/stdc++.h> using namespace std; bool nextper(int num[], int n) { int i; for (i = n - 1; i > 0; i--) { if (num[i] > num[i - 1]) { for (int j = n - 1; j >= i; j--) { if (num[j] > num[i - 1]) { int t = num[j]; num[j] = num[i - 1]; num[i ...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; cout << 6 * n * (n - 1) + 1; return 0; }
#include <bits/stdc++.h> using namespace std; long long bd(string n) { string num = n; long long dec_value = 0; long long base = 1; long long len = num.length(); for (long long i = len - 1; i >= 0; i--) { if (num[i] == 1 ) dec_value += base; base = base * 2; } return dec_val...
#include <bits/stdc++.h> using namespace std; const double eps(1e-8); long long a[100]; long long f[100]; long long dp[100]; long long l, r; long long calc(long long i) { long long ret = 0; for (long long j = (1); j <= (i - 1); ++j) { if (i % j == 0) ret += f[j]; } return ret; } ...
#include <bits/stdc++.h> static const int N = 1 << 17; struct Fenwick { int n; int t[N * 4]; void set(int n) { this->n = n; } void add(int x, int v) { for (int i = x; i <= n; i += (i & -i)) t[i] += v; } void clear(int x) { for (int i = x; i <= n; i += (i & -i)) t[i] = 0; } ...
#include <bits/stdc++.h> using namespace std; int N, P[3], a[3], b[3]; map<char, char> h; int p[] = {666013, 100003, 544513}; int m[] = {123456, 555123, 100055}; string s, t; int main() { std::ios_base::sync_with_stdio(false); h[ N ] = S ; h[ S ] = N ; h[ E ] = W ; h[ W ] = E ; ...
#include <bits/stdc++.h> using namespace std; long long n, q; long long a[755], mx[755]; signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cin >> n >> q; for (long long i = 1; i <= n; i++) cin >> a[i]; for (long long i = 0; i <= n; i++) { long long l ...
#include <bits/stdc++.h> using namespace std; int root[1000005], weight[1000005]; vector<int> vec[26]; int findroot(int x) { while (x != root[x]) { root[x] = root[root[x]]; x = root[x]; } return x; } void merge(int x, int y) { x = findroot(x); y = findroot(y); if (x == y)...
#include <bits/stdc++.h> using namespace std; bool done[333333]; int main(int argc, char *argv[]) { int N; scanf( %d , &N); int pt = N; printf( 1 ); for (int i = 0; i < (N); i++) { int a; scanf( %d , &a); done[a] = true; while (done[pt]) pt--; printf( %d , (i + 2...
#include <bits/stdc++.h> using namespace std; long long int fast_expo(long long int x, long long int p) { if (p == 0) return 1; else if (p % 2 == 0) { long long int t = fast_expo(x, p / 2) % 998244353; return (t * t) % 998244353; } else return (x * (fast_expo(x, p - 1)) % 9982443...
#include <bits/stdc++.h> using namespace std; long long int max(long long int a, long long int b) { if (a > b) return a; else return b; } void solve() { vector<pair<int, int> > points; vector<int> xval, yval; for (int i = 0; i < 3; i++) { int x, y; cin >> x >> y; ...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; long long int A[n]; for (int i = 0; i < n; i++) { cin >> A[i]; } sort(A, A + n); long long ans = 0; for (int i = 0; i < n / 2; i++) { ans += (A[i] + A[n - i - 1]) * (A[i] + A[n - 1 - i]); } ...
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5; int n, root; vector<int> adj[N]; bool ok; int dfs(int v, int p = -1) { int ret = 0; int cnt = 2; if (v == root) cnt++; for (int u : adj[v]) { if (u == p) continue; int res = dfs(u, v); if (res) ret = 2; ...
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e6 + 10; const int mod = 1e9 + 7; const int P = 257; int H[MAXN]; char s[MAXN]; char t[MAXN]; int iP[MAXN]; int add(int a, int b) { return (a + b) % mod; } int mul(long long a, long long b) { return (a * b) % mod; } int range(int l, i...
#include <bits/stdc++.h> using namespace std; int a, ta, b, tb, x, y, sum, A, AA, B, BB; char ch; int main() { ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); ; cin >> a >> ta >> b >> tb >> x >> ch >> y; A = 60 * x + y; AA = A + ta; for (int i = 5 * 60; i <= 1439; i += b) { B = i...
#include <bits/stdc++.h> using namespace std; int n, i; vector<string> pos; string s; set<vector<string> > st; set<vector<string> >::iterator iter; bool srch(vector<string> pos) { if (pos.size() == 1) return true; iter = st.find(pos); if (iter != st.end()) return false; int x = pos.size() ...
#include <bits/stdc++.h> using namespace std; struct block { int x, y; inline bool operator<(const block &cpr) const { if (x != cpr.x) return x < cpr.x; return y < cpr.y; } inline bool operator==(const block &cpr) const { return ((x == cpr.x) && (y == cpr.y)); } }; struct n...
#include <bits/stdc++.h> using namespace std; const int MAXn = 100; int adj[MAXn + 5][MAXn + 5]; int main() { int n; cin >> n; for (int i = 0; i < n; i++) { int u, v, c; cin >> u >> v >> c; u--; v--; adj[u][v] = c; adj[v][u] = -1 * c; } bool dir = 0; i...
#include <bits/stdc++.h> using namespace std; class trio { public: long long first, second, third; }; const long long MOD = 163577857; long long gcdExtended(long long a, long long b, long long *x, long long *y) { if (a == 0) { *x = 0, *y = 1; return b; } long long x1, y1; lo...
#include <bits/stdc++.h> using namespace std; #define sim template < class c #define ris return * this #define dor > debug & operator << #define eni(x) sim > typename enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) { sim > struct rge { c b, e; }; sim > rge<c> range(c i, c j) { return rg...
#include <bits/stdc++.h> using namespace std; int main() { int numRows, numCols; scanf( %d %d n , &numRows, &numCols); bool *rowArray = new bool[numRows]; for (int k = 0; k < numRows; k++) { rowArray[k] = 1; } bool *colArray = new bool[numCols]; for (int k = 0; k < numCols; k++) { ...
#include <bits/stdc++.h> using namespace std; long long lol(long long a, long long b) { return a / b; } int main() { int n, a[300009]; cin >> n; while (n--) { long long s, a, b, c; cin >> s >> a >> b >> c; long long nani = s / c; long long nande = nani / a; long long kiri...
#include <bits/stdc++.h> using namespace std; vector<vector<int> > v; vector<bool> vis; string ans = ; void dfs(int temp) { ans += temp + a ; for (auto it = v[temp].begin(); it != v[temp].end(); ++it) { if (!vis[*it]) { vis[*it] = true; dfs(*it); } } } int main()...
#include <bits/stdc++.h> using namespace std; char types[11]; bool possible[1005][12][11]; int m; int pre[1005][12][11][3]; int main() { scanf( %s , types); scanf( %d , &m); for (int i = 0; i < 11; ++i) for (int d = 0; d <= 10; ++d) possible[0][i][d] = 0; possible[0][0][0] = 1; int...
#include <bits/stdc++.h> using namespace std; int n, k, cnt[1010], ans; int main() { cin >> n >> k; for (int i = 1; i <= n; i++) { int x; cin >> x; cnt[x]++; } for (int i = 1; i <= (n + 1) / 2; i++) { int idx = -1, mx = -1; for (int j = 1; j <= k; j++) { if (c...
#include <bits/stdc++.h> using namespace std; short c1[25001], c2[25001]; int a[12][12]; int main() { int n, m, res = 0; cin >> n >> m; char c; for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) { cin >> c; if (c == W ) a[i][j] = 2; else if (c == P ...
#include <bits/stdc++.h> using namespace std; int n, m; vector<int> g[5000], rev[5000]; bool used[5000]; vector<int> ord; bool curcm[5000]; vector<int> cm; void dfs1(int v) { used[v] = true; for (int to : g[v]) if (!used[to]) { dfs1(to); } ord.push_back(v); } void dfs...
#include <bits/stdc++.h> using namespace std; const int INF = INT_MAX; const long long INFL = LLONG_MAX; const long double pi = acos(-1); int N, M; string s[100]; long long d[1 << 20]; long double f[1 << 20]; int main() { ios_base::sync_with_stdio(0); cout.precision(15); cout << fixed; ...
#include <bits/stdc++.h> using namespace std; const double PI = acos(0) * 2; const double EPS = 1e-8; const long long MOD = 1e9 + 7; const int MAXN = 1e4 + 5; const int oo = 1e9; const double foo = 1e30; template <class T> int getbit(T s, int i) { return (s >> i) & 1; } template <class T> T ...
#include <bits/stdc++.h> using namespace std; using LLI = long long; long long NWD(long long blep, long long b) { return (b == 0) ? blep : NWD(b, blep % b); } long long NWW(long long blep, long long b) { return blep / NWD(blep, b) * b; } const int MX = 3e5 + 400; int n, T[MX]; long long ans[MX]; v...
#include <bits/stdc++.h> using namespace std; const int M = 1e5 + 1; int n; int main() { scanf( %d , &n); n = abs(n); int i = 0; while (1) { int s = i * (i + 1); s /= 2; if (s >= n) { if (s % 2 && n % 2) { printf( %d , i); exit(0); } ...
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { string s; cin >> s; int n = s.size(); if (n % 2 == 1) { for (int i = 0; i < n + 1; ++i) { cout << (i < (n + 1) / 2 ? 4 : 7); } cout << endl; return 0; } int seven = 0, four = 0;...
#include <bits/stdc++.h> using namespace std; long long a[100005]; long long d[800][800], g[800][800]; int w[100]; vector<long long> v; int main() { int n; scanf( %d , &n); for (int i = 1; i <= n; i++) { scanf( %lld , &a[i]); long long x = a[i]; int cnt = 0; while (x) { ...
#include <bits/stdc++.h> using namespace std; const int MAXN = 2e5 + 5; const long long MOD = 1e9 + 7; const long long INF = 1e18; signed main() { int n; cin >> n; vector<long long> a(n); for (int i = 0; i < n; i++) { cin >> a[i]; } multiset<long long> kek; long long ans = 0;...
#include <bits/stdc++.h> using namespace std; int n; long long dp[4]; int a[100005]; string s; int main() { cin >> n; cin >> s; for (int i = 0; i < n; i++) { cin >> a[i]; if (s[i] == h ) dp[0] += a[i]; else if (s[i] == a ) dp[1] = min(dp[0], dp[1] + a[i]); ...
#include <bits/stdc++.h> using namespace std; namespace Work { int c[100010], f[100010], l[100010]; int n, d, s; void solve(FILE* fin, FILE* fout) { fscanf(fin, %d%d%d , &n, &d, &s); for (int i = 0; i < n; i++) fscanf(fin, %d%d%d , c + i, f + i, l + i); vector<int> a, b; a.clear(); b.cle...
#include <bits/stdc++.h> using namespace std; long long a, b, n, ret; long long retr(long long x) { long long t = 0; while (x > 0) { t = 10 * t + (x % 10); x /= 10; } return t; } int main() { int i; cin >> a >> b; ret = retr(b); ret += a; cout << ret; }
#include <bits/stdc++.h> using namespace std; int n; char s[200100]; int x[200100]; int main() { scanf( %d , &n); scanf( %s , s); int mint = 0x3f3f3f3f; for (int i = 0; i < n; i++) { scanf( %d , &x[i]); if (i && s[i] == L && s[i - 1] == R ) mint = min((x[i] - x[i - 1]) /...
#include <bits/stdc++.h> #pragma comment(linker, /STACK:102400000,102400000 ) using namespace std; const int N = 100100; struct point { int id, val, sum; } a[N], b[N]; bool cmp(point x, point y) { return x.val > y.val; } int main() { int n, m; scanf( %d%d , &n, &m); int na = 0; int nb...
#include <bits/stdc++.h> using namespace std; vector<vector<int>> dg, og; vector<bool> vist; vector<int> dist; void bfs(int begin) { vist[begin] = true; dist[begin] = 0; queue<int> pq; pq.push(begin); while (!pq.empty()) { int a = pq.front(); pq.pop(); for (int i = 0; i <...
#include <bits/stdc++.h> #pragma comment(linker, /STACK:128777216 ) using namespace std; const long long LINF = 1000000000000000000LL; const int INF = 1000000000; const long double eps = 1e-9; const long double PI = 3.1415926535897932384626433832795l; void prepare(string s) { if (s.length() != 0) { ...
#include <bits/stdc++.h> using namespace std; int main() { int n, k, i, s; cin >> n >> k; for (i = 1; i <= n + 5; i++) { s = i * k; if (s > n) { cout << s; break; } } return 0; }
#include <bits/stdc++.h> using namespace std; int a[300000]; int main() { int i, j, n, k, m, l = 0, h, b = 0, c; cin >> n; for (i = 0; i < n; i++) cin >> a[i]; for (i = 1; i < n - 1; i++) { if (a[i - 1] == 1 && a[i + 1] == 1 && a[i] == 0) { l++; a[i + 1] = 0; } } ...
#include <bits/stdc++.h> using namespace std; int cnt, h; bool f = true; int main() { long long s, x; cin >> s >> x; h = sizeof(long long) * 8 - __builtin_clzll(max(s, x)) - 1; for (; h >= 0; h--) { if (x & (1LL << h)) cnt++, s -= (1LL << h); else if (s >= (1LL << h + 1)) ...
#include <bits/stdc++.h> using namespace std; char mtx[555][555]; long long comb[555][555]; int n, m, MOD; map<pair<int, int>, long long> dp[555]; long long solve(int col, int empty, int halfempt) { if (empty < 0 || halfempt < 0) return 0; if (col == n) { return empty == 0 && halfempt == 0; ...
#include <bits/stdc++.h> using namespace std; long long a1, a2, b1, b2, c1, c2, d1, d2; int main() { cin >> a1 >> a2 >> b1 >> b2 >> c1 >> c2; for (int q = 0; q < 4; q++) { if (q == 0) { d1 = b1 - (a1); d2 = b2 - (a2); } if (q == 1) { d1 = b1 - (-a1); d2 = ...
#include <bits/stdc++.h> using namespace std; const int N = 100005; int n, m, k, top, a[N]; pair<int, int> op[N * 3]; int main() { scanf( %d%*d%d%d , &n, &m, &k); k--; m /= 2; if (!k) { return puts( 0 0 n ), 0; } for (int i = (int)(1); i <= (int)(n); i++) { int x; sca...
#include <bits/stdc++.h> using namespace std; int main() { int n, i, p = 0; cin >> n; int ara[n]; for (i = 0; i < n; i++) { cin >> ara[i]; } sort(ara + 0, ara + n); for (i = 0; i < n - 1; i++) { if (ara[i] + 1 != ara[i + 1]) p = p - 1 + ara[i + 1] - ara[i]; } cout << ...
#include <bits/stdc++.h> using namespace std; vector<int> g[101]; int n, m; bool visited[101]; void dfs(int v) { visited[v] = true; for (int i = 0; i < g[v].size(); i++) { if (!visited[g[v][i]]) dfs(g[v][i]); } } bool isConnected() { fill(visited, visited + n, false); dfs(0); ...
#include <bits/stdc++.h> using namespace std; const long long N = 3e5 + 55; const long long mod = 1000000007; double add[N << 2], sum[N << 2]; struct node { int pos, h, l, r; } a[N]; map<int, int> b; vector<int> v, v2; int getid(int x) { return lower_bound(v.begin(), v.end(), x) - v.begin() + 1; }...
#include <bits/stdc++.h> using namespace std; int x[55][55], a, b, n, m; int solve() { int res = 1000000000; for (int _n((n - a + 1) - 1), i(0); i <= _n; i++) for (int _n((m - b + 1) - 1), j(0); j <= _n; j++) { int cnt = 0; for (int _n((a)-1), k(0); k <= _n; k++) for (int _...
#include <bits/stdc++.h> using namespace std; int dp[550005]; int main() { int n, d, c, i, j, x, flog; scanf( %d %d , &n, &d); dp[0] = 1; for (i = 0; i < n; i++) { scanf( %d , &c); for (j = 500000; j >= c; j--) { dp[j] |= dp[j - c]; } } int day = 0; x = 0; ...
#include <bits/stdc++.h> using namespace std; template <typename T> T in() { char ch; T n = 0; bool ng = false; while (1) { ch = getchar(); if (ch == - ) { ng = true; ch = getchar(); break; } if (ch >= 0 && ch <= 9 ) break; } while (1) { ...
#include <bits/stdc++.h> using namespace std; const int MOD = 1000000007; int main() { int a[1010], b[1010]; int n; while (cin >> n) { for (int i = 0; i < n; i++) cin >> a[i] >> b[i]; int ans = 0; for (int i = 0; i < n; i++) { int s = a[i]; while (s <= ans) s += b[i];...
#include <bits/stdc++.h> using namespace std; const int M = 100010; int n, i, Ans, b[M], pos[M]; long long A, w1, w2, m, ans, s[M]; struct shit { long long w; int id; } a[M]; bool cmp(shit x, shit y) { return x.w > y.w; } int main() { scanf( %d%I64d%I64d%I64d%I64d , &n, &A, &w1, &w2, &m); ...
#include <bits/stdc++.h> using namespace std; int n; vector<int> A(100); bool f(int m) { int k1 = 0, k2 = 0; for (int i = 0; i < n; i++) { k1 += A[i]; k2 += m - A[i]; } if (k2 > k1) return true; else return false; } int main() { cin >> n; int MAX = -1; ...
#include <bits/stdc++.h> using namespace std; int n, m, a[105][105]; inline int get(int x, int y) { bool vis[11]; for (register int i = 0; i <= 10; i++) vis[i] = 0; vis[a[x - 1][y]] = vis[a[x + 1][y]] = vis[a[x][y - 1]] = vis[a[x][y + 1]] = 1; for (register int i = 1; i <= 10; i++) { if (!vi...
#include <bits/stdc++.h> using namespace std; long long INF = 1e9; const int MAX = 1e5 + 7, N = 1e5 + 3; double pi = acos(-1); long long r, l, k, m, n, ans; int main() { cin >> n; cin >> k >> l; long long m1 = k - 1 + l - 1; long long m2 = n - k + n - l; if (m1 <= m2) { cout << Wh...
#include <bits/stdc++.h> using namespace std; char _c; bool _f; template <class T> inline void IN(T &x) { x = 0, _f = 0; while (_c = getchar(), !isdigit(_c)) if (_c == - ) _f = 1; while (isdigit(_c)) x = x * 10 + _c - 0 , _c = getchar(); if (_f) x = -x; } template <class T> inlin...
#include <bits/stdc++.h> using namespace std; template <typename T> void pr(vector<T> &v) { for (int i = 0; i < (int)(v).size(); i++) cout << v[i] << ; cout << endl; } template <typename T> void pr(vector<vector<T>> &v) { for (int i = 0; i < (int)(v).size(); i++) { pr(v[i]); } } ...
#include <bits/stdc++.h> using namespace std; int const N = 100000; int n; int ans; char digits[8][8]; int ten[8]; bitset<N> isprime; int sum[8]; struct Integer { int i, j, x; Integer(int i, int j, int x) : i(i), j(j), x(x) {} operator int() { return x; } Integer(int x = 0) : x(x), i(-...
#include <bits/stdc++.h> using namespace std; long long GCD(long long x, long long y) { if (y == 0) return x; return GCD(y, x % y); } long long LCM(long long x, long long y) { return (x * y) / (GCD(x, y)); } long long LOGK(long long x, long long k) { if (x >= k) return 1 + LOGK(x / k, k); retu...
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; long long t, n; long long quickpower(int a, int b) { long long res = 1; while (b) { if (b % 2 == 1) res *= a; a *= a; b >>= 1; } return res; } int main() { cin >> t; while (t--) { cin >> n;...
#include <bits/stdc++.h> using namespace std; template <typename T> T gcd(T a, T b) { return b == 0 ? a : gcd(b, a % b); } const int MAXN = 1e5 + 1e4; int n, pos_ = 0; vector<int> g[MAXN]; vector<int> a[MAXN]; vector<int> ans; vector<vector<int>> t(4 * MAXN); vector<int> parent(MAXN), depth(MA...
#include <bits/stdc++.h> using namespace std; int main() { int n, a, b, m = 0, c = 0; scanf( %d , &n); while (n--) { scanf( %d%d , &a, &b); if (a > b) { m++; } else if (a < b) { c++; } } if (m > c) { printf( Mishka ); } else if (m < c) { pr...
#include <bits/stdc++.h> #pragma GCC optimize( O3 ) #pragma GCC optimize( unroll-loops ) #pragma GCC optimize( -Ofast ) using namespace std; void rearrange(long long arr[], long long n) { long long temp[n]; long long small = 0, large = n - 1; long long flag = true; for (long long i = 0; i < n;...
#include <bits/stdc++.h> using namespace std; int main() { long long pow = 1; long long L, R; cin >> L >> R; while (pow * 10 <= R) pow *= 10; if (L < pow) { if (R < pow * 5) cout << R * (pow * 10 - 1 - R) << endl; else cout << pow * 5 * (pow * 5 - 1) << endl; } el...
#include <bits/stdc++.h> using namespace std; long long n, l, k, ultim; map<int, int> cnt; int main() { cin >> n >> k; for (int i = 0; i <= 63; i++) if ((n >> i) & 1) cnt[i]++, l++; if (l > k) { cout << No ; return 0; } for (int i = 63; i >= -63; i--) { if (l + cnt[i...
#include <bits/stdc++.h> using namespace std; void in(int &x) { register int c = getchar(); x = 0; for (; (c < 48 || c > 57); c = getchar()) ; for (; c > 47 && c < 58; c = getchar()) { x = (x << 1) + (x << 3) + c - 48; } } const int N = 1 << 24; long long dp[N]; string s[1000...
#include <bits/stdc++.h> using namespace std; template <typename T> bool chkmax(T &x, T y) { return x < y ? x = y, true : false; } template <typename T> bool chkmin(T &x, T y) { return x > y ? x = y, true : false; } int readint() { int x = 0, f = 1; char ch = getchar(); while (ch < ...
#include <bits/stdc++.h> using namespace std; inline int inp() { return 0; } inline int inp(bool& A) { if (cin >> A) return 1; return -1; } inline int inp(char& A) { return scanf( %c , &A); } inline int inp(int& A) { return scanf( %d , &A); } inline int inp(float& A) { if (cin >> A) return 1;...
#include <bits/stdc++.h> using namespace std; int main() { string ans = , s; int n; cin >> s >> n; for (int i = 0; i < n; i++) { string t; cin >> t; if (t.length() >= s.length()) if (s == t.substr(0, s.length())) if (ans == || ans > t) ans = t; } if (...
#include <bits/stdc++.h> using namespace std; inline bool valid(int64_t x, int64_t y, int64_t n, int64_t m) { return (x >= 0 && x < n && y >= 0 && y < m); } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int64_t n, m, q; cin >> n >> m >> q; vector<string> v(n); for (in...
#include <bits/stdc++.h> using namespace std; const int Mod = 998244353; int add(int a, int b) { return a + b >= Mod ? a + b - Mod : a + b; } int dec(int a, int b) { return a - b < 0 ? a - b + Mod : a - b; } int mul(int a, int b) { return 1ll * a * b % Mod; } void Add(int &a, int b) { a = add(a, b); } voi...
#include <bits/stdc++.h> using namespace std; char inp[1000010]; char out[1000010]; int main() { int i, j, dot_index, nonzero_index = 0, start, end, p = 0, B; cin >> inp; int len = strlen(inp); dot_index = len; for (i = 0; inp[i] == 0 || inp[i] == . ; i++) ; for (j = len - 1; in...
#include <bits/stdc++.h> using namespace std; const int INF = 0x7fffffff; const long double eps = 1e-8; const int MAXN = 1111; int n, m; char g[MAXN][MAXN]; int col[MAXN][MAXN]; int sz[MAXN * MAXN]; char ans[MAXN][MAXN]; bool vis[MAXN][MAXN]; const int dx[4] = {-1, 0, 1, 0}; const int dy[4] = {0...
#include <bits/stdc++.h> using namespace std; #define int long long int32_t main() { int t; cin >> t; while (t--) { int n; cin >> n; int c=0,i=1; while(n>0){ c++; n-=i; i+=2; } cout<<c<<endl; ...
#include <bits/stdc++.h> using namespace std; int n; bool vis[100][100]; char g[100][100]; void dfs(int a, int b) { if (vis[a][b] || a > n || a < 1 || b < 1 || b > n || g[a][b] == 1 ) return; vis[a][b] = 1; dfs(a + 1, b); dfs(a, b + 1); dfs(a - 1, b); dfs(a, b - 1); } int dist(pai...
#include <bits/stdc++.h> using namespace std; typedef vector<vector<int>> graph; ifstream in( buffcraft.in , ios::in); ofstream out( buffcraft.out , ios::out); int main() { double m, R, ans = 0; cin >> m >> R; for (int x = 2; x < m; x++) ans += ((x - 1) * 2 + 2 * sqrt(2.0)) * 2 * (m - x); ...
#include <bits/stdc++.h> using namespace std; struct rect { int x1, y1, x2, y2; }; int main() { ios_base::sync_with_stdio(false); int n; cin >> n; vector<rect> v(n); int minx = 1000000000; int miny = 1000000000; for (int i = 0; i < n; ++i) { cin >> v[i].x1 >> v[i].y1 >> v[i...
#include <bits/stdc++.h> using namespace std; int n, m; pair<long long, int> p[200005]; int main(int argc, char const *argv[]) { ios_base::sync_with_stdio(false); cin >> n; for (int i = 0; i < (n); i++) { cin >> p[i].first; p[i].second = i; } priority_queue<pair<long long, int>, ...
#include <bits/stdc++.h> using namespace std; int main() { int n; while (cin >> n) { int ans = n / 2; if (n % 2 == 0) ans -= 1; cout << ans << endl; } return 0; }
#include <bits/stdc++.h> // Include every standard library using namespace std; typedef long long LL; typedef pair<int, int> pii; typedef pair<LL, LL> pll; typedef pair<string, string> pss; typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<pii> vii; typedef vector<LL> vl; typedef vec...
#include <bits/stdc++.h> using namespace std; int main() { int i, n, rem, k, f = 0, c = 0; cin >> n; vector<string> s; if (n == 0) { cout << zero ; return 0; } while (n != 0) { rem = n % 10; n = n / 10; c++; if (rem == 0) { rem = n % 10; i...
#include <bits/stdc++.h> using namespace std; long long int trash = 0; long long int a[50], c[50]; long long int value2power[50]; long long int n, m; priority_queue<long long int> mainPQ; vector<long long int> queueArray; bool test(priority_queue<long long int> &PQ, long long int *b, long lo...
#include <bits/stdc++.h> using namespace std; const long long N = 1e6; const long long mod = 1e9 + 7; vector<long long> primes; bool not_prime[N]; void sieve_of_eratosthenes(long long n) { for (long long i = 2; i < N; i++) { if (not_prime[i]) continue; primes.push_back(i); for (long lo...
#include <bits/stdc++.h> using namespace std; vector<long long> a[100005], vis(100005, 0), tree[100005], lev[2]; long long n, m, k; set<long long> v; stack<long long> st; void dfs(long long node, long long par) { vis[node] = 1; st.push(node); for (auto i : a[node]) if (!vis[i] and v.find(i...
#include <bits/stdc++.h> using namespace std; bool comp(pair<unsigned long long, unsigned long long> a, pair<unsigned long long, unsigned long long> b) { unsigned long long s1, s2, h1, h2; tie(s1, h1) = a; tie(s2, h2) = b; if (s1 * h2 > s2 * h1) return true; return false; } int m...
#include <bits/stdc++.h> using namespace std; long long s[1000], x[1000], size; void tob(long long a, long long arr[], long long& len) { len = 0; while (a != 0) { arr[len++] = a % 2; a /= 2; } } long long DP(long long n, long long carry) { if (n >= size) return 1 - carry; if (x...
#include <bits/stdc++.h> using namespace std; int n, m, d[210000]; long long cnt[210000]; long long solve() { cnt[1] *= 2; cnt[n] *= 2; int Min = cnt[1], Max = cnt[1]; for (int i = 1; i <= n; ++i) { if (Min > cnt[i]) Min = cnt[i]; else if (Max < cnt[i]) Max = cnt[i]; ...
#include <bits/stdc++.h> using namespace std; int gcd(int a, int b) { return b ? gcd(b, a % b) : a; } int main() { int n, num[105], ans; scanf( %d , &n); for (int i = 1; i <= n; i++) cin >> num[i]; sort(num + 1, num + 1 + n); ans = num[1]; for (int i = 2; i <= n; i++) ans = gcd(ans, num[i]...