func_code_string
stringlengths
59
71.4k
#include <bits/stdc++.h> using namespace std; vector<int> v, vv, vv2; int main() { int t, n, a[1000], k, f = 0; cin >> n; if (n == 3) { for (int i = 1; i <= n; i++) { if (i % 2 != 0) { for (int j = 1; j <= n; j++) { if (j % 2 != 0) { cout << W ; ...
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e5 + 5; int tree[4 * MAXN]; int maxTree[4 * MAXN]; int p[MAXN]; int n; void push(int v) { if (tree[v]) { tree[2 * v] += tree[v]; tree[2 * v + 1] += tree[v]; maxTree[2 * v] += tree[v]; maxTree[2 * v + 1] += tree[v];...
#include <bits/stdc++.h> #pragma optimize( SEX_ON_THE_BEACH ) #pragma GCC optimize( unroll-loops ) #pragma GCC optimize( O3 ) #pragma GCC optimize( fast-math ) using ll = long long int; using ull = long long int; using dd = double; using ldd = long double; namespace Hashes { const int mod197 = 1e9 +...
#include<bits/stdc++.h> using namespace std; using ll = long long; using pii = pair<int, int>; using pll = pair<ll, ll>; using vi = vector<int>; using vl = vector<ll>; using vii = vector<pii>; using vll = vector<pll>; #define fi first #define se second #define sz(c) ((int)(c).size()) #define al...
#include <bits/stdc++.h> using namespace std; int n; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n; char ch; int Sum = 0, Count = 0; n /= 2; for (int i = 1; i <= n; i++) { cin >> ch; if (ch == 4 || ch == 7 ) { Count++; ...
#include <bits/stdc++.h> using namespace std; int main(void) { int n; cin >> n; int ans = 1; for (int i = 1; i < n; i++) { ans *= 3; ans %= 1000003; } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 10; vector<int> v[maxn]; int ma = 0; int h = 0; int f = 0; int root = 0; int g[maxn]; bool mark[maxn]; void dfs(int k) { if (mark[k] == false) { mark[k] = true; } else { return; } for (int i = 0; i < v[k...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long n, m, k; cin >> n >> m >> k; map<long long, long long> cnt1, cnt2; vector<long long> a(n), b(m); for (long long i = 0; i < n; i++) { cin >> a[i]...
#include <bits/stdc++.h> using namespace std; int gcd(int a, int b) { return (b != 0 ? gcd(b, a % b) : a); } int lcm(int a, int b) { return (a / gcd(a, b) * b); } int R[] = {1, -1, 0, 0, 1, -1, -1, 1}; int C[] = {0, 0, 1, -1, 1, -1, 1, -1}; int KR[] = {-2, -2, -1, 1, 2, 2, -1, 1}; int KC[] = {1, -1, 2, 2,...
#include <bits/stdc++.h> using namespace std; long long a[11111111]; long long b[11111111]; int len = 0; long long gcd(long long a, long long b) { return a == 0 ? b : gcd(b % a, a); } int counter(int x) { int res = 0; while (x) { res++; x /= 10; } return res; } void printK(in...
#include <bits/stdc++.h> using namespace std; int q, c, i1, i2; long long v, u, w; bool flag; map<long long, long long> cost; vector<long long> a, b; void Rule() { for (int i = i1 - 1; i >= 0; --i) { cost[a[i]] += w; } for (int i = i2 - 1; i >= 0; --i) { cost[b[i]] += w; } } ...
#include <bits/stdc++.h> using namespace std; int n, m; int a[1000100]; long long calc(int idx) { long long ans = 0; int x = -1, y = -1; for (int i = 0; i < idx; i += m) { ans += (long long)abs(a[i] - a[idx]) * 2; x = i; } for (int i = n - 1; i > idx; i -= m) { ans += (long...
#include <bits/stdc++.h> using namespace std; char _buf[100000], *_p1 = _buf, *_p2 = _buf; inline int gi() { 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 << 3) + (x << 1)...
#include <bits/stdc++.h> using namespace std; void solution1(int a, int b, map<pair<int, int>, bool>& mp1, map<pair<int, int>, int>& mp2) { if (a == b) { mp2[{a, b}] = a; return; } int j = a; while (j <= b) { if (j == a) { if (mp1[{j + 1, b}]) { m...
#include <bits/stdc++.h> using namespace std; int main() { long long int n, k; cin >> n >> k; vector<pair<long long int, long long int>> v; for (long long int i = 0; i < n; i++) { long long int x; cin >> x; v.push_back({x, i + 1}); } sort(v.begin(), v.end()); vector<lon...
#include <bits/stdc++.h> using namespace std; int arr[200005]; map<int, int> mp; int main() { int n, k; cin >> n >> k; vector<int> v; for (int i = 0; i < n; i++) { int a; cin >> a; v.push_back(a); } sort(v.begin(), v.end()); int ans = 1e9; for (int i = 0; i < n;...
#include <bits/stdc++.h> using namespace std; struct A { int a[500000]; int& operator[](const int x) { return a[x + 250000]; } } f[2]; int a, b, k, t, m; int main() { scanf( %d%d%d%d , &a, &b, &k, &t); m = 2 * k * t + 200; f[0][a - b] = 1; for (int i = 1; i <= t << 1; ++i) { long...
#include <bits/stdc++.h> using namespace std; vector<long long int> vec; map<int, int> mp; multiset<long long int> st; long long int n, m; string s, s1, s2; int arr[] = {4, 8, 15, 16, 23, 42}; int main() { long long int i, j, k, c = INT_MAX, ans = 0, t, z, x, y; for (i = 0; i < 6; i++) mp[arr[i]...
#include <bits/stdc++.h> using namespace std; inline void readInt(int &x) { int neg = 1; char ch; while (!isdigit(ch = getchar())) { if (ch == - ) { neg = -1; } } x = ch - 0 ; while (isdigit(ch = getchar())) { x = x * 10 + ch - 0 ; } x *= neg; } int N...
#include <bits/stdc++.h> int kx[8] = {+2, +2, -2, -2, +1, +1, -1, -1}; int ky[8] = {+1, -1, +1, -1, +2, -2, +2, -2}; int d9x[9] = {+1, +1, +1, +0, +0, +0, -1, -1, -1}; int d9y[9] = {+1, +0, -1, +1, +0, -1, +1, +0, -1}; int dx4[4] = {+0, +0, +1, -1}; int dy4[4] = {+1, -1, +0, +0}; long long int gcd(unsigne...
#include <bits/stdc++.h> using namespace std; vector<long long> adj[200001]; long long a[200001]; vector<long long> start; stack<long long> last; long long ans; bool f; void dfs(long long); signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long n; ...
#include <bits/stdc++.h> using namespace std; int output = 0; int N, consCats; vector<int> adj[999999]; int vCats[999999]; bool visited[999999]; bool leafs[999999]; bool aux; void deep(int s, bool visited[], vector<int> adj[], int consCats, int var, int vCats[]); int main() { cin >> ...
#include <bits/stdc++.h> using namespace std; using namespace std; long long i, n, x, m, k, ans; int main() { cin >> n; x = n; while (x) { x /= 10; m++; } ans = n * m + m - 1; k = 1; for (i = 0; i < m - 1; i++) { k *= 10; ans -= k; } cout << ans << end...
#include <bits/stdc++.h> using namespace std; int ost(int k, int res) { int ans = 0; while (k < (double)res / 2) { ans++; k *= 2; } return ans; } int main() { int n, k; cin >> n >> k; vector<int> a(n); for (int i = 0; i < n; i++) cin >> a[i]; sort(a.begin(), a.end...
#include <bits/stdc++.h> using namespace std; string scan(); const int mod = 1000000007; const int MAXN = 10010; int sta[MAXN], stb[MAXN]; long long s, x; long long memo[MAXN][2]; long long bt(int i, int rem) { if (i > 52 && rem == 0) return 1; if (i == 60) return 0; long long &ret = memo[i]...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(NULL); ; int n; cin >> n; int a[n]; for (int i = 0; i < n; i++) cin >> a[i]; int mi = *min_element(a, a + n); int p = -1; int f = 0; int ans = INT_MAX; for (int i = 0; i < ...
#include <bits/stdc++.h> using namespace std; int a[20007]; int main() { ios_base::sync_with_stdio(0); int t = 1; while (t--) { int n; cin >> n; map<int, int> mp; for (int i = 0; i < n; i++) { int x, y; cin >> x >> y; mp[x] = y; if (mp[x] == -1 *...
#include <bits/stdc++.h> using namespace std; vector<long long> v[100010]; long long dp[100010]; void dfs(long long i, long long first) { dp[first]++; for (auto x : v[i]) { dfs(x, first + 1); } } signed main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); ; long l...
#include <bits/stdc++.h> using namespace std; struct node { int num; string ss; }; unordered_map<string, node> mm; int main() { ios::sync_with_stdio(false); cin.tie(0); int n; while (cin >> n) { mm.clear(); for (int i = 0; i < n; i++) { string s; cin >> s; ...
#include <bits/stdc++.h> using namespace std; const long long N = 100005; long long p = 1e9 + 7; int32_t main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); ; long long n; cin >> n; long long sum = 0; for (long long i = 1; i <= n; i++) { long long a; cin >> a; ...
#include <bits/stdc++.h> #pragma comment(linker, /STACK:102400000,102400000 ) using namespace std; const int maxn = 2e5 + 10; const int inf = 0x7fffffff; const long long INF = 9E18; const int mod = 1e9 + 7; const long long mod2 = 1e9 + 9; const int eps = 1e-7; const double pi = acos(-1.0); template...
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const long double pi = acos(-1); const int MOD = 1e9 + 7; int ocor[26]; int prefix[100010][26]; int blaublau[100010]; string s, t; bool confere(int idx) { int cu = blaublau[idx]; int aux[26]; for (int i = 0; i < 26; ...
#include <bits/stdc++.h> using namespace std; int n, k; vector<int> digits; vector<vector<bool>> dp; vector<int> bin_digits; bool can; void In() { cin >> n >> k; digits.resize(n); string next; for (int i = 0; i < n; i++) { cin >> next; digits[i] = stoi(next, 0, 2); } } ...
#include <bits/stdc++.h> using namespace std; const long long N = 1e5 + 5; void solve() { int n; cin >> n; vector<int> v(n); map<int, int> mpp; for (int i = 0; i < n; i++) { cin >> v[i]; mpp[v[i]]++; } int ans1 = 0, ans2 = 0; bool flag = false; for (int i = 0; i <= ...
#include <bits/stdc++.h> using namespace std; int main() { int n; scanf( %d , &n); int a[1010]; for (int i = 0; i < n; i++) { scanf( %d , &a[i]); } sort(a, a + n); if (a[0] == 1) { printf( -1 n ); } else { printf( 1 n ); } }
#include <bits/stdc++.h> using namespace std; const uint64_t seed = std::chrono::system_clock::now().time_since_epoch().count(); mt19937_64 rnd(seed); const int MOD = 998244353; struct Dinic { struct Edge { int from, to; long long cap, flow; Edge(int u, int v, long long c) : from(u...
#include <bits/stdc++.h> using namespace std; const int INF = (1 << 30) + 7; const int N = 1e5 + 7; int main() { ios::sync_with_stdio(false); int q, l, r, d, ans; cin >> q; while (q--) { cin >> l >> r >> d; ans = (r / d + 1) * d; if (d < l) ans = d; else a...
#include <bits/stdc++.h> using namespace std; template <class T> inline void read(T& x) { bool fu = 0; char c; for (c = getchar(); c <= 32; c = getchar()) ; if (c == - ) fu = 1, c = getchar(); for (x = 0; c > 32; c = getchar()) x = x * 10 + c - 0 ; if (fu) x = -x; }; template <...
#include <bits/stdc++.h> using namespace std; void read() {} int main() { read(); string s; while (cin >> s) { int l = s.size(); string ans; bool f = 0; for (int i = 0; i < l; i++) { if (i != 0) { if (s[i] == a && i + 1 < l - 1 && s[i + 1] == t && !f) { ...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); int n; cin >> n; int arr[n]; for (int i = 0; i < n; i++) cin >> arr[i]; sort(arr, arr + n); int c[1005] = {0}; int u[1005] = {0}, t = 0; for (int i = 0; i < n; i++) { if (c[a...
#include <bits/stdc++.h> using namespace std; long long int a, b, c, d, n, ans = 0; int main() { cin >> a; cin >> b; cin >> c; cin >> d; if ((a + b > c && a + c > b && b + c > a) || (a + b > d && a + d > b && b + d > a) || (a + d > c && a + c > d && d + c > a) || (d + b...
#include <bits/stdc++.h> using namespace std; const int inf = 0x3f3f3f3f; const int _inf = 0xc0c0c0c0; const long long INF = 0x3f3f3f3f3f3f3f3f; const long long _INF = 0xc0c0c0c0c0c0c0c0; const long long mod = (int)1e9 + 7; const int N = 3e5 + 100; vector<int> vc[N], e[N]; int col[N]; int vis[N]; ...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; for (int l = 0; l < n; l++) { string b; cin >> b; string a; a = b[0]; string c; for (int i = 1; i <= b.length(); i += 2) { c = b[i]; a += c; } cout << a << n ; ...
#include <bits/stdc++.h> using namespace std; const int sz = 1500000; const long long MAX = 10000000000000000; template <typename T> T abs(T a) { return a < 0 ? -a : a; } int main() { int n, m; cin >> n >> m; vector<vector<int> > graph(n); for (long long i = 0; i < m; i++) { int ...
#include <bits/stdc++.h> int main() { int a, b; scanf( %d%d , &a, &b); if (a > b) printf( %d %d n , b, (a - b) / 2); else printf( %d %d n , a, (b - a) / 2); return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; char grid[n][n]; int hash_count = 0, cross = 0; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { cin >> grid[i][j]; if (grid[i][j] == # ) hash_count++; } } for (int i = 0; ...
#include <bits/stdc++.h> using namespace std; vector<int> m = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; int y, m1, d1, y2, m2, d2, s[13]; bool is_leap(int x) { if (x % 100 == 0) return !(x % 400); return !(x % 4); } int main() { scanf( %d:%d:%d , &y, &m1, &d1); scanf( %d:%d:%d , &y2,...
#include <bits/stdc++.h> using namespace std; int n; int main() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); int n, k; cin >> n >> k; vector<int> v(n); long long sum = 0; for (int i = 0; i < n; i++) { cin >> v[i]; sum += v[i]; } if (sum % k != 0) cout ...
#include <bits/stdc++.h> using namespace std; int n, m; long long a[200200]; int f(int x) { return ((x % n) + n) % n; } int main() { scanf( %d%d , &n, &m); m--; for (int i = (0); i < (n); i++) cin >> a[i]; int p = m; for (int i = (1); i <= (n); i++) if (a[p] >= a[f(m + i)]) p = f(m +...
#include <bits/stdc++.h> using namespace std; vector<long long> v[10001]; long long n, ass1, ass2; int main() { v[1].push_back(1); v[1].push_back(2); v[2].push_back(1); v[2].push_back(3); v[3].push_back(2); v[3].push_back(3); cin >> n; ass1 = ass2 = 3; while (ass1 + ass2 <= n...
#include <bits/stdc++.h> using namespace std; int cnt = -1; struct node { bool op; string val; int op1, op2; int type; node() { op = 0; val = ; type = 0; } } m[5020]; map<string, int> ind; inline int cti(char i) { return (int)(i - 0 ); } vector<string> vct; b...
#include <bits/stdc++.h> using namespace std; typedef struct T { int ind; int st; int ds; bool operator<(const T &one) const { if (st != one.st) return st < one.st; return ds < one.ds; } } gr; gr grps[10000]; int n; vector<int> mv; int valid(int nt) { int en = 0; fo...
#include<iostream> #include<cstdlib> #include<cstdio> #include<cmath> #include<iomanip> #include<cstring> #include<algorithm> #include<ctime> using namespace std; const int MAXN=2010; int read() { int kkk=0,x=1; char c=getchar(); while((c< 0 || c> 9 ) && c!= - ) c=getchar(); if(c== - ...
#include <bits/stdc++.h> using namespace std; int read() { char ch = getchar(); int x = 0, fl = 1; for (; !isdigit(ch); ch = getchar()) if (ch == - ) fl = -1; for (; isdigit(ch); ch = getchar()) x = (x << 3) + (x << 1) + (ch - 0 ); return x * fl; } const int NN = 500000 + 17; void ...
#include <bits/stdc++.h> using namespace std; int getDiff(int n, string s1, string s2) { int cnt = 0; for (int i = 0; i < n; i++) { if (s1[i] != s2[i]) { cnt++; } } return cnt; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n; cin >> n; ...
#include <bits/stdc++.h> using namespace std; int n, l[1010], r[1010]; char a[1010]; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cin >> n; for (int i = 1; i < n; i++) cin >> a[i]; l[1] = 0; for (int i = 1; i < n; i++) { if (a[i] == R ) l[i + 1] = l[i] + 1; if ...
#include <bits/stdc++.h> using namespace std; const int N = 5e3 + 99; complex<int> read() { int x, y; cin >> x >> y; return complex<int>(x, y); } long double dist(complex<int> a, complex<int> b) { return hypot(abs(a.real() - b.real()), abs(a.imag() - b.imag())); } complex<long double> conv...
#include <bits/stdc++.h> using namespace std; #pragma comment(linker, /STACK:64000000 ) const int N = 5e3 + 10; int n; int t[N]; int cnt[N]; int res[N]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> n; for (int i = 1; i <= n; i++) { cin >> t[i]; } fo...
#include <bits/stdc++.h> using namespace std; long long freq[100005]; int32_t main() { long long n; cin >> n; string s; cin >> s; sort(s.begin(), s.end()); reverse(s.begin(), s.end()); cout << s[0]; for (long long i = 1; i < n; i++) { if (s[i] == 0 ) cout << s[i]; } ...
#include <bits/stdc++.h> using namespace std; const long long INF = 1e18; const int NMAX = 1e6; struct eq { int x, c; bool operator<(const eq &aux) const { return x < aux.x; } }; eq a[200005], b[200005]; stack<pair<int, int> > st; void prec(int &n, eq a[]) { for (int i = 1; i <= n; ++i) scan...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); int t; cin >> t; while (t--) { int n, x; cin >> n >> x; ; int a[n]; int b[n]; for (int i = 0; i < n; i++) { cin >> a[i]; cin >> b[i]; ...
#include <bits/stdc++.h> using namespace std; void solve() { long long int n, a, s = 0, c = 0; cin >> n; for (long long int i = 0; i < n; i++) { cin >> a; s += a; } for (long long int i = 1; i <= 5; i++) { s += i; if (s % (n + 1) != 1) c++; s -= i; } cout <<...
#include <bits/stdc++.h> using namespace std; const long long mod = 1000000007; const long long inf = mod * mod; const long long d2 = (mod + 1) / 2; const long double EPS = 1e-9; const long double PI = acos(-1.0); int ABS(int a) { return max(a, -a); } long long ABS(long long a) { return max(a, -a); } ...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(), cout.tie(); long long n, k; cin >> n >> k; long long a[n]; map<long long, long long> mp; for (int i = 0; i < n; i++) { cin >> a[i]; mp[a[i]]++; } sort(a, a + n); int i =...
#include <bits/stdc++.h> using namespace std; int N; string s; int pows[4] = {0, 0, 0, 0}; void Desc(int q) { if (q <= 1) return; switch (q) { case 2: pows[0]--; break; case 3: pows[1]--; break; case 4: pows[0] -= 2; break; case 5...
#include <bits/stdc++.h> using namespace std; vector<int> status(26); vector<vector<int> > adjList(200000); vector<string> names(100); vector<int> ts; vector<int> processing(26); void dfs(int u, bool &valid) { status[u] = 1; processing[u] = true; for (int j = 0; j < adjList[u].size(); j++) { ...
#include <bits/stdc++.h> using namespace std; const int N = 123456; char buffer[N]; string solve(string s, int k) { const int n = s.size(); sort(s.begin(), s.end()); string res; int ptr = 0; while (ptr < n) { int p = ptr; char mini = ~ ; char maxi = 0 ; assert(mini...
#include <bits/stdc++.h> using namespace std; int main() { int t, fl; cin >> t; while (t--) { fl = 1; int a, b, c, d, x, y, x1, y1, x2, y2; cin >> a >> b >> c >> d >> x >> y >> x1 >> y1 >> x2 >> y2; int p = x - a + b, q = y - c + d; if ((p >= x1 && p <= x2) && (x1 < x2 || a...
#include <bits/stdc++.h> using namespace std; int main() { int N; cin >> N; string s; cin >> s; int current = N; int count = 0; while (true) { if (current >= s.size()) break; set<char> vs; vs.insert(s[current - 1]); vs.insert(s[current - 2]); vs.insert(s[cur...
#include <bits/stdc++.h> using namespace std; int x[] = {-1, -1, 1, 1}; int y[] = {-1, 1, -1, 1}; int main() { int i, j, k, l, m = 0, n, cnt = 0; cin >> n; char a[n + 10][n + 10]; for (i = 0; i < n; i++) for (j = 0; j < n; j++) cin >> a[i][j]; for (i = 1; i < n - 1; i++) for (j =...
#include <bits/stdc++.h> using namespace std; int main() { long int n, h, A, B, k, S, T, ta, tb, fa, fb; cin >> n >> h >> A >> B >> k; for (long int i = 0; i < k; i++) { S = 0; cin >> ta >> fa >> tb >> fb; if (ta == tb) { S = abs(fa - fb); } else { if (fa < A) { ...
#include <bits/stdc++.h> using namespace std; long long power(long long a, long long b, long long p) { if (a == 0) return 0; long long res = 1; a %= p; while (b > 0) { if (b & 1) res = (res * a) % p; b >>= 1; a = (a * a) % p; } return res; } int32_t main() { std::io...
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 10; const int INF = 1.01e9; const long long INF18 = 1.01e18; int main() { int n; long long C; scanf( %d%lld , &n, &C); vector<long long> a(n); vector<long long> b(n - 1); for (int i = 0; i < (n); i++) { scanf( %lld...
#include <bits/stdc++.h> using namespace std; int x[1000 + 1], y[1000 + 1]; void solve() { int n; cin >> n; for (int i = 0; i < n + 1; i++) cin >> x[i] >> y[i]; int res = 0; for (int i = 1; i < n; i++) { double X = x[i], Y = y[i]; int cnt = 0; if (x[i - 1] == x[i]) { ...
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; int fac[4]; fac[0] = 1; fac[1] = 1; fac[2] = 1; for (int i = 3; i < 10; i++) { int y1213 = 100; int n1113; vector<int> ans112; int tempor = 100; } while (t--) { int n; ...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> v; for (int i = 1; i * i <= n; i++) { if (n % i == 0) { v.push_back(i); if (i != n / i) { v.push_back(n / i); } } } sort(v.begin(), v.end()); int ans = 0;...
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 20; long long int c[15][maxn]; int lowbit(int x) { return x & (-x); } void upDate(int pos, long long int val, int which) { while (pos <= maxn - 20) { c[which][pos] += val; pos += lowbit(pos); } } long long int ask(int...
#include <bits/stdc++.h> using namespace std; const int N = 100005; int n, m, q; int c[N]; vector<pair<long long, int> > girl[N]; int head[N], to[N * 2], pre[N * 2], tot; void addedge(int u, int v) { to[++tot] = v; pre[tot] = head[u]; head[u] = tot; } int L[N], R[N], dfn, id[N], dep[N], to...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n, v, a, b, x; cin >> n >> v; int mp[3002] = {0}; for (int i = 0; i < n; i++) { cin >> a >> b; mp[a] += b; } int prev = 0, ans = 0; for (int i...
#include <bits/stdc++.h> using namespace std; struct node { node *c[3]; bool flag; }; node *root; void insert(string a) { node *cur = root; for (int i = 0; i < a.size(); i++) { if (!(cur->c[a[i] - a ])) cur->c[a[i] - a ] = new node(); cur = cur->c[a[i] - a ]; } cur->flag...
#include <bits/stdc++.h> using namespace std; const int MOD = 1000000007; const int INF = int(1e9); const int MAX = 200; int num[MAX], mixt[MAX]; int n; bool substring(string &a, string &b) { for (int i = 0; i < n; i++) { bool found = true; for (int j = 0; j < 3; j++) { if (a[i + j...
#include <bits/stdc++.h> using namespace std; long long mod(long long a, long long b) { if (a % b < 0) { return a % b + b; } return a % b; } long long mod_exp(long long a, long long b, long long c) { long long res = 1; a = a % c; while (b > 0) { if (b % 2 == 1) { res ...
#include <bits/stdc++.h> using namespace std; double h, luas, top; int n; double f(double x) { return ((x / h + top / h) * (x - top)) / 2; } double binser(double l, double r) { double ret = 0; for (int i = 1; i <= 100; i++) { double mid = (l + r) / 2; if (f(mid) >= luas) { ret = mi...
#include <bits/stdc++.h> using namespace std; unsigned long long n, H; unsigned long long bound[60]; unsigned long long cnt(unsigned long long p, unsigned long long h, unsigned long long n) { if (h == 1) { if (p == 0 && n == 1) return 1; if (p == 1 && n == 2) return 1; ...
#include <bits/stdc++.h> using namespace std; template <typename T, typename U> std::pair<T, U> operator+(const std::pair<T, U> &l, const std::pair<T, U> &r) { return {l.first + r.first, l.second + r.second}; } typedef void (*callback_function)(void); const long long INF64 = 1e18; const long long INF3...
#include <bits/stdc++.h> using namespace std; long long int gcd(long long int a, long long int b) { if (a < b) swap(a, b); if (b == 0) return a; else gcd(b, a % b); } int main() { long long int ncr[62][62]; for (long long int i = 0; i < 62; i++) { ncr[i][0] = 1; ncr[i...
#include <bits/stdc++.h> using namespace std; int main() { long n, q; cin >> n >> q; long i, j; int** a = new int*[2]; for (i = 0; i < 2; ++i) { a[i] = new int[n + 2]; for (j = 0; j < n + 2; j++) { a[i][j] = 0; } } long res = 0; long x, y; while (q--) { ...
#include <bits/stdc++.h> #pragma warning(disable : 4996) using namespace std; using ld = long double; template <class T> using Table = vector<vector<T>>; const ld eps = 1e-9; template <class S, class T> ostream &operator<<(ostream &os, const pair<S, T> v) { os << ( << v.first << , << v.second ...
#include <bits/stdc++.h> using namespace std; #define ll long long int #define mp make_pair //ll const MAX_N=100000; ll const MAX_A = (ll)1e9 + 1; const ll MOD = 1e9 + 7; void solve() { ll n, l,u,v,w,n1,n2,n3,h,sum=0,suma=0,sumb=0,sumc=0,minia=MAX_A,minib=MAX_A,minic=MAX_A, ansa,ansb,ansc...
#include <bits/stdc++.h> using namespace std; priority_queue<int, vector<int>, greater<int> > q; int main() { int n, m; while (cin >> n) { long long sum = 0; if (!q.empty()) { q.pop(); } while (n--) { scanf( %d , &m); if (!q.empty() && m > q.top()) { ...
#include <bits/stdc++.h> using namespace std; int main() { char str[100]; int n, z; cin >> z; while (z--) { cin >> str; n = strlen(str); if (n > 10) { cout << str[0] << n - 2 << str[n - 1] << endl; } else cout << str << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long v1, v2, v3, vm; long long u1, u2, u3; cin >> v1 >> v2 >> v3 >> vm; for (u1 = v1; u1 <= 2 * v1; u1++) { for (u2 = v2; u2 <= 2 * v2; u2++) { for (u3 = v...
#include <bits/stdc++.h> using namespace std; int main() { double l, r, x, y, k, i, f = 0; cin >> l >> r >> x >> y >> k; for (i = x; i <= y; i++) { if ((i * k) >= l && (i * k) <= r) { f = 1; break; } else continue; } if (f == 1) cout << YES n ; else...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); long long n, m, x; cin >> n >> m; vector<long long> vPref(n), vSuf(n), vTot(n), vCen(n); for (int i(0), ThkMk(n); i < ThkMk; ++i) { cin >> x; vector<long long...
#include <bits/stdc++.h> using namespace std; const long long MOD = 1000000007ll; const double EPS = 1e-11; int n; char s[1252525]; int cntright[1252525]; int cntleft[1252525]; int revright[1252525]; int revleft[1252525]; long long sumright[1252525]; long long sumleft[1252525]; int main() { ...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); long long n, k, m; cin >> n >> k >> m; vector<long long> a(k); for (long long& v : a) cin >> v; sort(a.begin(), a.end()); a.push_back(0); k++; a.insert(a.begin(), 0); for (int ...
#include <bits/stdc++.h> using namespace std; long long int M = 1e9 + 7; int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long int t; cin >> t; vector<long long int> v; for (long long int i = 1; i <= 100000; ++i) { long long int x = (i * (3 *...
#include <bits/stdc++.h> #pragma comment(linker, /STACK:256000000 ) using namespace std; int n; vector<long long> a(200013); bool f(long long m) { long long l = (long long)(a[0] + 2 * m), r = (long long)(a[n - 1] - 2 * m); if (l >= r) { return 1; } if ((r - l) <= 2 * m) { return 1...
#include <bits/stdc++.h> using namespace std; const long long MOD = 1000000009; long long modexp_recursion(long long a, long long b, long long n) { long long t = 1; if (b == 0) return 1; if (b == 1) return a % n; t = modexp_recursion(a, b >> 1, n); t = t * t % n; if (b & 0x1) { t = t...
#include <bits/stdc++.h> using namespace std; inline int read(int f = 1, int x = 0, char ch = ) { while (!isdigit(ch = getchar())) if (ch == - ) f = -1; while (isdigit(ch)) x = x * 10 + ch - 0 , ch = getchar(); return f * x; } const int N = 5e5 + 5; int n, m, f[N], g[N], fs[N], gs[N], f...