func_code_string
stringlengths
59
71.4k
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 22; int n, mn = N + 1, q; int par[N], ans[N]; bool mark[N]; vector<int> G[N]; void dfs(int v, int p, int rr) { rr = min(rr, v); ans[v] = rr; par[v] = p; for (int i = 0; i < (G[v].size()); i++) { int u = G[v][i]; ...
#include <bits/stdc++.h> using namespace std; int main() { int t; t = 1; while (t--) { int n, k; cin >> n >> k; string s; cin >> s; int b[26] = {0}; for (int i = 0; i < n; i++) { b[s[i] - A ]++; } int mn = INT_MAX; for (int i = 0; i < k; i++...
#include <bits/stdc++.h> using namespace std; int n, u, r; int a[30], b[30], p[30], k[30]; long long res; bool first; void doit(int v[]) { long long tmp = 0; for (int i = 0; i < n; i++) { tmp += v[i] * k[i]; } res = max(res, tmp); if (first) { first = false; res = tmp; ...
#include <bits/stdc++.h> using namespace std; struct Event { char r; int pos; Event(char r = , int pos = -1) : r(r), pos(pos) {} }; bool operator<(Event a, Event b) { if (a.r != b.r) return a.r > b.r; return a.pos < b.pos; } vector<Event> v; int main() { string s; cin >> s; ...
#include <bits/stdc++.h> using namespace std; const int Maxn = 110; int N, A[Maxn]; map<int, int> K, dp; int SG(int x) { set<int> S; if (dp.count(x)) return dp[x]; if (x == 0) return 0; for (int i = 1; i <= 30; i++) { int y = (x >> i) | (x & ((1 << (i - 1)) - 1)); if (y != x) ...
#include <bits/stdc++.h> using namespace std; long long dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1}; long long ddx[8] = {1, 1, 0, -1, -1, -1, 0, 1}, ddy[8] = {0, 1, 1, 1, 0, -1, -1, -1}; long long gcd(long long a, long long b) { if (!a) return b; return gcd(b % a, a); } long long lcm(lo...
#include <bits/stdc++.h> const long double eps = 1e-6; struct Point { long long x, y; Point(long long _x = 0, long long _y = 0) : x(_x), y(_y) {} Point operator-(const Point &B) const { return Point(x - B.x, y - B.y); } long double operator*(const Point &B) const { return (long double)x * B.y ...
#include <bits/stdc++.h> #pragma GCC optimize(2) using namespace std; void qread(int &x) { int neg = 1; x = 0; char c = getchar(); while (c < 0 || c > 9 ) { if (c == - ) neg = -1; c = getchar(); } while (c >= 0 && c <= 9 ) x = 10 * x + c - 0 , c = getchar(); x *= ne...
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 10; int n, k; int pr[N], sz[N]; int root(int x) { return pr[x] = (pr[x] == x ? x : root(pr[x])); } void merge(int x, int y) { x = root(x); y = root(y); if (x == y) return; if (rand() & 1) { pr[x] = y; sz[y] += sz[x...
#include <bits/stdc++.h> using namespace std; int n; int A[3005][5], dp[3005][3]; int solve(int x, bool a) { int &r = dp[x][a]; if (r != -1) return r; if (x == n) { if (a == 0) { return r = A[x][1]; } else { return r = A[x][2]; } } if (a == 0) { return...
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const int MAXN = 5000 + 5; const int MOD = 1e9 + 7; const double pi = cos(-1); int n, d, ans[MAXN], fa[MAXN]; int c, now, maxx, cnt, pos; int ch[MAXN]; int getdepth() { int ans_t = now; c++; if (c == maxx) { c ...
#include <bits/stdc++.h> using namespace std; using ll = long long; template <class t, class u> void chmax(t& first, u second) { if (first < second) first = second; } template <class t, class u> void chmin(t& first, u second) { if (second < first) first = second; } template <class t> using v...
#include <bits/stdc++.h> #pragma comment(linker, /STACK:66777216 ) using namespace std; int a, b, c, d, i, j, n, m, k; void brute() { int mas[4][4]; vector<int> num; memset((mas), 0, sizeof(mas)); for (int _n((n * n) - 1), i(0); i <= _n; i++) { scanf( %d , &a); num.push_back(a); ...
#include <bits/stdc++.h> using namespace std; const int N = 3e5 + 10; long long n, m, q, u, v, l, r, c, res, sum[N], p[N], lmt[N], vst[N]; vector<long long> adj[N], vec; void dfs(int u, int p) { vst[u] = 1; vec.push_back(u); for (auto v : adj[u]) { if (vst[v] == 2) continue; if (vst[v]...
#include <bits/stdc++.h> using namespace std; using ll = long long; template <typename T> ostream& operator<<(ostream& os, const vector<T>& v) { for (T e : v) { os << e << ; } return os; } constexpr ll mod = 998244353; constexpr int maxn = 502; ll lte[maxn]; ll dp[maxn]; int mai...
#include <bits/stdc++.h> using namespace std; int in[2 * 100010], s[2 * 100010]; int n; int main() { scanf( %d , &n); memset(in, 0, sizeof(in)); memset(s, 0, sizeof(s)); for (int i = 0; i < n; i++) { int xx; scanf( %d , &xx); s[i] = xx; in[xx] = i + 1; } int t = 0...
#include <bits/stdc++.h> using namespace std; int N, M; long long K; int A[505][505]; vector<int> goods, bads; int remap[505]; double P[505][505]; typedef double matrix[105][105]; void mult(matrix A, matrix B, matrix C) { matrix temp; memset(temp, 0, sizeof(temp)); for (int i = 0; i < 105;...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; long long arr[n]; int i; map<long long, int> mp; for (i = 0; i < n; i++) { int t; cin >> t; mp[t]++; } auto it = mp.begin(); int maxe = 0; while (it != mp.end()) { if (it->seco...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int count0(0), count5(0); for (int i = 1; i <= n; i++) { int a; cin >> a; if (a == 0) count0++; if (a == 5) count5++; } if (count0 == 0) cout << -1; else if (count5 < 9) cout <...
#include <bits/stdc++.h> using namespace std; int A[20][6], n, B[4]; bool check(int l) { int a0 = 0, a1 = 0, i, j; for (i = 0; i < 4; i++) for (j = i + 1; j < 4; j++) if (B[i] == B[j]) return 0; for (i = 0; i < 4; i++) { a0 += (int)(B[i] == A[l][i + 2]); for (j = 0; j < 4; j+...
#include <bits/stdc++.h> using namespace std; void OUT_TST(string s, istream_iterator<string> it) { cerr << s; } template <typename T, typename... Args> void OUT_TST(string s, istream_iterator<string> it, T a, Args... args) { cerr << *it << = << a << ; OUT_TST(s, ++it, args...); } template <cla...
#include <bits/stdc++.h> using namespace std; vector<pair<char, long long int>> vp(4000005); void ans(vector<long long int> dp, vector<long long int> star, long long int x, vector<pair<char, long long int>> &vp, long long int n, long long int &flag) { if (x <= 1) { return; } ...
#include <bits/stdc++.h> using namespace std; const int INF = 1 << 29; const double PI = acos(-1); const double EPS = 1e-8; void func(vector<pair<int, int> > &v) { sort((v).begin(), (v).end()); int start = -1; int end = -1; vector<pair<int, int> > res; for (int i = 0; i < (int)v.size(); ++...
#include <bits/stdc++.h> using namespace std; const int mod = 1000000007; int main() { int t; cin >> t; for (int tc = 0; tc < t; tc++) { long long a, b, c, d; cin >> a >> b >> c >> d; int temp = 1; if (a % 2) { temp *= -1; } if (b % 2) { temp *= -1; ...
#include <bits/stdc++.h> using namespace std; const int MAX = 5 * (1e5 + 5); vector<int> e[MAX]; vector<int> ice[MAX]; int n, m; int ans[MAX]; bool vis[MAX]; int cnt; void dfs(int now, int pre) { int len = ice[now].size(); for (int i = 0; i <= len; i++) vis[i] = 0; for (int i = 0; i < len;...
#include <bits/stdc++.h> int n, nxt[100005], fa[100005]; int find(int x) { return fa[x] == x ? x : fa[x] = find(fa[x]); } int main(void) { scanf( %d , &n); if (n % 2) { puts( -1 ); return 0; } for (int i = 0; i <= n; i++) fa[i] = i; for (int i = 0; i < (n / 2); i++) { int j =...
#include <bits/stdc++.h> using namespace std; int main() { int n, a; cin >> n >> a; vector<int> m(n); for (int i = 0; i < n; i++) cin >> m[i]; n--; a--; int calc = 0; if (m[a]) calc++; for (int j = 1; j <= max(n - a, a); j++) { if (a - j < 0) { if (m[a + j]) calc++;...
#include <bits/stdc++.h> using namespace std; int n; int arities[100001]; int legs[100001]; bool markers[100001]; list<int> graph[100001]; void parse() { int a, b; cin >> n; for (int it = 0; it < (100001); it++) { (arities)[it] = (0); }; for (int it = 0; it < (100001); it++) { ...
#include <bits/stdc++.h> using namespace std; char stra[110]; char strb[110]; int mark[110]; int g[11000]; int main() { int b, d; scanf( %d%d , &b, &d); scanf( %s , stra); scanf( %s , strb); int lena = strlen(stra); int lenb = strlen(strb); memset(mark, -1, sizeof(mark)); mar...
#include <bits/stdc++.h> using namespace std; unordered_map<long long, string> Map; unordered_map<long long, string>::iterator it; string Get(long long x) { string ans = ; int s[13], cnt = 0; while (x) { s[++cnt] = x % 10; x /= 10; } for (int i = cnt; i >= 1; i--) ans += char(s...
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e3 + 13; const int INF = 1e6 + 7; int t[MAXN][MAXN]; int tab[MAXN * MAXN]; bool odw[MAXN * MAXN]; int wyn[MAXN * MAXN]; bool prze[MAXN * MAXN]; int xx[4] = {0, 0, -1, 1}; int yy[4] = {-1, 1, 0, 0}; vector<int> v[MAXN * MAXN]; int ch...
#include <bits/stdc++.h> using namespace std; string s; pair<int, int> a[100003]; int l = 0; bool lios(string s) { if (s.size() < 4) return false; if (s.substr(s.size() - 4, 4) == lios ) return true; return false; } bool liala(string s) { if (s.size() < 5) return false; if (s.substr(s...
#include <bits/stdc++.h> using namespace std; const long long INF = 1e15; long long binpow(long long a, long long b) { long long res = 1; while (b > 0) { if (b & 1) { res = res * a; } a = a * a; b >>= 1; } return res; } long long dp[205][205][205]; int32_t mai...
#include <bits/stdc++.h> using namespace std; const int max_n = 1011, inf = 1000111222; int n, a[max_n][max_n], x[max_n]; int main() { scanf( %d , &n); for (int i = 0; i < n; ++i) { for (int j = 0; j < n; ++j) { scanf( %d , &a[i][j]); } } long long val = 1LL * a[0][1] * a[0][...
#include <bits/stdc++.h> using namespace std; const int di[] = {-1, 0, 1, 0}; const int dj[] = {0, 1, 0, -1}; const long long MOD = 1e9 + 7; const long long INF = 1e9; const double EPS = 1e-11; int main() { ios::sync_with_stdio(false), cin.tie(0); int n, q, c; cin >> n >> q >> c; vector<pa...
#include <bits/stdc++.h> using namespace std; int t[200005], revt[200005]; int main() { ios::sync_with_stdio(0); int n; cin >> n; for (int i = 1; i <= n; i++) { cin >> t[i]; revt[t[i]]++; } int ans = 1; for (int i = 0; i <= n; i++) ans += max(0, revt[i] - 1); cout << an...
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 10; int l[maxn]; int r[maxn]; int mx[maxn]; int main() { ios::sync_with_stdio(0); cin.tie(0); int n; cin >> n; long long ans = n; for (int i = 1; i <= n; i++) { cin >> l[i] >> r[i]; } sort(l + 1, l + 1...
#include <bits/stdc++.h> using namespace std; bool vowel(char a) { a = toupper(a); if ((a == A ) || (a == E ) || (a == I ) || (a == O ) || (a == U )) return 1; return 0; } long long int n, m, q, a, b, c, sum = 0, cnt = 0; long long int arr[2000005]; map<long long int, bool> mp; stri...
#include <bits/stdc++.h> using namespace std; int main() { string a[6], b[6], c[6]; a[0] = purple ; b[0] = Power ; a[1] = green ; b[1] = Time ; a[2] = blue ; b[2] = Space ; a[3] = orange ; b[3] = Soul ; a[4] = red ; b[4] = Reality ; a[5] = yellow ; b[5]...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; long long int cur = 1; long long num = 1; while (cur != n + 1) { if (cur != 1) cout << cur * 1ll * cur * 1ll * cur + 2 * cur * cur + 1; else cout << 2; cout << endl; cur++; } ...
#include <bits/stdc++.h> using namespace std; long long n, m, cnt[100005], root, par[100005], br[100005], st[100005], brcnt; vector<long long> a[100005]; pair<long long, long long> vert[100005]; map<pair<long long, long long>, long long> mm; set<long long> brcl; long long tmp = 1; void dfs(long long v) ...
#include <bits/stdc++.h> using namespace std; int main() { long long i, j, c, pi, pj, max, a[10][10]; char s[10][10]; c = 3; for (i = 0; i < 6; i++) { if (i % 2 == 0 && i > 0) c--; a[i][0] = c; a[i][1] = c; } c = 4; for (i = 0; i < 6; i++) { if (i % 2 == 0 && i > ...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> A(n + 10, 0); for (int i = 0; i < n; i++) cin >> A[i]; unordered_map<long long, int> fir, sec; fir[A[0]] = 1; for (int i = 1; i < n; i++) sec[A[i]]++; long long S = 0; for (int i = 0; i < n; i...
#include <bits/stdc++.h> using namespace std; long long n, a, b, k; long long q; long long param = 0; string ciag; long long MOD = 1000000009; long long potega(long long a_1, long long n_1) { if (n_1 == 0) return 1; if (n_1 == 1) return a_1; else if (n_1 % 2 == 0) { long long s = p...
#include <bits/stdc++.h> using namespace std; long double dist(long double x, long double y, long double a, long double b) { return sqrt((a - x) * (a - x) + (y - b) * (y - b)); } long double distMan(long double x, long double y, long double a, long double b) { return abs(x - a) + a...
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; long long fp(long long x, long long y) { long long res = 1; while (y) res = (y & 1) ? res * x % mod : res, x = x * x % mod, y >>= 1; return res; } int t; int n, m, rb, cb, rd, cd, lx = 1, ly = 1; long long p; void dfs(int...
#include <bits/stdc++.h> using namespace std; const int MAX = 5005; int n, T; int pp[MAX]; int t[MAX]; double p[MAX]; double ps[MAX]; double pl[MAX]; double dp[2][MAX]; int main(void) { scanf( %d%d , &n, &T); for (int i = (0); i < (n); ++i) scanf( %d%d , pp + i, t + i); for (int i = (0);...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); long long 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 int dp[n]; memset(dp, 0, sizeof(dp)); lon...
#include <bits/stdc++.h> using namespace std; int main() { int x, t, a, b, da, db; cin >> x >> t >> a >> b >> da >> db; if (x == 0) { cout << YES << endl; return 0; } for (int i = 0; i < t; i++) { if (a - da * i == x) { cout << YES << endl; return 0; }...
#include <bits/stdc++.h> using namespace std; void FAST() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); } int gcd(int x, int y) { if (x == 0) return y; return gcd(y % x, x); } int powM(int x, int y, int m) { int ans = 1, r = 1; x %= m; while (r > 0 && r <= y) { if...
#include <bits/stdc++.h> using namespace std; using LL = long long int; struct point { LL x, y; point(LL x_ = 0, LL y_ = 0) : x(x_), y(y_) {} point operator-(const point& b) { return point(x - b.x, y - b.y); } point operator+(const point& b) { return point(x + b.x, y + b.y); } }; LL cross_abs(...
#include <bits/stdc++.h> using namespace std; long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; } void solve() { int n; cin >> n; vector<long long> a(n); for (int i = 0; i < n; i++) cin >> a[i]; if (n == 1) { cout << 1 n ; return; } vector<long long> ...
#include <bits/stdc++.h> #pragma comment(linker, /stack:247474112 ) #pragma GCC optimize( Ofast ) using namespace std; const long long maxn = 2e5 + 10; long long mx[maxn], val[maxn], sum[maxn]; vector<long long> g[maxn]; long long pass[maxn]; bool ok = 0; long long ans = LLONG_MIN; void dfs(long lo...
#include <bits/stdc++.h> using namespace std; long long second; long long a1[1231], a2[2131]; long long b[1231]; long long sum[1231]; int main() { int n; cin >> n; for (int i = 2; i <= n; i++) cin >> a1[i]; for (int i = 1; i <= n - 1; i++) cin >> a2[i]; for (int i = 1; i <= n; i++) { ...
#include <bits/stdc++.h> using namespace std; long long inf; const double eps = 1e-8; const double pi = acos(-1.0); template <class T> long long chkmin(T &a, T b) { return a > b ? a = b, 1 : 0; } template <class T> long long chkmax(T &a, T b) { return a < b ? a = b, 1 : 0; } template <clas...
#include <bits/stdc++.h> using namespace std; template <typename T1, typename T2> istream &operator>>(istream &in, pair<T1, T2> &a) { in >> a.first >> a.second; return in; } template <typename T1, typename T2> ostream &operator<<(ostream &out, pair<T1, T2> a) { out << a.first << << a.second;...
#include <bits/stdc++.h> using namespace std; int main() { string s[50]; bool ada[256] = {0}; double dekat[256]; for (int i = 0; i < 256; i++) dekat[i] = 1000000000.0; int n, m; double x; cin >> n >> m >> x; for (int i = 0; i < n; i++) cin >> s[i]; vector<pair<int, int> > v; ...
#include <bits/stdc++.h> using namespace std; int main() { int n, a, b, cnt = 1, point = 0; vector<int> x; cin >> n; for (int i = 0; i < n; i++) { cin >> a >> b; if (b == 0) x.push_back(a); else { cnt += (b - 1); point += a; } } sort(x.begin(),...
#include <bits/stdc++.h> using namespace std; inline int read() { char ch = getchar(); int nega = 1; while (!isdigit(ch)) { if (ch == - ) nega = -1; ch = getchar(); } int ans = 0; while (isdigit(ch)) { ans = ans * 10 + ch - 48; ch = getchar(); } if (nega == -...
#include <bits/stdc++.h> using namespace std; int n, x[101000], y[101000], fa[101000], sz[101000], tot[101000], u, v; map<int, vector<int> > xx, yy; map<int, vector<int> >::iterator it; long long ans = 1, er[202000]; int GF(int x) { return fa[x] == x ? x : fa[x] = GF(fa[x]); } void doit(vector<int> &the) ...
#include <bits/stdc++.h> using namespace std; const double pi = acos(-1); int ans, pos[120000], fa[21][120000], tim, dep[120000], K, n, x, y; vector<int> E[120000]; struct wph { bool operator()(const int x, const int y) { return pos[x] < pos[y]; } }; set<int, wph> S; void prep(int x, int ff) { f...
#include <bits/stdc++.h> using namespace std; const long long int mod = 1e9 + 7; const long long int lim = 1e17; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long int T = clock(); long long int n, k; cin >> n >> k; map<long long int, long long in...
#include <bits/stdc++.h> using namespace std; char a[103], b[103], c[103]; char aa[103], bb[103], cc[103]; char temp[103]; int temp2; char ss[602]; char s[602]; int n; int main() { scanf( %s%s%s , aa, bb, cc); scanf( %d , &n); int i, j, jj; int coun1 = 0, coun2 = 0, coun3 = 0; for ...
#include <bits/stdc++.h> using namespace std; int n; vector<int> arr; int dp[101][101][101][2]; int solve(int index, int even, int odd, int pre) { if (index == n + 1) return 0; if (dp[index][even][odd][pre] != -1) return dp[index][even][odd][pre]; if (arr[index] != 0) { int ans = solve(index...
#include <bits/stdc++.h> using namespace std; const int MAX = 2e5 + 5; int parent[MAX]; int depth[MAX]; int get(int a) { while (a != parent[a]) a = parent[a]; return a; } void join(int a, int b) { a = get(a); b = get(b); if (a == b) return; if (depth[a] > depth[b]) swap(a, b); ...
#include <bits/stdc++.h> using namespace std; int main() { string s; getline(cin, s); long long n = s.length(), i = n - 1; while (1) { if ((s[i] >= 65 && s[i] <= 91) || (s[i] >= 97 && s[i] <= 122)) { if (s[i] == a || s[i] == y || s[i] == e || s[i] == i || s[i] == o...
#include <bits/stdc++.h> using namespace std; const int INF = 1 << 30; const long long inf = 1LL << 60; const int N = 200010; struct Edge { int to, next; } e1[N], e2[N]; int list1[N], list2[N], d1, d2; priority_queue<pair<int, int> > Q; queue<int> S; bool vis[N]; vector<int> v[N]; void add(i...
#include <bits/stdc++.h> using namespace std; int main() { int n; int t; cin >> t; while (t--) { int n; cin >> n; long long move = 0; for (int i = 1; i <= n / 2; ++i) { move += i * 1ll * i; } cout << move * 8 << endl; } return 0; }
#include <bits/stdc++.h> int n, m, x, i, ans; int main() { scanf( %d , &n); for (i = 1; i <= n; i++) { scanf( %d , &x); if (x == 2) ++m; } if (n == 1) ans = 1; if (n == 2 && m == 0) ans = 2; if (n == 2 && m == 1) ans = 2; if (n == 2 && m == 2) ans = 2; if (n == 3 && m == ...
#include <bits/stdc++.h> using namespace std; int main() { int x, t, a, b, da, db; while (cin >> x >> t >> a >> b >> da >> db) { bool f = 0; for (int i = 0; i <= t; i++) { for (int j = 0; j <= t; j++) { int t1, t2; if (i == t) t1 = 0; else ...
#include <bits/stdc++.h> using namespace std; int n, ans; int a[19]; int inv[2000009]; int f[17009]; int tag[19]; int qpow(int a, int b) { int ans = 1; for (; b; b >>= 1, a = (long long)a * a % 1000000007) if (b & 1) ans = (long long)ans * a % 1000000007; return ans; } void init() { ...
#include <bits/stdc++.h> using namespace std; void func(void) { freopen( input.c , r , stdin); freopen( output.c , w , stdout); } void print(vector<long long> &v) { cout << v.size() << endl; for (int i = 0; i < v.size(); i++) { printf( %lld , v[i]); } printf( n ); } void pr...
#include <bits/stdc++.h> using namespace std; int flag = 0, ans, n; int r[10], d[12], l[12], u[12]; int print(int x1, int y1, int x2, int y2) { cout << ? << x1 << << y1 << << x2 << << y2 << endl; int val; cin >> val; if (flag) { if (x1 <= l[0] && r[0] <= x2 && y1 <= d[0] && ...
#include <bits/stdc++.h> using namespace std; const int maxn = (int)2e5 + 88; char tu[maxn]; int lu[maxn]; int main() { int n, a, b, k; cin >> n >> a >> b >> k; scanf( %s , tu); for (int i = 0; i < maxn; i++) { lu[i] = 0; } int ans = 0; int ant = 0; int ttt = 0; for (...
#include <bits/stdc++.h> using std::cerr; using std::cin; using std::cout; using std::endl; using std::list; using std::map; using std::max; using std::min; using std::pair; using std::set; using std::sort; using std::string; using std::swap; using std::vector; const int MAXN = 100005; c...
#include <bits/stdc++.h> #pragma clang diagnostic push #pragma clang diagnostic ignored -Wunused-const-variable using namespace std; template <typename T> class Modular { public: using Type = typename decay<decltype(T::value)>::type; constexpr Modular() : value() {} template <typename U> ...
#include <bits/stdc++.h> using namespace std; int sum[501000 << 2], sum2[501000 << 2]; void pushUp(int rt) { sum[rt] = max(sum[rt * 2], sum[rt * 2 + 1]); } void updata(int l, int r, int rt, int q, int val) { if (l == q && r == q) { sum[rt] = val; return; } int m = (l + r) / 2; if (q ...
#include <bits/stdc++.h> using namespace std; int main() { int i, n, k, s = 0, m; vector<pair<int, int> > v(110); scanf( %d , &n); scanf( %d , &k); for (i = 0; i < n; ++i) { scanf( %d , &v[i].first); v[i].second = i + 1; } sort(v.begin(), v.begin() + n); for (i = 0; s <= ...
#include <bits/stdc++.h> using namespace std; int read() { int v = 0, f = 1; char c = getchar(); while (c < 48 || 57 < c) { if (c == - ) f = -1; c = getchar(); } while (48 <= c && c <= 57) v = (v << 3) + v + v + c - 48, c = getchar(); return v * f; } const int N = 5e5 + 100,...
#include <bits/stdc++.h> using namespace std; long long n, x, f[101][101][101], g[101]; char s[101]; int main() { scanf( %I64d%I64d%s , &n, &x, s + 1); for (long long i = 1; i <= n; i++) f[s[i] - 0 ][i][i] = 1; g[0] = g[1] = 2; for (long long i = 2; i <= x; i++) g[i] = g[i - 1] * g[i - 2] % 100...
#include <bits/stdc++.h> using namespace std; string s[110]; int n, d; int m; int main() { cin >> n >> d; cin >> m; for (int i = 0; i < m; ++i) { int x, y; cin >> x >> y; bool t = false; if (!((x - y) <= d && (x - y) >= -d)) t = true; if (!((x + y) <= n + n - d && (x ...
#include <bits/stdc++.h> const int a = 1 << 18; using namespace std; long long odp[a], n, k, res; vector<int> v[a]; void dfs(int x, int pop) { for (int i = 0; i < v[x].size(); i++) { if (v[x][i] != pop) dfs(v[x][i], x), odp[x] += odp[v[x][i]], res += min(odp[v[x][i]], k - odp[v[x...
#include <bits/stdc++.h> char s[100], Ans[2000]; int n, m, ans, cnt, b[20], a[40][40], p[50], q[50], x[20][20]; void dfs(int c, int d) { if (d == 15) { memset(x, 0, sizeof(x)); for (int i = 1; i <= 28; i++) { if (x[b[p[i]]][b[q[i]]]) return; x[b[p[i]]][b[q[i]]] = x[b[q[i]]][b[p[i]]...
#include <bits/stdc++.h> using namespace std; int b[8]; string str; int main() { int n, i; cin >> n >> str; for (i = 0; i <= (n - 1); i++) switch (str[i]) { case 2 : b[2]++; break; case 3 : b[3]++; break; case 4 : b[2] += 2...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cout << fixed; cout.precision(4); int r, c; cin >> r >> c; int a[r][c]; for (int i = 0; i < r; ++i) { for (int j = 0; j < c; ++j) { cin >> a[i...
#include <bits/stdc++.h> #pragma comment(linker, /STACK:102400000,102400000 ) #pragma GCC optimize( O2 ) using namespace std; const int maxn = 1e4 + 123; int n, k; int a[maxn]; vector<int> ve[4]; long long sum; int main(int argc, char const *argv[]) { std::cin >> n; for (int i = 0; i < n; i++...
#include <bits/stdc++.h> const int inf = 0x3f3f3f3f, Inf = 0x7fffffff; const long long INF = 0x3f3f3f3f3f3f3f3f; __inline__ __attribute__((always_inline)) unsigned int rnd() { static unsigned int seed = 416; return seed ^= seed >> 5, seed ^= seed << 17, seed ^= seed >> 13; } template <typename _Tp> ...
#include <bits/stdc++.h> using namespace std; using namespace std; vector<pair<pair<int, int>, pair<int, int> > > a[300005]; vector<int> g1[300005]; vector<int> g2[300005]; string Max = , Min = ; int ansMax = 0; int ansMin = 0; bool used[300005]; void getMax(int cur) { ansMax++; used[cur...
#include <bits/stdc++.h> char s[520][520]; char q[520][520]; int main() { int n, m; scanf( %d , &n); memset(s, 0 , sizeof(s)); memset(q, 0 , sizeof(q)); q[1][1] = + , q[1][2] = + , q[2][1] = + , q[2][2] = * ; s[1][1] = + , s[1][2] = + , s[2][1] = + , s[2][2] = * ; m = 2; ...
#include <bits/stdc++.h> using namespace std; const int maxN = 110000; int t[4 * maxN], m; int get(int k) { int res = 0; for (int i = k; i >= 0; i = (i & (i + 1)) - 1) { res = max(res, t[i]); } return res; } void update(int k, int delta) { for (int i = k; i <= m; i |= (i + 1)) { ...
#include <bits/stdc++.h> using namespace std; inline int in() { int x, y; y = scanf( %d , &x); return x; } const int N = 300003; int n, m, k; vector<int> g[N], gr[N]; int to[N], from[N], mark[N], res[N], din[N], rem; int x[N], r[N], y[N]; void out() { cout << -1 n ; exit(0); } ...
#include <bits/stdc++.h> using namespace std; const long long N = 4e5 + 5; pair<long long, long long> arr[N]; long long l[N]; long long s[N]; long long dp[N]; long long bit[N]; long long n; void update(long long idx, long long val) { while (idx <= n) { bit[idx] = max(bit[idx], val); id...
#include <bits/stdc++.h> using namespace std; int cnt[100001]; int main() { int n, k; cin >> n; int ans = 1; int m = n; while (n--) { cin >> k; cnt[k] = cnt[k - 1] + 1; ans = max(ans, cnt[k]); } cout << m - ans; }
#include <bits/stdc++.h> char year[10]; int main() { scanf( %s , year); int l = strlen(year) - 1; int num = 0, num2 = 0; for (int i = 0; i <= l; i++) { num = num * 10 + year[i] - 0 ; } for (int i = 1; i <= l; i++) num2 = num2 * 10 + year[i] - 0 ; int x = 1; for (int i = 1; i ...
#include <bits/stdc++.h> #pragma GCC optimize( O3 ) #pragma GCC optimize( unroll-loops ) using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; vector<tuple<int, int, int, int> > v(n); vector<int> used(n, 0); for (int i = 0; i < n; i++) { in...
#include <bits/stdc++.h> using namespace std; const int a = 26; char c[10000], ans[10000]; int p[10000], ap[10000], perm[10000]; map<int, int> m; int main() { string s, st; cin >> s; int n = s.size(), x, t, last, y; x = 17576; for (int i = 0; i < 3; i++) { x /= a; t = 0; ...
#include <bits/stdc++.h> using namespace std; const int lim = 500000001; class TMain { private: int n, m, f[505][505], dis[505][505], ans[505][505], now[505]; public: int run() { scanf( %d %d , &n, &m); for (int i = 1; i <= n; i++) for (int j = 1; j <= n; j++) if (i ...
#include <bits/stdc++.h> using namespace std; int main() { long long k, n, s, p; cin >> k >> n >> s >> p; long long w = n / s; if (n % s != 0) w++; w *= k; long long ans = w / p; if (w % p != 0) ans++; cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; const int N = (int)5e5 + 50; int n; int ans[N]; vector<int> G[N]; int q[N]; int dep[N]; vector<pair<int, int> > hist[N]; void upd(int u, int val) { q[u] = max(q[u], val); } void calc(int v, int p) { dep[v] = 0; for (int nxt : G[v]) { if (nx...
#include <cstdio> #include <iostream> #define ll long long using namespace std; int n , m , cnt = 0; const int N = 5e5 + 5; const int mod = 1e9 + 7; ll pow2[N]; int num[N] , fa[N]; int find(int x){ if(fa[x] == x) return x; return fa[x] = find(fa[x]); } int main(){...