func_code_string
stringlengths
59
71.4k
#include <bits/stdc++.h> using namespace std; int a[100005], b[100005]; int main(void) { int n; stack<int> s; scanf( %d , &n); for (int i = 1; i <= n; i++) { scanf( %d , &a[i]); } for (int i = n; i >= 1; i--) { if (s.empty()) { s.push(a[i]); b[i] = 0; co...
#include <bits/stdc++.h> int dp[200100]; int X[200100]; int Y[200100]; int T[200100]; int MX[200100]; int main(void) { int n, r; scanf( %d %d , &r, &n); for (int i = 1; i <= n; i++) dp[i] = MX[i] = -200100; MX[0] = X[0] = Y[0] = dp[0] = T[0] = 0; for (int i = 1; i <= n; i++) { scan...
#include <bits/stdc++.h> using namespace std; struct node { int u, v; }; node p[200010]; int du[200010], n, m; int _first[200010], _next[200010], _to[200010], cnt; int add(int a, int b) { _next[++cnt] = _first[a]; _first[a] = cnt; _to[cnt] = b; du[b]++; } bool check(int x) { cn...
#include <bits/stdc++.h> using namespace std; int main() { long long int n, m; scanf( %lld , &n); scanf( %lld , &m); long long int i, j; string s; cin >> s; long long int arr[400], brr[400]; for (i = 1; i <= 300; i++) { arr[i] = i; brr[i] = i; } while (m--) { ...
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; vector<long long> p; int ho, mi, se; void fix_time() { if (se > 59) mi += se / 60, se = se % 60; if (se < 0) se += 60, mi--; if (mi > 59) ho += mi / 60, mi = mi % 60; if (mi < 0) mi += 60, ho--; if (ho < 0) ho += 24; ...
#include <bits/stdc++.h> using namespace std; struct Edge { int u, v, d, id; long long cnt; bool operator<(const struct Edge& rhs) const { return d < rhs.d; } } edg[100001]; int vert[100001]; long long sz[100001]; int find(int i) { if (vert[i] == i) return i; return vert[i] = find(vert[i...
#include <bits/stdc++.h> using namespace std; bitset<16 * 2002> dp[1 << 16]; int n, k; int a[16]; int weight[16]; int calc(int &x) { int c = 0; while (x % k == 0) x /= k, c++; return c; } int _calc(int x) { int c = 0; while (x % k == 0) x /= k, c++; return c; } void dfs(int s...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long int n, m, i, a[5]; cin >> n; for (i = 0; i < 5; i++) { a[i] = n % 10; n /= 10; } n = a[3] + 10 * a[1] + 100 * a[0] + 1000 * a[2] + 10000 * a[4]; m = n; ...
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n; cin >> n; int a[n + 5]; for (int i = 0; i < n; i++) cin >> a[i]; int ans = 1; for (int i = 1; i <= 26; i++) { int x = 1; while (true) { int count...
#include <bits/stdc++.h> using namespace std; const long long maxn = 1000000 + 10; long long d[maxn]; long long ans = 0; int main() { ios_base::sync_with_stdio(false); long long n, m; cin >> n >> m; for (long long i = 0; i < m; i++) { long long v, u; cin >> v >> u; d[u]++; ...
#include <bits/stdc++.h> int n; char S[300000]; struct edge { int to, nxt; } E[500000]; int H[500000], tot; inline void add_edge(int a, int b) { E[++tot] = (edge){b, H[a]}, H[a] = tot; } struct SegmentTree { struct node { node *L, *R; node() { L = R = NULL; } }; node *root; ...
#include <bits/stdc++.h> using namespace std; const int maxn = 45; int a[maxn], b[maxn]; const long long INFF = 0x3f3f3f3f3f3f3f3fll; int N; struct Martix { long long arr[maxn][maxn]; void init() { memset(arr, 0x3f, sizeof(arr)); } void to() { this->init(); for (int i = 0; i < N; i++...
#include <bits/stdc++.h> using namespace std; const long long MOD = 1e9 + 7LL; const int MAXN = 212345; int vis[MAXN]; vector<int> g[MAXN]; long long dfs(int u) { vis[u] = 1; long long r = 1; for (int v : g[u]) if (!vis[v]) r += dfs(v); return r; } long long fexp(long long b, long ...
#include <bits/stdc++.h> using namespace std; long long powmod(long long base, long long exponent, long long mod) { long long ans = 1; while (exponent) { if (exponent & 1) ans = (ans * base) % mod; base = (base * base) % mod; exponent /= 2; } return ans; } long long gcd(long lo...
#include <bits/stdc++.h> using namespace std; int n; int a[2513][2513]; bitset<2513> big[2513]; vector<int> comp; vector<pair<int, int> > need[2513 * 2513]; int main() { scanf( %d , &n); for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) { scanf( %d , &a[i][j]); if (i ==...
#include <bits/stdc++.h> using namespace std; void print(int n) { string x = ; if (n >= 5) { x += -O| ; n -= 5; } else { x += O-| ; } while (n--) { x += O ; } x += - ; while (x.size() < 8) x += O ; cout << x << endl; } int main() { int n; ...
#include <bits/stdc++.h> using namespace std; signed main() { ios_base::sync_with_stdio(false); cin.tie(0); long long n, m; cin >> n >> m; vector<vector<long long>> in(n); vector<long long> deg(n); long long a, b; for (long long i = 0; i < m; ++i) { cin >> a >> b; --a; ...
#include <bits/stdc++.h> using namespace std; long long cou = 0, ans = 0, mx = INT_MIN, mn = INT_MAX, sum = 0, modu = 1e9 + 7; vector<vector<int>> from, to; vector<bool> visited(1e3, false); void dfs(int t) { visited[t] = true; for (int c = 0; c < from[t].size(); c++) { if (!visited[from[t][c]])...
#include <bits/stdc++.h> using namespace std; char a[2048][2048]; int flagr[2048], flagc[2048]; int n, ans = 0; void print() { cout << endl; cout << ========== << endl; for (int i = 0; i < n; ++i) { for (int j = 0; j < n; ++j) cout << a[i][j]; cout << endl; } cout << endl; ...
#include <bits/stdc++.h> using namespace std; int n, x, y; string h; int main() { cin >> n; for (int i = 0; i < n; i++) { cin >> h >> x >> y; if (x >= 2400 and y > x) { cout << YES ; return 0; } } cout << NO ; return 0; }
#include <bits/stdc++.h> using namespace std; int n, m, d; vector<int> e[100000 + 5], lst[100000 + 5]; int dfn[100000 + 5], low[100000 + 5], cnt, tot, sta[100000 + 5], ptr, scc[100000 + 5], cycle[100000 + 5]; char open[100000 + 5][55]; void tarjan(int now) { dfn[now] = low[now] = ++cnt; sta[++...
#include <bits/stdc++.h> using namespace std; const int N = 100010; string s; int n; int main() { cin >> s; n = s.length(); for (int i = 1; i < n - 1; i++) { if (s[i - 1] == . || s[i] == . || s[i + 1] == . ) continue; int c1 = s[i - 1] - A + 1; int c2 = s[i] - A + 1; ...
#include <bits/stdc++.h> using namespace std; const double PI = 3.1415926535897932384626433832795; const double EPS = 1e-9; const int MAX_NUMBER = 25 * 1000 * 1000; const int ROOT = 10000; bool isPrime[MAX_NUMBER]; int primesAmount; bool canMult(int a, int b) { if (b == 0) { return true; }...
#include <bits/stdc++.h> using namespace std; const int N = 5e5 + 5, mod = 1e9 + 7; struct pt { long long x, y; inline void in() { scanf( %lld%lld , &x, &y); } inline long long operator*(const pt& rhs) const { return x * rhs.y - rhs.x * y; } inline pt operator+(const pt& rhs) const { ...
#include <bits/stdc++.h> using namespace std; const int MAXN = 300 + 10; const int MAXM = 1e5 + 10; const int MOD = 1e9 + 7; int T, n, q, t, a[MAXN], dp[MAXN][MAXM], deg[MAXN], cnt[MAXN]; vector<int> g[MAXN]; bool visited[MAXN]; void dfs(int v, int x) { visited[v] = true; cnt[v] = 0; for (au...
#include <bits/stdc++.h> using namespace std; template <typename A, typename B> inline char smax(A &a, const B &b) { return a < b ? a = b, 1 : 0; } template <typename A, typename B> inline char smin(A &a, const B &b) { return b < a ? a = b, 1 : 0; } template <typename I> inline void read(I &x)...
#include <bits/stdc++.h> using namespace std; const int maxn = 200000 + 123; using LL = long long; using PLL = pair<LL, LL>; PLL lr[maxn], a[maxn]; LL ans[maxn]; deque<pair<LL, PLL>> itv; priority_queue<PLL, vector<PLL>, greater<PLL>> Q; LL n, m; int main() { ios_base::sync_with_stdio(0); ci...
#include <bits/stdc++.h> using namespace std; int main() { int k; cin >> k; char arr[4][4]; int i, j; std::map<int, int> map; for (i = 0; i < 4; i++) { for (j = 0; j < 4; j++) { cin >> arr[i][j]; if (arr[i][j] == . ) { continue; } else { map...
#include <bits/stdc++.h> //#include <bits/extc++.h> #define ll long long #define endl n #define pb push_back #define ms(v,x) memset(v,x,sizeof(v)) #define ff first #define ss second #define td(v) v.begin(),v.end() #define rep(i,a,n) for (int i=(a);i<(n);i++) #define per(i,a,n) for (int i=(n-1);i>...
#include <bits/stdc++.h> using namespace std; int main() { long long int n, m, s, a[101], b[101], x, y, i; double c, d, e, f, g = 10000000, h, k = -1; cin >> n >> m >> s; for (i = 1; i <= n; i++) cin >> a[i]; cin >> x >> y; for (i = 2; i <= n; i++) { c = double(a[i]) / double(m); ...
#include <bits/stdc++.h> using namespace std; struct node { int val; int num; } c[100010]; bool cmp(node a, node b) { return a.val < b.val; } int main() { int n, d, a, b, u, v, res = 0; scanf( %d%d%d%d , &n, &d, &a, &b); for (int i = 1; i <= n; i++) { scanf( %d%d , &u, &v); c[i...
#include<bits/stdc++.h> #define R register #define I inline #define ll long long #define ull unsigned long long #define LL __int128 #define db double using namespace std; #define pii pair<int,int> #define mp(x,y) make_pair(x,y) #define piii pair<pair<int,int>,int> #define mp3(x,y,z) make_pair(make...
#include <bits/stdc++.h> using namespace std; const long long inf = 1ll << 62; struct Query { long long n; int id; Query(long long _n = 0, int _id = 0) : n(_n), id(_id) {} inline bool operator<(const Query& rhs) const { return n > rhs.n; } } qry[100010]; long long ans[100010]; vector<pair<lo...
#include <bits/stdc++.h> using namespace std; map<long long, bool> tz; int gcd(int a, int b) { if (b == 0) return a; else return gcd(b, a % b); } int cnk(long long n, long long k, long long mod) { long long result = 1; int lal = 0; for (int lol = n; lal < k; lal++, lol--) { ...
#include <bits/stdc++.h> using namespace std; int a[5005]; int vals[5005]; int n; long long d[2][5005]; int main() { cin >> n; for (int i = 0; i < n; i++) { cin >> a[i]; vals[i] = a[i]; } sort(vals, vals + n); memset(d, 0, sizeof(d)); int cur = 0, nw = 1; for (int i =...
#include <bits/stdc++.h> using namespace std; vector<int> A; int F(int q, int w, int pr) { if (w - q <= 2) return w - q; int s = q; int g = 0; int ans = 2; while (s < w) { int f = s; int st = 1; while (st <= (A[s] - pr)) st <<= 1; st = pr + (st >> 1); while (f < w...
#include <bits/stdc++.h> using namespace std; const double pi = acosl(-1); void solve() { long long n, s, t; cin >> n >> s >> t; if (n == s + t) { cout << max(s, t) + 1 << n ; } else { if (2 * n == s + t) { cout << 1 << n ; } else { if (s > t) { swap...
#include <bits/stdc++.h> using namespace std; const int maxn = 2e3 + 10; const int MOD = 1e9 + 7; long long bit[maxn], n, k; long long sum(int i) { long long s = 0; while (i > 0) { s += bit[i]; s %= MOD; i -= i & -i; } return s; } void add(int i, long long x) { while ...
#include <bits/stdc++.h> using namespace std; int main() { long long n, x, y; cin >> n >> x >> y; vector<char> a(n); for (long long i = 0; i < n; i++) { cin >> a[i]; } long long j = 0, p = 0; while (j < n) { while (a[j] == 48 && j < n) { j++; } p++; ...
#include <bits/stdc++.h> using namespace std; int n, m, i, j, k, x, y, z; int f[100005]; int main() { scanf( %d%d , &n, &m); for (; m; --m) { scanf( %d%d%d , &x, &y, &z); k = 7; k -= f[x]; k -= f[y]; k -= f[z]; if (!f[x]) f[x] = k & -k, k -= k & -k; if (!f[y]) f...
#include <bits/stdc++.h> using namespace std; const int m = 50; struct M { double v[60][60]; M() { memset(v, 0, sizeof(v)); } double *operator[](const int &a) { return v[a]; } M operator*(const M &a) const { M b; int i, j, k; for (i = 0; i <= m; i++) for (j = 0; j <= m; j...
#include <bits/stdc++.h> using namespace std; int n, T; double p[5555]; int t[5555]; double f[5555][5555]; int main() { cin >> n >> T; for (int i = 0; i < n; i++) { cin >> p[i] >> t[i]; p[i] /= 100; } for (int x = 1; x < t[n - 1]; x++) f[n - 1][x] = f[n - 1][x - 1] + p[n - ...
#include <bits/stdc++.h> using namespace std; const int maxn = 1005; const int mod = 1e9 + 9; int Case = 1, n, m; char ss[maxn][maxn]; int dr[4][2] = {{0, -1}, {0, 1}, {1, 0}, {-1, 0}}; int vis[maxn][maxn][5][5]; struct node { int x, y, d, cnt; node(int x = 0, int y = 0, int d = 0, int cnt = 0) ...
#include <bits/stdc++.h> using namespace std; int read() { int x = 0, flag = 1; char ch = getchar(); while (!isdigit(ch)) { if (ch == - ) flag = -1; ch = getchar(); } while (isdigit(ch)) { x = (x << 3) + (x << 1) + (ch ^ 48); ch = getchar(); } return x * flag; ...
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 10; const int base = 31337; const int mod = 1e9 + 7; const int inf = 0x3f3f3f3f; const int logo = 20; const int off = 1 << logo; const int treesiz = off << 1; int n; int niz[maxn]; int main() { scanf( %d , &n); for (int i...
#include <bits/stdc++.h> using namespace std; const int N = 100010; int n, m; vector<long long> g[N]; vector<long long> rg[N]; vector<long long> vs; bool used[N]; int cmp[N], cmpsize[N]; void add_edge(int from, int to) { g[from].push_back(to); rg[to].push_back(from); } void dfs(int v) { ...
#include <bits/stdc++.h> using namespace std; signed main() { ios_base::sync_with_stdio(false); cin.tie(0); string s; cin >> s; int n = s.size(); int a = 0, b = 0, c = 0; for (int i = 0; i < n; ++i) { a += (s[i] == a ); b += (s[i] == b ); c += (s[i] == c ); } ...
#include <bits/stdc++.h> using namespace std; long long int t, n, lenn; long long int last(long long int x) { long long int tr = x; lenn = 0; while (x > 0) { tr = x % 10; x /= 10; ++lenn; } return tr; } int main() { ios::sync_with_stdio(0); cin.tie(0); cout.ti...
#include <bits/stdc++.h> using namespace std; using LL = long long; template <typename T> using V = vector<T>; template <typename T, typename S> using P = pair<T, S>; template <class T> using min_heap = priority_queue<T, std::vector<T>, std::greater<T>>; using LD = long double; template <typename T,...
#include <bits/stdc++.h> int a[100 + 10]; int main() { int n, m, min_, max_; scanf( %d %d %d %d , &n, &m, &min_, &max_); int i, j, t = 0; for (i = 0; i < m; i++) { scanf( %d , &a[i]); } for (i = 0; i < m; i++) { for (j = i + 1; j < m; j++) { if (a[j] < a[i]) { t...
#include <bits/stdc++.h> using namespace std; long long spf[101]; long long arr[100001]; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); long long n; cin >> n; long long sum = 0; for (int i = 0; i < n; i++) { cin >> arr[i]; sum += arr[i]; } ...
/** try <3 **/ #include<bits/stdc++.h> using namespace std; #define task sol #define lb lower_bound #define ub upper_bound #define fi first #define se second #define pb push_back #define mp make_pair #define zs(v) ((int)(v).size()) #define BIT(x, i) (((x) >> (i)) & 1) #define CNTBIT __bu...
#include <bits/stdc++.h> using ll = long long; using namespace std; const int INF = 1e8; const int N = 2e5 + 2; int n, m, k; vector<int> G[N]; int a[N]; bool sp[N]; int distN[N], dist1[N]; int suf[N]; bool cmp(int& v, int& u) { return dist1[v] < dist1[u]; } void bfsN() { for (int i = 0; i < ...
#include <bits/stdc++.h> using namespace std; const int N = 2222; const int INF = 0x3f3f3f3f; int n, m, k, s; int mat[2][N][9], cp[9][9]; void tomin(int &a, int b) { if (a > b) a = b; } void tomax(int &a, int b) { if (a < b) a = b; } void work() { for (int i = 0; i < m; i++) for (i...
#include <bits/stdc++.h> using namespace std; int main() { long long arr[4]; for (int i = 0; i < 4; i++) cin >> arr[i]; sort(arr, arr + 4); long long w, x, y, z; w = arr[0]; x = arr[1]; y = arr[2]; long long a, b, c, d; b = (w - x + y) / 2; a = w - b; c = x - a; cout ...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; if (n % 2 == 0) { cout << n / 2 << endl; for (int i = 0; i < n / 2; i++) cout << 2 ; return 0; } else { cout << (n / 2) << endl; for (int i = 0; i < (n / 2) - 1; i++) cout << 2 ; cout ...
#include <bits/stdc++.h> using namespace std; int a[10000]; int n, m, mn, mn1; multiset<int> s; int main() { cin >> n >> m; for (int i = 0; i < n; i++) { cin >> a[i]; s.insert(a[i]); } int q = *s.rbegin() + m; while (m--) { int t = *s.begin(); s.erase(s.begin()); ...
#include <bits/stdc++.h> using namespace std; long long int div_floor(const long long int &a, const long long int &b) { return a / b - (((a ^ b) < 0) and a % b); } long long int div_ceil(const long long int &a, const long long int &b) { return a / b + (((a ^ b) >= 0) and a % b); } long long int modp...
#include <bits/stdc++.h> using namespace std; int32_t main() { ios::sync_with_stdio(0); cin.tie(0); long long n; cin >> n; long long ar[n + 1]; for (long long i = 0; i < n; i++) { cin >> ar[i]; } ar[n] = n + 1; long long ans = 0; for (long long i = 0; i < n; i++) { ...
#include <bits/stdc++.h> const int mod = 1000000007; const int gmod = 3; const int inf = 1039074182; const double eps = 1e-9; const long long llinf = 2LL * inf * inf; template <typename T1, typename T2> inline void chmin(T1 &x, T2 b) { if (b < x) x = b; } template <typename T1, typename T2> inli...
#include <bits/stdc++.h> using namespace std; int main() { long long n; cin >> n; multiset<long long> v; vector<pair<string, long long>> ans; for (int i = 0; i < n; ++i) { string s; cin >> s; if (s == insert ) { long long x; cin >> x; ans.push_back({ in...
#include <bits/stdc++.h> using namespace std; using INT = long long; const int NN = 111; string tar; string s[NN]; int n; void dfs(int len) { if (!len) { for (int i = 1; i <= n; i++) { for (int j = 0; j < s[i].length(); j++) { int f = 1; for (int k = j; k < s[i].lengt...
#include <bits/stdc++.h> const long long N = 2e5 + 7; const long long M = 2e4 + 5; const double eps = 1e-8; const long long mod = 1e9 + 7; const long long inf = 0x7fffffff; const double pi = 3.1415926; using namespace std; vector<long long> v[N], num; long long n; long long dfs(long long x, long lon...
#include <bits/stdc++.h> using namespace std; long long nums[100005]; int main() { ios_base::sync_with_stdio(false); cin.tie(0); int n; cin >> n; long long potL = 1000000000; long long total = 0; for (int i = 0; i < n; i++) { long long num; cin >> num; if (num % 2 == ...
#include <bits/stdc++.h> const int N = 1e4 + 5; int ans, n; double f[2][N]; signed main() { scanf( %d%lf , &n, &f[1][1]); for (int i = 1; i <= n; i++) for (int j = 1; j <= i; j++) { if (f[i & 1][j] >= 1.0) { f[i & 1 ^ 1][j] += (f[i & 1][j] - 1.0) / 2.0; f[i & 1 ^ 1][j +...
#include <bits/stdc++.h> using namespace std; int i, n, x[110], y[110], f[110], j, ans; bool b[110]; int find(int x) { if (f[x] == x) return x; else return f[x] = find(f[x]); } void Union(int x, int y) { f[find(x)] = find(y); } int main() { scanf( %d , &n); for (i = 1; i <= n; ...
#include <bits/stdc++.h> using namespace std; const int maxN = 2e5 + 7; int N, M, head[maxN], cnt; struct Eddge { int nex, to, id; Eddge(int a = -1, int b = 0, int c = 0) : nex(a), to(b), id(c) {} } edge[maxN << 1]; inline void addEddge(int u, int v, int id) { edge[cnt] = Eddge(head[u], v, id); ...
#include <bits/stdc++.h> using namespace std; int n; map<string, int> mid, pid; std::vector<string> hostname; vector<int> a[100000]; char s[1000]; int m_total = 0, p_total = 0; int b[100000]; std::vector<std::vector<int> > ans; bool cmp(int i, int j) { return a[i] < a[j]; } int main(int argc, char...
#include <bits/stdc++.h> using namespace std; const int INF = 1e9 + 7; const int maxn = 1e4 + 5; int n, b, q; int a[maxn], c[maxn]; inline int f(int x, int j) { return (x / 5) + (x % 5 >= j); } inline int calc(int j, int l, int r) { return f(r, j) - f(l - 1, j); } int main() { scanf( %d%d%d , &n, &b...
#include <bits/stdc++.h> using namespace std; int ins[300]; struct Rec { int n, p; int a[10]; } st[1000000]; void Print(int now) { int i, j, x, pre, ret; if (now == 0) return; pre = st[now].p; ret = st[now].a[st[now].n - 1]; for (i = 0; i < st[pre].n; i++) for (x = 2; x <= 8;...
#include <bits/stdc++.h> using namespace std; queue<long long> q1; long long a[20005]; long long l, r; int main(void) { int i = 0; int j; cin >> l >> r; q1.push(0); while (1) { a[i] = q1.front() * 10 + 4; i++; if (a[i - 1] >= r) break; q1.push(a[i - 1]); a[i] ...
#include <bits/stdc++.h> using namespace std; const long long MOD = (long long)1e9 + 7; const long double PI = 3.141592653589793238462643383279502884197; long long fac[1] = {1}, inv[1] = {1}; long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; } long long mp(long long a, long long b) { ...
///====================== TEMPLATE STARTS HERE =====================/// #include <bits/stdc++.h> using namespace std; #define endl n #define pb push_back #define MP make_pair #define ff first #define ss second #define ABS(x) ((x)<0?-(x):(x)) #define FABS(x) ((x)+eps<0?-(x):(x)) #define LCM(x,y...
#include <bits/stdc++.h> using namespace std; char s[105], pos[105], p[105], cmp[105]; int main() { int n = 0, k = 0; scanf( %d%d , &n, &k); scanf( %s , p); scanf( %s , pos); for (int i = 0; i < n; ++i) { s[i] = * ; } int lenp = strlen(p); for (int i = 0; i < n - lenp + 1; +...
#include <bits/stdc++.h> using namespace std; using namespace std::chrono; template <typename A> ostream &operator<<(ostream &cout, vector<A> const &v); template <typename A, typename B> ostream &operator<<(ostream &cout, pair<A, B> const &p) { return cout << ( << p.first << , << p.second << ) ; ...
#include <bits/stdc++.h> using namespace std; void lwr(string& s) { for (int i = 0; i < s.size(); i++) { if (s[i] >= A and s[i] <= Z ) s[i] = s[i] - A + a ; } } pair<int, int> _rank(const string& s) { int ret = 0; for (int i = 0; i < s.size(); i++) ret += s[i] == r ; return pair...
#include <bits/stdc++.h> int n, m, p, r[605], c[605], f[605], g[605][605], a[605][605], b[605][605]; void tuopu() { int h = 0, t = 0; for (int i = 1; i <= n; i++) if (!r[i]) f[++t] = i, g[i][t] = 1; m = t; while (h < t) { int x = f[++h]; for (int i = 1; i <= n; i++) if (b[x...
#include <bits/stdc++.h> using namespace std; int t, n, a[100005]; vector<int> v[100005]; int val[100005]; int k[100005]; int main() { for (int i = 2; i <= 100000; i++) { v[i].push_back(1); for (int j = i + i; j <= 100000; j += i) { v[j].push_back(i); } } scanf( %d , &t...
#include <bits/stdc++.h> int a[500005][9] = {0}; int nnf[500005] = {0}; int pn[200005] = {0}; int val[200005]; int x, in; void print(int *a, int n) { int i; for (i = 0; i < n; i++) printf( %d , a[i]); printf( n ); } long long int check(int cnt, int val, int d) { if (in == -1) nnf[val] ...
#include <bits/stdc++.h> using namespace std; int N, K, L; int pre[1000005]; long long dp[1000005]; int cnt[1000005]; string s; pair<int, int> chk(long long C) { fill(dp + 1, dp + 1 + N, 0); fill(cnt + 1, cnt + 1 + N, 0); for (int i = 1; i <= N; i++) { dp[i] = dp[i - 1]; cnt[i] = c...
#include <bits/stdc++.h> const int N = 1010; int n, k, a[N], a2[N], used[N], m, d, ans; std::list<int> list; int t; void spendTimeUntil(int setSz) { while (list.size() > setSz) { d = round(100 * (double)m / (double)n); for (int x : list) { if (a2[x] + 1 == d && !used[x]) { us...
#include <bits/stdc++.h> using namespace std; void fun() {} const long long int inf = 1e18; const long long int md = 1e9 + 7; const long long int N = 300050; long long int __gcd(long long int a, long long int b) { if (b == 0) return a; return __gcd(b, a % b); } long long int poww(long long int a...
#include <bits/stdc++.h> using namespace std; vector<int> v[27]; bool vis[27]; vector<pair<int, int> > pr; int cnt, flag; void dfs(int nod, int dest) { int i; vis[nod] = 1; if (nod == dest) { flag = 1; return; } for (i = 0; i < v[nod].size(); i++) { int curr = v[nod][i]...
#include <bits/stdc++.h> using namespace std; const int MOD = 1e9 + 7; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int t; cin >> t; string s; vector<int> a; while (t--) { int x; cin >> x >> s; a.resize(x); int sz = s.size(); for (int i = 0; i < ...
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; const int N = 1e6 + 7; long long p[N]; int main() { int a, b, c, d; scanf( %d , &a), scanf( %d , &b), scanf( %d , &c), scanf( %d , &d); for (int i = a; i < (int)b + 1; i++) { p[i + b] += 1; p[i + c + 1] -= 1; ...
#include <bits/stdc++.h> #pragma GCC optimize( Ofast , unroll-loops , no-stack-protector ) using namespace std; int32_t main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); long long test = 1; while (test--) { long long x, y; cin >> x >> y; long long n; cin ...
#include <bits/stdc++.h> using namespace std; long long leftBinarySearch(long long* color, long long size, long long target) { int l = 0; int r = size - 1; int idx = -1; while (l <= r) { int m = l + (r - l) / 2; if (color[m] <= target) { l = m + 1; idx = m; } else {...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); int n, k, i, tt = 1, a, b; cin >> n >> k; vector<pair<int, int> > p; for (i = 0; i < n; i++) { cin >> a >> b; p.push_back(make_pair(-a, b)); } sort(p.begin(), p.end()); for...
#include <bits/stdc++.h> using namespace std; const int N = (int) 1e7 + 100; long long s[N]; int d[N]; int ans[N]; int main() { fill(d, d + N, -1); d[1] = 1; for (int i = 2; i * i < N; i++) { if (d[i] == -1) { d[i] = i; for (int j = i * i; j < N; j += i) { ...
#include <bits/stdc++.h> using namespace std; int const N = 2e5 + 5; vector<vector<int> > adj(N); long long a[N]; pair<pair<long long, long long>, long long> dfs(int u, int prt = 0) { if (adj[u].empty()) return {{1, a[u]}, a[u]}; pair<pair<long long, long long>, long long> ret = {{0, 0}, 0}; for (...
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; int n; char cmd[1000001]; bool sym(int p) { int rm = 0, cur = 0; for (int i = 0; i < n - 1; ++i) { if (cur > p + 1 && cmd[i] == L ) cur--; else if (cmd[i] == R ) rm = max(rm, ++cur); } return c...
#include <bits/stdc++.h> using namespace std; int main() { long long int t; cin >> t; while (t--) { long long int n, k; cin >> n >> k; vector<long long int> a(n); for (int i = 0; i < n; i++) cin >> a[i]; vector<long long int> pks; for (int i = 1; i < n - 1; i++) { ...
#include <bits/stdc++.h> using namespace std; int main() { int a, b, x; scanf( %d %d %d , &a, &b, &x); if (a != 0 && a >= b) { a = a - (a / b) * b; } a *= 10; int cont = 0; vector<int> v; while (cont <= b && a != 0) { if (a < b) { v.push_back(0); } else { ...
#include <bits/stdc++.h> using namespace std; int ans; void solve(long long n, long long l1, long long r1, long long l, long long r) { if (n == 0 || l1 > r || r1 < l) return; long long mid = (l1 + r1) >> 1; if (mid >= l && mid <= r) ans += (n % 2); solve(n / 2, l1, mid - 1, l, r); solve(n / 2,...
#include <bits/stdc++.h> using namespace std; int w[110], n, C0, C1, D[110][110][2]; int main() { int i, j, k, l; scanf( %d , &n); for (i = 1; i <= n; i++) { scanf( %d , &w[i]); if (i % 2 == 0) C0++; else C1++; } for (i = 0; i <= n; i++) { for (j = 0; j ...
#include <bits/stdc++.h> using namespace std; const long long MOD = 1e9 + 7; int main() { long long n, m; cin >> n >> m; string s; cin >> s; vector<vector<long long>> cost(n + 1, vector<long long>(6)); for (int i = n - 1; i >= 0; i--) { cost[i][0] = (s[i] == a ? 0 : 1) + cost[i + 1...
#include <bits/stdc++.h> using namespace std; void solve() { int n; cin >> n; cout << (n % 4 == 0 ? YES : NO ) << n ; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); int t; cin >> t; while (t--) { solve(); } return 0; }
#include <bits/stdc++.h> using namespace std; long long arr[300000]; int main() { long long n, m; scanf( %lld %lld , &n, &m); for (long long i = 1; i <= n; i++) { scanf( %lld , &arr[i]); } string s; cin >> s; long long len = s.size(); long long ans = 0; for (long long i =...
#include <bits/stdc++.h> using namespace std; long long int mod(long long int x) { return (((x) % 1000000007) + 1000000007) % 1000000007; } long long int mod1(long long int x, long long int m) { return (((x) % m) + m) % m; } long long int solve() { long long int n, k; cin >> n >> k; long...
#include <bits/stdc++.h> using namespace std; int n, len; char str[55][25]; long long f[(1 << 20) + 10], bin[55]; double ans[(1 << 20) + 10]; double res; int main() { int i, j, k, c; bin[0] = 1; for (i = 1; i < 55; i++) bin[i] = (bin[i - 1] << 1); scanf( %d , &n); for (i = 0; i < n; i+...