func_code_string
stringlengths
59
71.4k
#include <bits/stdc++.h> using namespace std; int main() { long long s, x; cin >> s >> x; long long ans = __builtin_popcountll(x); ans = 1LL << ans; if (s == x) ans -= 2; for (int i = 0; i < 60; i++) { if (x & (1LL << i)) s -= 1LL << i; } for (int i = 0; i < 60; i++) { in...
#include <bits/stdc++.h> using namespace std; int main() { int n, tmp; bool ok = 1; int ar[5]; memset(ar, 0, sizeof(ar)); scanf( %d , &n); for (int i = 0; i < n; ++i) { scanf( %d , &tmp); tmp /= 25; if (!ok) continue; if (tmp == 1) { ar[1]++; } else if (...
#include <bits/stdc++.h> using namespace std; struct Que { int a, b, w; } Q[300010]; bool operator<(Que a, Que b) { return a.b < b.b; } int n, i, m, Lim, j; long long ans[301000], w[301000], s[301000]; int main() { scanf( %d , &n); for (i = 0; i < n; i++) scanf( %I64d , &w[i]); scanf( %d ,...
#include <bits/stdc++.h> using namespace std; const long long maxn = 1000000 + 5; const long long DIFF = 2000; const long long mod = 1000000000 + 7; long long dp[DIFF + 5][DIFF + 5]; char s[maxn]; int main() { dp[0][0] = 1; for (int i = 1; i <= DIFF; dp[i][0] = dp[i - 1][1], i++) for (int j ...
#include <bits/stdc++.h> using namespace std; int main() { int x, y, a, b, i, c = 0, j = 0; cin >> x >> y; a = 240 - y; for (i = 1; c <= a; i++) { c = c + (5 * i); j++; } if (j - 1 <= x) { cout << j - 1 << endl; } else { cout << x << endl; } }
#include <bits/stdc++.h> using namespace std; const long long mx = (1 << 22); long long f[mx], ans[mx]; int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); ; long long n; cin >> n; long long a[n]; for (long long i = 0; i < n; i++) cin >> a[i]; memset(ans, ...
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; struct node { int x, y, c; } s[2005], tmp[2005]; int n, k, l, cx, cy; int lx[2005], ly[2005], bk[2005]; multiset<int> t[2005]; namespace Tree { int mn[8005], mx[8005], sum[8005], lzy[8005]; inline void pushtag(int p, int l, i...
#include <bits/stdc++.h> using namespace std; template <class T1, class T2> inline void upd1(T1& a, const T2& b) { a = a < b ? a : b; } template <class T1, class T2> inline void upd2(T1& a, const T2& b) { a = a > b ? a : b; } template <class T> inline bool equ(const T& a, const T& b) { ret...
#include <bits/stdc++.h> using namespace std; const int maxn = 105, maxm = 5005; const double eps = 1e-9; int N, M, m, X[maxm], Y[maxm], Z[maxm]; double f[maxn][maxn], p[maxn]; int main() { scanf( %d%d , &N, &M); for (int i = 1; i <= M; i++) { scanf( %d%d%d , &X[i], &Y[i], &Z[i]); if (X[...
#include <bits/stdc++.h> using namespace std; const int a1[4] = {1, -1, 0, 0}, a2[4] = {0, 0, 1, -1}; struct ww { int a, b; } g[1610 * 1610], h[1610 * 1610]; int i, j, k, n, m, s, l, r; int a[1610][1610], f[1610][1610], d[1610][1610], F[1610][1610], ans[1610 * 1610]; inline void bfs(int x, int y...
#include <bits/stdc++.h> int main() { int n; scanf( %d , &n); int i = 1; while ((i * (i + 1) / 2) <= n) { if ((i * (i + 1) / 2) == n) { printf( YES ); return 0; } i++; } printf( NO ); }
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 123, inf = 1e9 + 123, mod = 1e9 + 7; const long long INF = 1e18; int n, a[N]; int main() { cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0); cin >> n; for (int i = 1; i <= n; i++) { cin >> a[i]; } sort(a +...
#include <bits/stdc++.h> using namespace std; template <class T> void rd(T &x) { x = 0; int 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) + ch - 0 , ch = getchar(...
#include <bits/stdc++.h> using namespace std; int pic[610][610]; int ABS(int x) { if (x < 0) return -x; return x; } int main(int argc, char const *argv[]) { int q; scanf( %d , &q); for (int i = 0; i < q; i++) { int n, m, pix = 0, sum1 = 0, sum2 = 0; scanf( %d%d , &n, &m); ...
#include <bits/stdc++.h> using namespace std; const int N = 4e5 + 50; int n, m, a[N], b[N]; vector<int> G[N]; int in[N], out[N], tim, dep[N]; int mn[20][N], lg[N], p[N], k; void dfs(int u, int f) { dep[u] = dep[f] + 1; in[u] = ++tim; mn[0][p[u] = ++k] = u; for (int v : G[u]) if (v !=...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, k; cin >> n >> k; char def = a ; int pos = 0; string ans = ; for (int i = 0; i < n; i++) { ans += def + pos; pos = (pos + 1) % k; } cout...
#include <bits/stdc++.h> using namespace std; long long mod = 1000000007LL; long long base = 10000007; long long large = 1000000000000000000LL; class UnionFind { private: vector<int> p, rank; public: UnionFind(int n) { rank.assign(n, 0); p.assign(n, 0); for (int i = 0; i < n...
#include <bits/stdc++.h> using namespace std; int input[100000]; int output[100000]; pair<pair<int, int>, int> queries[100000]; int blockSize; bool mo_compare(pair<pair<int, int>, int>& x, pair<pair<int, int>, int>& y) { int firstBlockIndex = x.first.first / blockSize; int secondBlockIndex = y.first...
#include <bits/stdc++.h> using namespace std; int N, M, K; char a[1001], b[1001]; int mem[1001][1001][11][2]; int main() { scanf( %d %d %d , &N, &M, &K); scanf( %s %s , a, b); memset(mem, 0, sizeof(mem)); int ans = 0; for (int i = 1; i <= N; i++) { for (int j = 1; j <= M; j++) { ...
#include <bits/stdc++.h> using namespace std; long long k, n, m; int answ = 1; bool flag = 0; int main() { cin >> n >> m; k = 2; for (int i = 2; i <= m; i++) k = (k * 2) % 1000000009; if (k > n) { for (int i = 1; i <= n; i++) answ = (answ * (k - i)) % 1000000009; cout << answ; ...
#include <bits/stdc++.h> using namespace std; const double pi = acos(-1.0); long long int path[100001]; long long int dist[100001]; void shortest_path(vector<pair<long long int, long long int>> v[], long long int start) { long long int i; for (i = 0; i < 100001; i++) dist[i] = 1e1...
#include <bits/stdc++.h> using namespace std; using ll = int64_t; template <typename T, typename U> ostream& operator<<(ostream& _s, pair<T, U> _t) { _s << ( << _t.first << , << _t.second << ) ; return _s; } template <typename T, typename U> istream& operator>>(istream& _s, pair<T, U>& _t) { ...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); unsigned long long n; cin >> n; vector<unsigned long long> a(n); for (unsigned long long i = 0; i < n; i++) cin >> a[i]; unsigned long long total = 0; for (unsigned long long i...
#include <bits/stdc++.h> using namespace std; int n, m, cnt[200005 * 5], E2[200005], f[200005 * 5]; signed main() { scanf( %d , &n); int mx = 0; for (int i = 1; i <= n; i++) { int x; scanf( %d , &x); cnt[x]++; mx = max(mx, x); } E2[0] = 1; for (int i = 1; i < 200005...
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; using pii = pair<int, int>; constexpr int MAXN = 100005; int n; string type[MAXN], word[MAXN]; bitset<30> to_bs(const string& s) { bitset<30> res; for (char c : s) { res[c - a ] = true; } r...
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 10; bool lucky[10010]; int n, m; int a[N]; int t[N + N]; void init() { memset(lucky, false, sizeof(lucky)); lucky[0] = true; for (int i = 1; i <= 10000; i++) if (i % 10 == 4 || i % 10 == 7) lucky[i] = lucky[i / 10]; } ...
#include <bits/stdc++.h> using namespace std; const double pi = acos(-1.0), eps = 1e-8; const int inf = ~0U >> 2; int mod = 1e9 + 7; int Pow(int x, long long t) { int r = 1; for (; t; t >>= 1, x = (long long)x * x % mod) if (t & 1) r = (long long)r * x % mod; return r; } const int N = 10...
#include <bits/stdc++.h> using namespace std; bool palindrome(const string &s) { int n = s.length(); for(int i = 0; i < n; i++) { if(s[i] != s[n - i - 1]) return false; } return true; } int main() { ios::sync_with_stdio(false); cin.tie(0); int te; ...
#include <bits/stdc++.h> const long double PI(acosl(-1.0)); long double eps = 1e-9; using namespace std; using namespace std; const int N = 1000000; int main() { std::ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n; cin >> n; vector<pair<int, int> > p(n); int s =...
#include <bits/stdc++.h> using namespace std; template <class T> void CIN(T &a) { cin >> a; } template <class T> void CIN(T &a, T &b) { cin >> a >> b; } template <class T> void CIN(T &a, T &b, T &c) { cin >> a >> b >> c; } template <class T> void CIN(T &a, T &b, T &c, T &d) { cin...
#include <bits/stdc++.h> using namespace std; int main() { int a, b, c; cin >> a >> b >> c; int max = 0; int n[100]; n[0] = a * b + c, n[1] = a * b * c, n[2] = a + b * c, n[3] = a + b + c, n[4] = a * (b + c), n[5] = (a + b) * c; for (int i = 0; i < 6; i++) { if (n[i] > max) max = n...
#include <bits/stdc++.h> using namespace std; typedef long long Int; typedef pair<int,int> PII; typedef vector<int> VInt; #define FOR(i, a, b) for(i = (a); i < (b); ++i) #define RFOR(i, a, b) for(i = (a) - 1; i >= (b); --i) #define EACH(it, a) for(auto it = (a).begin(); it != (a).end(); ++it) #de...
#include <bits/stdc++.h> using namespace std; const int N = 55; const int MOD = 1e9 + 7; struct Node { int op, x, y, d; Node() {} Node(int _op, int _x, int _y, int _d) { op = _op, x = _x, y = _y, d = _d; } bool operator<(const Node &cur) const { return d > cur.d; } }; priority_queue<Node> qu...
#include <bits/stdc++.h> using namespace std; template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; } template <class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return 1; } return 0; } template <class T> o...
#include <bits/stdc++.h> using namespace std; int n; long long a[305], Lcm; long long sol(long long x) { long long cnt = 0; for (long long i = 2; i * i <= x; i++) { if (x % i == 0) { cnt += 2; if (i * i == x) cnt--; } } return cnt; } int main() { int T; ci...
#include <bits/stdc++.h> using namespace std; char ch[100001]; int per[100001]; bool is[100001]; bool vis[100001]; bool mem[100001]; bool have[100001]; vector<int> V; int main() { int i, j; int a, b; int n, m; cin >> n >> m; for (i = 0; i < m; i++) { cin >> ch[i] >> per[i]; ...
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; const long long inf = 2e18; struct custom_hash { static uint64_t splitmix64(uint64_t x) { x += 0x9e3779b97f4a7c15; x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9; x = (x ^ (x >> 27)) * 0x94d049bb133111eb; return x ^ (x ...
#include<bits/stdc++.h> using namespace std; #define ll long long #define ld long double #define For(i,x,y) for(ll i = (x);i <= (y);++i) #define FOr(i,x,y) for(ll i = (x);i >= (y);--i) #define fi first #define se second #define pa pair<ll,ll> #define mk make_pair #define pb push_back #define clr(a...
#include <bits/stdc++.h> using namespace std; int n; double s; vector<int> E[100005]; int dist[100005], pa[100005]; int dfs(int u, int p, int d) { dist[u] = d; int ans = u; for (int v : E[u]) { if (v == p) continue; int tmp = dfs(v, u, d + 1); pa[v] = u; if (dist[ans] < d...
#include <bits/stdc++.h> using namespace std; long mk[100000]; int main() { long a, b, m, r0, r; cin >> a >> b >> m >> r0; for (long i = 0; i < m; i++) mk[i] = -1; r = (a * r0 + b) % m; mk[r] = 1; long k = 1; while (true) { k++; r = (a * r + b) % m; if (mk[r] == -1) ...
#include <bits/stdc++.h> using namespace std; int n, maxi = 2, ans = 2; int a[100005]; vector<int> num; int main() { cin >> n; for (int i = 0; i < n; i++) cin >> a[i]; if (n < 3) { cout << n; return 0; } for (int i = 2; i < n; i++) { if (a[i] == a[i - 1] + a[i - 2]) { ...
#include <bits/stdc++.h> using namespace std; int dx[] = {+1, -1, +0, +0}; int dy[] = {+0, +0, +1, -1}; int fx[] = {+0, +0, +1, -1, -1, +1, -1, +1}; int fy[] = {-1, +1, +0, +0, +1, +1, -1, -1}; int hr[] = {-2, -2, -1, +1, +2, +2, -1, +1}; int hc[] = {+1, -1, +2, +2, -1, +1, -2, -2}; const int MAXN = 1e5...
#include <bits/stdc++.h> using namespace std; const int maxn = 100010; const int mod = 1e9 + 7; long long dp[maxn] = {0, 1, 2, 3, 5, 8}; int main() { for (int i = 6; i < maxn; i++) dp[i] = (dp[i - 1] + dp[i - 2]) % mod; int n, m; cin >> n >> m; cout << (2 * (dp[n] + dp[m] - 1)) % mod << endl; ...
#include <bits/stdc++.h> using namespace std; int Set(int N, int pos) { return N = N | (1 << pos); } int reset(int N, int pos) { return N = N & ~(1 << pos); } bool check(long long N, int pos) { return (bool)(N & (1LL << pos)); } int n, m, l, r; string s; char c1, c2; int main() { cin >> n >> m; ...
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; set<string> g; g.insert(s); int n = s.size(); for (int k = 0; k < s.size(); k++) { string s1 = ; s1 += s[n - 1]; for (int i = 0; i < s.size() - 1; i++) { s1 += s[i]; } s = s...
#include <bits/stdc++.h> using namespace std; long long mod = 1000000007; vector<long long> parent(200005), Size(200005, 1); long long answer = 0; long long find_set(long long n) { if (parent[n] == n) return n; else return find_set(parent[n]); } void add_edge(long long a, long long b) ...
#include <bits/stdc++.h> using namespace std; int main() { map<long long, long long> isolados; long long n, k, i, j, prox, qtd, x, resp; bool first = true; while (cin >> n >> k) { resp = 0; isolados.clear(); prox = -1; first = true; for (i = 0; i < k; i++) { cin...
#include <bits/stdc++.h> using namespace std; int main() { int n, sti[101], i, x, ans; cin >> n; memset(sti, 0, sizeof(sti)); for (i = 1; i <= n; i++) { cin >> x; sti[x]++; } ans = 0; for (i = 1; i <= 100; i++) { ans += 2 * (sti[i] / 4); sti[i] %= 4; ans += ...
#include <bits/stdc++.h> using namespace std; int n; double a[4010]; int main() { cin >> n; n *= 2; for (int i = 1; i <= n; ++i) cin >> a[i]; for (int i = 1; i <= n; ++i) a[i] = a[i] - int(a[i]); int cnt = 0; for (int i = 1; i <= n; ++i) if (abs(a[i] - 0) <= 0.0000001) cnt++; d...
#include <bits/stdc++.h> using namespace std; int main() { int a[100005]; int n, i; scanf( %d , &n); for (i = 0; i < n; i++) { scanf( %d , &a[i]); } sort(a, a + n); if (a[n - 1] == 1) { for (i = 0; i < n - 1; i++) { printf( %d , a[i]); } puts( 2 ); } ...
#include <bits/stdc++.h> using namespace std; long long solve(long long a, long long b, long long c) { long long a1 = a - c; a1 *= a1; long long b1 = c - b; b1 *= b1; long long c1 = b - a; c1 *= c1; return a1 + b1 + c1; } int main() { ios_base::sync_with_stdio(0); cin.tie(0);...
#include <bits/stdc++.h> using namespace std; struct group { int sz; vector<int> worst, best; group(vector<int>& a) : sz(1), worst(a.begin(), a.end()), best(a.begin(), a.end()) {} bool operator<(const group& a) const { for (int i = 0; i < best.size(); i++) if (best[i] >= a.wors...
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e5 + 10, STAN = (1 << 30) - 1; struct QJ { int l, r, q; } q[MAXN]; int n, m; struct Seg { int water[MAXN * 4], sh[MAXN * 4]; bool fir[MAXN * 4]; Seg() { memset(water, 0, sizeof(water)); memset(fir, 0, sizeof(fir)); ...
#include <bits/stdc++.h> using namespace std; pair<int, int> a[5003]; vector<int> color[5003]; int ans[5003]; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n, k, i, j; cin >> n >> k; for (i = 0; i < n; i++) { cin >> a[i].first; a[i].second = i; ...
#include <bits/stdc++.h> using namespace std; void enable_comma() {} string tostring(char c) { string s = ; s += c; return s; } string tostring(string s) { return + s + ; } string tostring(const char *c) { return tostring((string)c); } string tostring(long long x) { if (x < 0) ret...
#include <bits/stdc++.h> #pragma GCC target( avx2 ) #pragma GCC optimization( O3 ) #pragma GCC optimization( unroll-loops ) using namespace std; const long long N = 1e5 + 10; const long double Pie = acos(-1); signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ...
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; const int maxn = 200005; vector<int> g[maxn]; int dis[maxn]; int pa[maxn]; set<pair<int, int>> st; void dfs(int now, int pre = 0) { if (dis[now] > 2) { st.insert({dis[now], now}); } for (auto &i : g[now]) { if...
#include <bits/stdc++.h> using namespace std; long long int newarr[1005]; long long int dp[1005][1005]; long long int n, k; long long int solution(long long int index, long long int m) { if (m < 0) m += k; if (index >= n && m != 0) return 0; else if (m == 0) return 1; else if (dp[i...
#include <bits/stdc++.h> using namespace std; const int bas = 23333; const long long mod = 9999999999973ll; int N, M, S[26], L[555]; char C[255][255]; long long H[26], W[255][255][255], G[555]; int manacher(int n) { int k = 0, m = 0, res = 0; memset(L, 0, sizeof(L)); for (int i = 1; i <= n; i+...
#include <bits/stdc++.h> using namespace std; typedef long long lo; typedef vector<lo> vl; typedef vector<lo> vll; typedef vector<vl> vvl; template <typename T> ostream &operator<<(ostream &o, vector<T> v) { if (v.size() > 0) o << v[0]; for (unsigned i = 1; i < v.size(); i++) o << << v[i]; ...
#include <bits/stdc++.h> using namespace std; template <typename T> inline void checkMax(T& a, const T& b) { if (a < b) a = b; } template <typename T> inline void checkMin(T& a, const T& b) { if (a > b) a = b; } const int kMod = 1000000007; template <typename U, typename V> inline void addMo...
#include <bits/stdc++.h> using namespace std; long long a[100069], f[100069], p10[10]; int main() { long long t, rr, k, i, p, z, pp, ppp, zzz; p10[0] = 1; for (i = 1; i < 10; i++) { p10[i] = p10[i - 1] * 10; } for (i = 1; 1; i++) { f[i] = f[i - 1]; for (k = i; k > 0; k /= 10)...
#include <bits/stdc++.h> using namespace std; template <typename S, typename T> ostream& operator<<(ostream& out, const pair<S, T> p) { out << ( << p.first << , << p.second << ) ; return out; } template <typename T> ostream& operator<<(ostream& out, const vector<T>& v) { for (auto a : v) ou...
#include <bits/stdc++.h> inline long long rd() { long long _x = 0; int _ch = getchar(), _f = 1; for (; !isdigit(_ch) && (_ch != - ) && (_ch != EOF); _ch = getchar()) ; if (_ch == - ) { _f = 0; _ch = getchar(); } for (; isdigit(_ch); _ch = getchar()) _x = _x * 10 + _ch - 0 ...
#include <bits/stdc++.h> using namespace std; int main() { long long int n, l, r; cin >> n >> l >> r; long long int dp[n][3]; long long int a = r / 3 - (l - 1) / 3; long long int b = (r + 2) / 3 - (l + 1) / 3; long long int c = (r + 1) / 3 - l / 3; dp[0][0] = r / 3 - (l - 1) / 3; dp[...
#include <bits/stdc++.h> using namespace std; int main() { int t, n, a[1000], d; cin >> t; while (t--) { cin >> n; for (int i = 0; i < n; i++) { cin >> a[i]; } sort(a, a + n); d = 0; for (int i = 1; i < n; i++) { if (a[i] - a[i - 1] <= 1) { d...
#include <bits/stdc++.h> using namespace std; int n, m; int p[100]; char mm[100]; int main() { while (scanf( %d , &n) != EOF) { scanf( %s , &mm); int len = strlen(mm); m = 0; for (int i = 0; i < len; ++i) m = m * 10 + (mm[i] - 0 ); if (n == 0) { if (strlen(mm) != 1) ...
#include <bits/stdc++.h> using namespace std; const int MX_N = 3e5 + 5; const int MX_M = 3e5 + 5; int N, M, D[MX_N]; vector<pair<int, int>> al[MX_N]; int vis[MX_N], sumD; vector<int> edges; void dfs(int u, int p = 0, int pe = 0) { vis[u] = 1; for (auto v : al[u]) if (!vis[v.first]) { ...
#include <bits/stdc++.h> long long RemoveZeros(long long a) { long long temp; long long x = 0; long long i = 10; while (a > 0) { if (a % 10 != 0) { temp = (a % 10) * i; x += temp; i *= 10; } a /= 10; } return x / 10; } using namespace std; int ma...
#include <bits/stdc++.h> using namespace std; using li = long long; using ld = long double; using pii = pair<int, int>; const int INF = 1e9 + 13; const int N = 2e5 + 13; const int M = 1e9 + 7; const int B = 600; const int A = 256; const ld e = 1e-8; const int LOGN = 20; mt19937 rnd(time(0)); v...
#include <bits/stdc++.h> #pragma GCC optimize 03 using namespace std; const int N = 1e5 + 5; const int mod = 1e9 + 7; const int inf = 1e9 + 9; pair<int, int> ans[1004]; signed main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); string s; cin >> s; int c1 = 0, c2 = 0; ...
#include <bits/stdc++.h> const int MAX_N = 1e5 + 5; int n, m; char str[MAX_N], nxt[256]; bool chk[256], vis[256], not_root[256], flag; std::vector<char> ans; void dfs(char c) { if (!vis[c]) { vis[c] = true; ans.push_back(c); if (nxt[c]) dfs(nxt[c]); } else flag = true; } ...
#include <bits/stdc++.h> using namespace std; const int N = 1e6; int A[5]; int main() { ios_base::sync_with_stdio(0); int a, b, n, T, cas = 0; cin >> T; while (T--) { cin >> A[0] >> A[1] >> A[2]; int cnt = 0; sort(A, A + 3, greater<int>()); for (int i = 0; i < 3; ++i) { ...
#include <bits/stdc++.h> using namespace std; struct S { int a, b; S() {} S(int _a, int _b) { a = _a; b = _b; } const bool operator<(const S &o) const { return a < o.a; } }; string exm; inline void exf(void) { cout << exm << n ; exit(0); } template <typename T> ...
#include <bits/stdc++.h> using namespace std; void qmax(int &x, int y) { if (x < y) x = y; } void qmin(int &x, int y) { if (x > y) x = y; } inline long long read() { char s; long long k = 0, base = 1; while ((s = getchar()) != - && s != EOF && !(isdigit(s))) ; if (s == EOF) e...
#include <bits/stdc++.h> using namespace std; long long read() { long long a = 0; char c = getchar(); while (c > 9 || c < 0 ) c = getchar(); while ( 0 <= c && c <= 9 ) { a = a * 10 + c - 48; c = getchar(); } return a; } struct data { long long x, y, c; data(long ...
#include <bits/stdc++.h> #pragma GCC optimize( O3 ) #pragma GCC target( sse4 ) using namespace std; using ii = pair<int, int>; using ll = long long; const int N = 1e5 + 5; const int mod = 1e9 + 7; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int a, b; cin >> a >> b; vector<...
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 10; int t; int n; struct node { long long id, val; bool flag; friend bool operator<(node a, node b) { if (a.val == b.val) return a.flag == false; return a.val > b.val; } }; int main() { while (~scanf( %d ,...
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7, inf = 1061109567; const long long infll = 4557430888798830399; const int N = 2e5 + 5; int n, q, a[N], cnt[N]; bool last[N], first[N]; vector<int> app[N]; bool start[N]; signed main() { ios_base::sync_with_stdio(false); cin....
#include <bits/stdc++.h> const int MAXN = (int)1e5 + 5; const int MODN = (int)1e9 + 7; int inf = 0x3f3f3f3f; using namespace std; char str[MAXN]; int num[MAXN]; int a[MAXN]; int vis[MAXN]; int main() { int n, m; while (scanf( %d , &n) != EOF) { memset(vis, 0, sizeof(vis)); int sum ...
#include <bits/stdc++.h> using namespace std; int cntinv(vector<int> &a) { int n = a.size(); int ans = 0; for (int i = 0; i < n; ++i) { for (int j = i + 1; j < n; ++j) { if (a[j] < a[i]) ans++; } } return ans; } int main(int argc, char const *argv[]) { int n; scan...
#include <bits/stdc++.h> using namespace std; int n; int a[100010], d[100010]; int main() { int ans = 1, i, j; int temp; int dlen = 0, mx = 0; while (~scanf( %d , &n)) { for (i = 0; i != n; ++i) { dlen = mx = 0; scanf( %d , &temp); for (j = 2; j * j <= temp; j++) { ...
#include <bits/stdc++.h> using namespace std; struct UF { vector<int> par, sz; UF(int n) { sz.resize(n); par.resize(n); for (int i = 0; i < n; i++) sz[i] = 1, par[i] = i; } int find(int x) { if (par[x] == x) return x; return par[x] = find(par[x]); } void unite(i...
#include <bits/stdc++.h> using namespace std; const int maxn = (int)1e6 + 100; const long long inf = (1ll << 60); const int mod2 = (int)998244353; const int mod = (int)1e9 + 7; int n, m; vector<long long> b; vector<long long> c; void add(long long x) { for (int i = 0; i < b.size(); i++) { if...
#include <bits/stdc++.h> using namespace std; inline int read() { int X = 0, w = 1; char c = getchar(); while (c < 0 || c > 9 ) { if (c == - ) w = -1; c = getchar(); } while (c >= 0 && c <= 9 ) X = X * 10 + c - 0 , c = getchar(); return X * w; } const int N = 1000 + 1...
#include <bits/stdc++.h> using namespace std; char orz[500001]; int gg[500001]; int t; int main() { cin >> t; while (t--) { int n, q; scanf( %d%d , &n, &q); scanf( %s , orz + 1); int rrr = 1; for (int i = 1; i <= n; i++) { if (orz[i] == + ) gg[i] = gg[i...
#include <bits/stdc++.h> using namespace std; struct debugger { template <typename T> debugger& operator,(const T& v) { cerr << v << ; return *this; } } dbg; void solve() { int n, m; cin >> n >> m; for (int i = 0; i < 200; i++) cout << 9 ; cout << endl; for (int i...
#include <bits/stdc++.h> using namespace std; const long long MOD = 1e9 + 7; vector<vector<long long>> mul(vector<vector<long long>> A, vector<vector<long long>> B) { int n = A.size(); vector<vector<long long>> res(n, vector<long long>(n)); for (int i = 0; i < n; i++) {...
#include <bits/stdc++.h> using vi = std::vector<long long int>; using vvi = std::vector<vi>; using pii = std::pair<long long int, long long int>; using vpii = std::vector<pii>; using vvpii = std::vector<vpii>; using namespace std; const long long int N = 2e6 + 10; const long long int inf = 1e18 + 10; ...
#include <bits/stdc++.h> using namespace std; int a[610000], i, j, k, l, n, m, p[610000], t, last, o, r, mid; char c[610000]; bool check(int mid) { int tmp = 1e9, res = 0; p[0] = mid; m = last; for (i = 1; i <= n; ++i) { p[i] = p[i - 1] + a[i]; if (p[i] == 0 && p[i - 1] == -1) m = ma...
#include <bits/stdc++.h> using namespace std; const int max_n = 2005; string str[max_n]; int dp[max_n][max_n][4]; inline void solve() { register int n, m, i, j, k; long long ans = 0; cin >> n >> m; for (i = 0; i < n; ++i) cin >> str[i]; for (i = 0; i < n; ++i) { dp[i][0][0] = 1; ...
#include <bits/stdc++.h> using namespace std; int a[111111], b[111111]; vector<int> id[111111]; int main() { int N, M; cin >> N >> M; for (int i = 1; i <= N; i++) id[i].clear(); for (int i = 0; i < M; i++) scanf( %d , a + i); long long tot = 0; for (int i = 1; i < M; i++) { if (a[i...
#include <bits/stdc++.h> using namespace std; const long long N = 1e5 + 5; vector<long long> tim(N), pos(N), cur(N); int main() { long long T, n, act, start, des, dir, ans, startTime; cin>>T; for(long long t = 1; t <= T; ++t) { tim[0] = pos[0] = start = des = act = ans = startTime...
#include <bits/stdc++.h> using namespace std; int max_can; pair<int, int> red, blue; int main() { scanf( %d%d%d%d%d , &max_can, &red.first, &blue.first, &red.second, &blue.second); long long ans = 0; int sq = (int)sqrt(max_can); if (red.second >= sq) { for (int cnt = 0;; ++cnt) {...
#include <bits/stdc++.h> using namespace std; inline long long read() { long long x = 0, f = 0; char ch = getchar(); while (!isdigit(ch)) f |= (ch == - ), ch = getchar(); while (isdigit(ch)) x = x * 10 + ch - 0 , ch = getchar(); return f ? -x : x; } inline void write(long long x) { if ...
#include <bits/stdc++.h> int main() { int loop, cnt = 1, max = 1; scanf( %d , &loop); int arr[loop]; for (int i = 0; i < loop; i++) scanf( %d , &arr[i]); for (int i = 1; i < loop; i++) { if (arr[i - 1] >= arr[i]) { cnt = 1; } if (arr[i - 1] < arr[i]) { cnt++; ...
#include <bits/stdc++.h> using namespace std; multiset<int> ms; const int MAXN = 1000000; int pos[MAXN], a[MAXN], b[MAXN], st[MAXN]; int n, i, j, k, ans; int main() { scanf( %d , &n); for (i = 1; i <= n; ++i) { scanf( %d , &a[i]); pos[a[i]] = i; } for (j = 1; j <= n; ++j) { ...
#include <bits/stdc++.h> #pragma GCC optimize( Ofast ) #pragma GCC optimize( unroll-loops ) using namespace std; const long long N = 1000 + 5, L = 12, inf = LLONG_MAX; long long n, m, k; long long a[N][N], par[N * N], sz[N * N], res[N][N], hh, cnt; bool mark[N][N], vis[N][N]; long long mp[N * N]; vect...
#include <bits/stdc++.h> using namespace std; long long n, m; long long dp[1501][1501]; long long a[1510][1501]; long long func(long long here, long long here1) { if (here1 > m) return -999999999999999; if (here1 < 1) return -999999999999999; if (here == n + 1) return 0; long long &ret = dp[he...
#include <bits/stdc++.h> using namespace std; long long n, m, i, j, k, mod, dp[605][605], rd[605], xs[605][605], ans = 1; vector<long long> ts, bi[605], nrd, ncd; 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 ...