solution
stringlengths
53
181k
difficulty
int64
0
13
#include <bits/stdc++.h> using namespace std; int abv(int x) { return x >= 0 ? x : -x; } int rr[200], cc[200]; int main() { int i, ans, spc, tmp, r, n, rtop, rbott, top, bott; scanf("%d%d", &r, &n); top = 0, bott = 0, rbott = 1, rtop = r; for (i = 0; i < n; i++) { scanf("%d%d", rr + i, cc + i); if (rr[i...
6
#include <bits/stdc++.h> using namespace std; template <typename T> inline bool readn(T &x); inline void rd(); inline void debug(); constexpr int N = 5e5 + 9; constexpr long long mod = 1e9 + 7; int T, n, m, k; long long a[N]; void Dmymax_ly() { rd(); for (readn(T); T; T--) { readn(n); readn(k); for (int...
0
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; string s; cin >> s; int H = 0, T = 0; for (int i = 0; i < n; i++) { if (s[i] == 'H') H++; else T++; } int ans = INT_MAX; for (int i = 0; i < n; i++) { int j, swap = 0; for (j = 0; j < T; j++) { ...
4
#include <bits/stdc++.h> using namespace std; const double EPS = 0.0000001; int n, vs; bool check_poss(int dist, int mid, double t, pair<int, int> x) { double t1 = (double)abs(x.first - mid) / (vs - x.second); if (t1 > t) return 0; double x1 = t1 * x.second; double t2 = (double)abs(dist - x1) / (vs + x.second);...
8
#include <bits/stdc++.h> using namespace std; int foo(int x) { if (x < 0) return -1 * x; else return x; } int main() { int x1, x2, x3, x4, y1, y2, y3, y4; cin >> x1 >> y1 >> x2 >> y2; if (x1 == x2 || y1 == y2 || foo(x2 - x1) == foo(y2 - y1)) { if (x1 == x2) cout << x1 + y2 - y1 << " " << y1 ...
2
#include <bits/stdc++.h> using namespace std; const int MAXN = 5e5 + 50; inline long long int max(long long int a, long long int b) { return ((a > b) ? a : b); } inline long long int min(long long int a, long long int b) { return ((a > b) ? b : a); } inline long long int gcd(long long int a, long long int b) { if...
5
#include <bits/stdc++.h> using namespace std; long long x = 1e11; long long n, k; int main() { cin >> n >> k; for (int i = 1; i < k; i++) if (n % i == 0) x = min(x, (n / i) * k + i); return cout << x << '\n', 0; }
1
#include <bits/stdc++.h> using namespace std; const int N = 577; int n, m, Mod, dp[N], dp2[N], C[N][N], res[N][N], res2[N][N]; inline int GetSum(int l, int r) { return ((l + r) * 1LL * (r - l + 1) / 2) % Mod; } int main() { scanf("%d%d%d", &n, &m, &Mod); for (int i = C[0][0] = 1; i < N; i++) for (int j = C[0]...
11
#include <bits/stdc++.h> const bool debugging = 0; using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long n, k, numMoves; cin >> n >> k; bool isOdd = false; if (n % 2 == 1) { isOdd = true; numMoves = (n - 1) / 2; } else { numMoves = n / 2; } if (k < nu...
3
#include <bits/stdc++.h> #pragma warning(disable : 6031) #pragma warning(disable : 4101) using namespace std; const int INF = 1e9; const long long LINF = 1e18; const double PI = acos(-1); FILE* out = stdout; FILE* in = stdin; const int MAXN = 500005; int n, x, prevv, A[MAXN]; vector<int> ans; int main() { scanf("%d%d...
5
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 10; const long long MOD = 1e9 + 7; long long fact[N]; long long invfact[N]; long long mod_pow(long long x, long long n) { long long res = 1; while (n) { if (n & 1) res = res * x % MOD; x = x * x % MOD; n >>= 1; } return res; } inline ...
6
#include <bits/stdc++.h> using namespace std; template <typename T> T lcm(T a, T b) { return a / __gcd(a, b) * b; } template <class T> inline T bigmod(T p, T e, T M) { T ret = 1; for (; e > 0; e >>= 1) { if (e & 1) ret = (ret * p) % M; p = (p * p) % M; } return (T)ret; } template <class string> long l...
1
#include <bits/stdc++.h> using namespace std; long long int max(long long int a, long long int b) { if (a > b) return a; else return b; } long long int min(long long int a, long long int b) { if (a < b) return a; else return b; } const int dx[4] = {-1, 1, 0, 0}; const int dy[4] = {0, 0, -1, 1}; ...
5
#include <bits/stdc++.h> using namespace std; const int MOD = 1000000007; const long long UNDEF = -1; const long long INF = 1e18; template <typename T> inline bool chkmax(T &aa, T bb) { return aa < bb ? aa = bb, true : false; } template <typename T> inline bool chkmin(T &aa, T bb) { return aa > bb ? aa = bb, true :...
10
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; priority_queue<long long> pq; long long x, c = 0; for (int i = 0; i < n; i++) { cin >> x; pq.push(x); if (x < pq.top()) { c += (pq.top() - x); pq.pop(); pq.push(x); } } cout << c << endl; return...
7
#include <bits/stdc++.h> using namespace std; int main() { int n, m, *x, y; cin >> n >> m; x = new int[n]; for (int i = 0; i < n; i++) x[i] = 0; for (int i = 0; i < m; i++) { cin >> y; for (int j = y - 1; j < n; j++) { if (x[j] == 0) x[j] = y; } } for (int i = 0; i < n; i++) cout << x[i]...
0
#include <bits/stdc++.h> using namespace std; int n, t; double dp[2010][2010], p; int main() { scanf("%d%lf%d", &n, &p, &t); dp[0][0] = 1; for (int i = 0; i < t; i++) { dp[i + 1][n] += dp[i][n]; for (int j = 0; j < n; j++) { dp[i + 1][j] += dp[i][j] * (1 - p); dp[i + 1][j + 1] += dp[i][j] * p;...
4
#include <bits/stdc++.h> void run(std::istream &in, std::ostream &out) { int n; in >> n; std::vector<std::array<int, 3>> points(n); for (int i = 0; i < 3; i++) { for (int j = 0; j < n; j++) { in >> points[j][i]; } } std::sort(points.begin(), points.end(), [](std::array<int, 3> p1, ...
8
#include <bits/stdc++.h> long long mpow(long long a, long long n, long long mod) { long long ret = 1; long long b = a; while (n) { if (n & 1) ret = (ret * b) % mod; b = (b * b) % mod; n >>= 1; } return (long long)ret; } using namespace std; void solve() { int n, k; scanf("%d", &n); scanf("%d...
3
#include <bits/stdc++.h> using namespace std; string s, t, d; int m; void nhap() { cin >> s >> t; } void xuat() { int cols, rows, colg, rowg; switch (s[0]) { case 'a': cols = 0; break; case 'b': cols = 1; break; case 'c': cols = 2; break; case 'd': cols = 3;...
1
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); long long int t = -INT_FAST32_MAX; int n; cin >> n; for (int i = 0; i < n; i++) { long long int g; cin >> g; long long int f = sqrt(g) + 0.5; if (f * f != g) t = ((t < g) ? g : t); ...
0
#include <bits/stdc++.h> using namespace std; int s[100100]; long long p[50050]; int main() { for (int n, t; scanf("%d", &n) != EOF;) { memset(s, 0, sizeof(s)); for (int i = 0; i < n; i++) scanf("%d", &s[i]); sort(s, s + n); int cnt = 0; long long ans = 0; for (int i = n - 1; i > 0; i--) { ...
4
#include <bits/stdc++.h> using namespace std; const int maxn = 200005; int head[maxn], cnt = 1, n, q; struct Node { int v, nxt; } G[maxn << 1]; int dist[maxn]; int f[maxn][25], deep[maxn]; void insert(int u, int v) { G[cnt] = (Node){v, head[u]}; head[u] = cnt++; } void dfs(int x, int fa, int dep) { deep[x] = de...
5
#include <bits/stdc++.h> using namespace std; const int N = 1000; const int maxint = 2139062143; int x = 0, y = 0; int gcd(int a, int b) { if (b == 0) return a; return gcd(b, a % b); } string check(int a) { int i, j; for (i = 1; i <= N; i++) { for (j = i + 1; j <= N; j++) if (i * i + j * j == a * a) {...
4
#include <bits/stdc++.h> using namespace std; int main() { long long int n; cin >> n; long long int s = (n * (n + 1)) / 2; long long int ans = 0; vector<int> v; for (int i = n; i >= 1; i--) { ans += i; if (ans <= s / 2) { v.push_back(i); } else ans -= i; } cout << s % 2 << endl; ...
2
#include <bits/stdc++.h> using namespace std; const int N = 1010, M = 100100, INF = 1000010000; int n, m, S, T, u, v, c, f, fl = 1, mic; int hd[N], di[N], in[N], vi[N]; struct edge { int n, v, w, c; } e[M]; queue<int> q; void add_(int u, int v, int w, int c) { e[++fl] = (edge){hd[u], v, w, c}; hd[u] = fl; } void ...
10
#include <bits/stdc++.h> using namespace std; template <class T> void checkmin(T &t, T x) { if (x < t) t = x; } template <class T> void checkmax(T &t, T x) { if (x > t) t = x; } template <class T> void _checkmin(T &t, T x) { if (t == -1) t = x; if (x < t) t = x; } template <class T> void _checkmax(T &t, T x) { ...
4
#include <bits/stdc++.h> using namespace std; const int N = 20200; const int mod = 1e9 + 7; int sz = 1; int PL, MN; string s; int n; vector<int> g[N]; int ans[N]; int mx[N][110], mn[N][110]; inline bool is(char x) { return x >= '0' && x <= '9'; } int pos; inline void E(int v, int par) { if (s[pos] == '(') { int n...
7
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; int ok = 1; for (int i = 1; i < s.length(); i++) { if (islower(s[i])) { ok = 0; } } if (ok == 0) cout << s << endl; else { for (int i = 0; i < s.length(); i++) { if (isupper(s[i])) s[i] = tol...
1
#include <bits/stdc++.h> using namespace std; bool hang[1005], lie[1005]; int main() { int i, n, m, x, y; scanf("%d%d", &n, &m); memset(hang, 0, sizeof(hang)); memset(lie, 0, sizeof(lie)); for (i = 0; i < m; ++i) { scanf("%d%d", &x, &y); hang[x] = 1; lie[y] = 1; } int ans = 0; for (i = 2; i ...
5
#include <bits/stdc++.h> using namespace std; const int mod = 1000000007; const int N = 1000000; string str; int main() { int n; scanf("%d", &n); cin >> str; int low = 1, mid, high = 2 * n, t, x, y, i, ans; while (low <= high) { mid = (low + high) >> 1; t = mid; i = 0, x = y = -1; int flagS = ...
5
#include <bits/stdc++.h> using namespace std; #pragma comment(linker, "/stack:200000000") #pragma GCC optimize("Ofast", "unroll-loops", "omit-frame-pointer", "inline") #pragma GCC option("arch=native", "tune=native", "no-zero-upper") #pragma GCC target( \ "sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native,avx...
9
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n, ans = 0; cin >> n; long long int arr[n]; for (int i = 0; i < n; i++) cin >> arr[i]; sort(arr, arr + n); int i = 0, j = 1; while (j != n) { if (arr[i] < arr[j]) ...
2
#include <bits/stdc++.h> using namespace std; const long long M = 1e9 + 7; long long pmp(long long x, long long n) { long long a = 1; while (n > 0) { if (n & 1) a = (a * x) % M; x = (x * x) % M; n = n >> 1; } return a; } void solve() { long long n; cin >> n; vector<long long> a(n); vector<lo...
6
#include <bits/stdc++.h> using namespace std; int a[1010][1010], n, m; int Lx[1010][1010], Rx[1010][1010]; int Ly[1010][1010], Ry[1010][1010]; pair<int, int> p[1010]; int main() { scanf("%d%d", &n, &m); for (int i = 1; i <= n; ++i) for (int j = 1; j <= m; ++j) scanf("%d", &a[i][j]); for (int i = 1; i <= n; ++...
4
#include <bits/stdc++.h> using namespace std; int a[1005][1005]; int main() { int t; cin >> t; while (t--) { int n, m; cin >> n >> m; int minn = 1e9 + 7; int s = 0; int s1 = 0; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { cin >> a[i][j]; if (a[i][j] < 0...
1
#include <bits/stdc++.h> int main() { int n, w = 1, ma; scanf("%d", &n); int a[n]; scanf("%d", &a[0]); ma = a[0]; for (int i = 1; i < n; i++) { scanf("%d", &a[i]); ma = ((ma) > (a[i]) ? (ma) : (a[i])); if (a[i] == a[i - 1]) return !printf("NO\n"); if (((a[i] - a[i - 1]) < 0 ? -(a[i] - a[i - ...
4
#include <bits/stdc++.h> using namespace std; struct qry { int l, r, id, val; int block; }; int b_search(int X) { int S = 0, E = X; long long mid; while (S < E) { mid = (S + E) >> 1; if (mid * mid >= X) E = mid; else S = mid + 1; } return E; } class MoAlgo { int n, q; vector<in...
8
#include <bits/stdc++.h> using namespace std; const int N = 1e4 + 4; const int LN = 30; int n; int a[N]; int b[N]; bool done[N]; vector<pair<int, int> > va; vector<pair<int, int> > vb; int solve(int arr[], vector<pair<int, int> > &res) { for (int i = 1; i <= n; ++i) { done[i] = 0; } for (int i = LN - 1; i >= ...
9
#include <bits/stdc++.h> using namespace ::std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); string str; cin >> str; string::iterator ptr = str.begin(); int ucount = 0, lcount = 0; for (; ptr < str.end(); ptr++) { if (isupper(*ptr)) ucount++; else if (islower(*ptr)) lc...
0
#include <bits/stdc++.h> const int N = 222222; int tot; char op[N]; int num[N]; int x[N], y[N]; std::set<std::pair<int, int> > st[N]; int main() { int n; char s[20]; while (gets(s) != NULL) { int t = 0; sscanf(s, "%d", &n); for (register int i = 0; i < n; i++) { gets(s); op[i] = s[0]; ...
10
#include <bits/stdc++.h> using namespace std; int l[100010], r[100010], n, t; struct edge { int l, r; } e[100010]; bool cmp(edge a, edge b) { if (a.l != b.l) return a.l < b.l; return a.r < b.r; } int main() { scanf("%d", &t); while (t--) { scanf("%d", &n); for (int i = 1; i <= n; i++) { scanf("%...
3
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n; cin >> n; if (n <= 3) { cout << "-1" << endl; } else if (n % 2 != 0) { for (int i = n; i >= 1; i -= 2) { cout << i << " "; } cout << 4 << " " << 2 << " "; for (int...
4
#include <bits/stdc++.h> using namespace std; const int N = 300005; int n, q; int a[N]; int b[N], len = 0; bool read[N]; int cur = 0; vector<int> ids[N]; int last = 1; int main() { cin >> n >> q; for (int i = 1; i <= q; ++i) { int tp, x; cin >> tp >> x; if (tp == 1) { ++cur; b[++len] = x; ...
4
#include <bits/stdc++.h> using namespace std; int n, k, a[111111], b[111111], kk; bool w[111111]; long long m, s, cur; bool cmp(int x, int y) { return a[x] > a[y]; } int main() { scanf("%d %d %I64d", &n, &k, &m); for (int i = 0; i < n; ++i) { scanf("%d", a + i); b[i] = i; } sort(b, b + n - 1, cmp); me...
4
#include <bits/stdc++.h> using namespace std; int n, m, r, c, b, cr, s; void run() { long long cnt = 0; cout << cr << ' ' << b << endl; int i = b; while (cnt < (m - 1)) { i += s; cout << cr << ' ' << i << endl; cnt++; } b = i; cr++; } int main() { cin >> n >> m >> r >> c; int i = 0; cout...
1
#include <bits/stdc++.h> using namespace std; const int DX[] = {-1, -1, 1, 1}; const int DY[] = {-1, 1, -1, 1}; set<pair<int, int> > S; vector<int> P[1 << 18]; vector<int> M[1 << 18]; vector<pair<int, int> > RP[1 << 18]; vector<pair<int, int> > RM[1 << 18]; int n, m; int Get(int x, int y) { if (x < 0 || x >= n || y <...
11
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; string s; cin >> s; if (n == 1) { cout << 1 << endl; return 0; } int first = 0; int second = 1; int count = 0; string temp; while (first < n && second < n) { if (s[first] != s[second]) { temp += s[first];...
2
#include <bits/stdc++.h> using namespace std; const long long mod = 998244353; long double PI = acosl(-1); const long long inf = 1e15; const int nmax = 5e5 + 10; string str[7]; string s; string mara = "264513"; bool pawagese; char c[32][32]; char c1[32][32]; int w, h; void hishab() { memset(c, 0, sizeof c); string ...
6
#include <bits/stdc++.h> using namespace std; int n, G[2010][2010], x, y, mc, md, used[2010]; long long d[2010]; int main() { mc = 2e9; scanf("%d", &n); for (int i = 1; i < n; i++) for (int j = i + 1; j <= n; j++) scanf("%d", &x), G[i][j] = G[j][i] = x, mc = min(mc, x); memset(d, 62, sizeof d); for ...
9
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); int n, m, i, j, k, x, y, xx, yy, xstart, ystart; cin >> n >> m >> k; vector<string> s(n + 2); for (i = 1; i <= n; i++) { cin >> s[i]; s[i] = '*' + s[i] + '*'; for (j = 1; j <= m; j++) { if (...
4
#include <bits/stdc++.h> using namespace std; map<pair<int, int>, int> mp; vector<int> v[505]; int n, m, x, y, memo[505], memo2[505], ci[505]; long long may, cont; bool b1 = false; pair<int, int> esc; void dfs(int nodo, int pos) { if (b1 == true) return; for (int i = 0; i < v[nodo].size() and b1 == false; i++) { ...
7
#include <bits/stdc++.h> using namespace std; const long long M = 1e9 + 7; long long expo(long long a, long long b) { if (b == 0) return 1; if (b % 2 == 0) { long long ret = expo(a, b / 2); ret = (ret * ret) % 998244353; return ret; } else { long long ret = expo(a, b / 2); ret = (ret * ret) % ...
5
#include <bits/stdc++.h> #pragma GCC optimize(0) using namespace std; const int INF = 1 << 30; const int MAXBUF = 1 << 12; char buf[MAXBUF], *ps = buf, *pe = buf + 1; inline void rnext() { if (++ps == pe) pe = (ps = buf) + fread(buf, sizeof(char), sizeof(buf) / sizeof(char), stdin); } template <class T> ...
8
#include <bits/stdc++.h> using namespace std; const int AKA = 5e5 + 5; int frq[AKA]; long long arr[2005]; pair<long, pair<long, long> > p[2005]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long n, m, sum = 0, cnt = 0; cin >> n >> m; for (int i = 0; i < n; i++) { cin >> p[i].second.f...
1
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { string binary, answer; cin >> binary; int k = 1; int maxLen = binary.size() * 2; for (int i = 0; i < binary.size() - k; i += k) { if (binary[i] == binary[i + k]) { continue; } if...
1
#include <bits/stdc++.h> using namespace std; template <typename A, typename B> string to_string(pair<A, B> p); template <typename A, typename B, typename C> string to_string(tuple<A, B, C> p); template <typename A, typename B, typename C, typename D> string to_string(tuple<A, B, C, D> p); string to_string(const string...
7
#include <bits/stdc++.h> using namespace std; void candy(int x, int y) { int d = 1; bool flag = true; while (x >= 0 && y >= 0) { if (flag) { x = x - d; d++; flag = false; } else { y = y - d; d++; flag = true; } if (flag == true && x < d) { cout << "Vladik"...
0
#include <bits/stdc++.h> const int mod = 1e9 + 7; int f[705][705][10][2]; char s[1005]; int main() { scanf("%s", s + 1); int n = strlen(s + 1); for (int i = 1; i <= n; ++i) s[i] -= 48; for (int i = 0; i <= 9; ++i) f[0][0][i][0] = 1; for (int i = 1; i <= n; ++i) for (int j = 0; j < i; ++j) for (int k...
10
#include <bits/stdc++.h> using namespace std; int main() { int t, *a, i, n, d; cin >> t; while (t--) { cin >> n >> d; a = new int[n]; for (i = 0; i < n; i++) cin >> a[i]; for (i = 1; i < n && d > 0; i++) { if (a[i] * i <= d) { a[0] += a[i]; d -= i * a[i]; } else { ...
0
#include <bits/stdc++.h> using namespace std; long long typedef ll; int main() { int n, k; cin >> n >> k; ll a[n]; for (int i = 0; i < n; i++) cin >> a[i]; if (k >= n) { cout << a[n - 1]; return 0; } ll ans = 0; for (int i = 0; i < n - k; i++) { if (a[i] + a[2 * (n - k) - i - 1] > ans) ...
3
#include <bits/stdc++.h> using namespace std; const int maxn = 1e6 + 10; int n, ans, top; char c[maxn]; stack<int> s; int main() { scanf("%d%s", &n, c + 1); int len = strlen(c + 1), cnt1 = 0, cnt2 = 0; for (int i = 1; i <= len; ++i) { if (c[i] == '(') cnt1++; else cnt2++; } if (cnt1 != cnt...
2
#include <bits/stdc++.h> const long long MAX_N = 3 * 1e5 + 100; const int MOD = 1e9 + 7; const long long delta = 10333; const long long N = 1e5 + 100; using namespace std; long long dp[100][100]; long long a[100]; void clr() { for (int i = 0; i < 100; ++i) for (int j = 0; j < 100; ++j) dp[i][j] = 0; } int main() ...
5
#include <bits/stdc++.h> using namespace std; struct Node { int node, capacity, opposite_index; bool LevelSetVisit; Node(int n, int c, int oi, bool lsv) { node = n; capacity = c; opposite_index = oi; LevelSetVisit = lsv; } }; vector<Node> Graph[105 + 0]; int Levels[105 + 0]; int openPaths[105 + ...
6
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; long long modinv(long long a) { long long res = 1; for (int n = mod - 2; n > 0; n >>= 1) { if (n & 1) res = (res * a) % mod; a = (a * a) % mod; } return res; } const int N = 1e5; vector<int> adj[N]; long long ways[N], ans[N]; v...
6
#include <bits/stdc++.h> using namespace std; long long n, i, sum, l; long double k; vector<long double> a, ans; int main() { cin >> n; for (i = 0; i < n; ++i) { cin >> k; a.push_back(k); l = floor(k); ans.push_back(l); sum = sum + l; } i = 0; while (sum != 0) { if (a[i] != floor(a[i])...
3
#include <bits/stdc++.h> const long long inf = (long long)1e18 + 1; const long long SIZE = (long long)1e5 + 3; const long long MOD = (long long)1e9 + 7; using namespace std; bool compare(const pair<long long, long long> &a, const pair<long long, long long> &b) { return (a.second < b.second); } long long ...
3
#include <bits/stdc++.h> using namespace std; int n, m, i, j, k, x, y, z, c, o; int ans = 2000000000, now, tar; int mi[5], cur; int dx[5] = {0, 1, 1, -1, -1}; int dy[5] = {0, 1, -1, 1, -1}; int p, q; int main() { scanf("%d%d", &n, &m); scanf("%d", &c); for (i = 1; i <= 4; i++) mi[i] = ans; for (o = 1; o <= c; o...
6
#include <bits/stdc++.h> using namespace std; inline int max(int a, int b) { return a > b ? a : b; } string cat[5] = {"noob", "random", "average", "hardcore", "pro"}; struct Player { string name; int score; int cas; }; Player p[1003]; int m; void update(string name, int score) { for (int i = 0; i < m; i++) { ...
3
#include <bits/stdc++.h> using namespace std; void relax(int*** dp, string* rel, int target, int i, int j, int** nextOcc) { string r = rel[target]; if (target == 0) { int best = nextOcc[r[r.length() - 1] - 'a'][dp[r.length() - 1][i][j]] + 1; if (i > 0 && rel[1].size() >= i) best = min(best, ...
7
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 10; long long a[maxn]; int main() { int n; cin >> n; for (int i = 0; i < n; ++i) { cin >> a[i]; } long long sum = 0; long long now = 0; for (int i = 0; i < n; ++i) { sum += abs(a[i] - now); now += a[i] - now; } cout << su...
1
#include <bits/stdc++.h> using namespace std; int main() { int q; cin >> q; string x, y; int a, b; while (q--) { cin >> x >> y; reverse((x).begin(), (x).end()); reverse((y).begin(), (y).end()); for (int i = 0; i < y.size(); i++) { if (y[i] == '1') { a = i; break; } ...
1
#include <bits/stdc++.h> using namespace std; const int MAX = 2 * 1e5; int main() { char str[MAX]; scanf("%s", str); int lenth = strlen(str); for (int i = 1; i < lenth; ++i) { if (str[i] == str[i - 1]) { str[i] = 'a'; while (str[i] == str[i - 1] || str[i] == str[i + 1]) { str[i]++; ...
2
#include <bits/stdc++.h> using namespace std; int l[200005], a[200005], mn[200005], n, ans[200005], mnmn = 1e9 + 10; int main() { cin >> n; for (int i = 1; i <= n; i++) { scanf("%d", &a[i]); mnmn = min(mnmn, a[i]); } stack<pair<int, int> > st; st.push(make_pair(n, a[n])); for (int i = n - 1; i >= 1;...
5
#include <bits/stdc++.h> using namespace std; bool visit[1001]; int ans[2002]; int n, k; int to; int i; vector<int> vec; void bfs() { for (i = 0; i < 2002; i++) ans[i] = -1; queue<int> q; q.push(0); ans[0] = 0; while (!q.empty()) { int v = q.front(); q.pop(); for (i = 0; i < vec.size(); i++) { ...
7
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:16777216") using namespace std; int n, m; long long c[1024][1024]; long long _uu[1024]; long long _u[1024]; long long _vv[1024]; long long _v[1024]; long long uu(int i) { if (_uu[i] == -1) { long long sum = 0; for (int j = 1; j <= (int)(m); ++j) { ...
5
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 5; int n; int p[N]; pair<int, int> v[N]; void solve(int nx, int nnx) { int curr = 1; for (int i = 1; i <= n; i++) p[i] = 0; p[curr] = nx; p[nx] = nnx; curr = nx; bool okay = true; for (int i = 2; i <= n; i++) { if (v[curr].first == nnx)...
4
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int a[n]; string s = ""; for (int i = 0; i < n; i++) { cin >> a[i]; } int l = 0, r = n - 1; int last; int flag = 0; while (l <= r) { if (flag == 0) { if (a[l] <= a[r]) { s += 'L'; last = a[l]; ...
2
////#include <iostream> ////#include <cstdio> ////#include <cstring> ////#include <algorithm> //// ////#define LL long long //// ////LL gcd(LL a,LL b) { //// if(b == 0) return a; //// else return gcd(b,a % b); ////} //// ////inline LL calc(LL x) { //// LL ret = 0; //// while(x) { //// ret += x % 10; ...
4
#include <bits/stdc++.h> using namespace std; int main() { stack<int> sta; vector<int> v; int n, ans; while (scanf("%d", &n) != EOF) { v.resize(n); for (int i = 0; i < n; ++i) scanf("%d", &v[i]); while (!sta.empty()) sta.pop(); ans = 0; for (int i = 0; i < n; ++i) { while (!sta.empty()...
5
#include <bits/stdc++.h> using namespace std; using Int = long long; int main() { ios_base::sync_with_stdio(0); cin.tie(nullptr); string s; cin >> s; int z = 0; for (char c : s) { if (c != 'a') { z++; } } z /= 2; int t = 0; int n = (int)s.length(); string a = "", b = ""; for (int i...
1
#include <bits/stdc++.h> using namespace std; int N = 5e5 + 50; int a[] = {4, 8, 15, 16, 23, 42}; queue<int> que[50]; int main() { int n, val; scanf("%d", &n); for (int i = 0; i < n; i++) { scanf("%d", &val); que[val].push(i); } int res = 0; while (1) { bool flag = true; int pre = -1; fo...
2
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:1024000000,1024000000") using namespace std; const int MOD = 1e9 + 7, maxn = 1e5 + 5; int n, m, cnt, u[maxn], top, r; long long pow2[105], b[70], d[maxn], a[maxn << 2]; bool v[maxn]; struct Arc { int to; long long w; Arc(int to, long long w) : to(to), w(w) ...
9
#include <bits/stdc++.h> using namespace std; const int INF = 0x7fffffff; inline int reint() { int d; scanf("%d", &d); return d; } inline long relong() { long l; scanf("%ld", &l); return l; } inline char rechar() { scanf(" "); return getchar(); } inline double redouble() { double d; scanf("%lf", &d)...
7
#include <bits/stdc++.h> using namespace std; int main() { int x1, y1, x2, y2; cin >> x1 >> y1 >> x2 >> y2; x1 = (x1 > x2) ? (x1 - x2) : (x2 - x1); y1 = (y1 > y2) ? (y1 - y2) : (y2 - y1); int res = (x1 > y1) ? x1 : y1; cout << res; return 0; }
0
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int sum = 0; for (int i = 1; i <= n; i++) { int a; cin >> a; sum += a; } if (sum % n == 0) { cout << n << endl; } else { cout << n - 1 << endl; } return 0; }
2
#include <bits/stdc++.h> using namespace std; template <typename X> ostream& operator<<(ostream& x, const vector<X>& v) { for (long long i = 0; i < v.size(); ++i) x << v[i] << " "; return x; } template <typename X> ostream& operator<<(ostream& x, const set<X>& v) { for (auto it : v) x << it << " "; return x; } ...
7
//hussam11 #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<int> vi; typedef vector<ll> vll; typedef vector<pair<int, int>> vii; typedef set<int> si; #define pb push_back #define X first #define Y second #define FOR(i, a, b) for(int i = a; i <= b; i++) #define gcd(x, y) __gcd(x, y) #...
0
#include <bits/stdc++.h> using namespace std; char s[100005]; struct node { int x, op; } a[100005]; bool cmp(node q, node w) { return q.x < w.x; } int cnt; bool vis[100005]; int main() { int now, len, i; scanf("%d", &now); scanf("%s", s + 1); len = strlen(s + 1); s[0] = '+'; for (i = 1; i <= len; i++) { ...
6
#include <bits/stdc++.h> using namespace std; long long a, b, c; int main() { cin >> a >> b >> c; int cnt = 0; a *= 10; while (cnt <= 1000000) { long long d = a / b; long long rem = d * b; rem = a - rem; rem *= 10LL; a = rem; if (d == c) break; cnt++; } if (cnt == 1000001) { ...
2
#include <bits/stdc++.h> using namespace std; int t; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> t; while (t--) { int a, b, c, r, d; cin >> a >> b >> c >> r; if (a > b) { swap(a, b); } d = c + r; c = c - r; if (c > b || d < a) { cout << max(0, abs(b - a)...
0
#include <bits/stdc++.h> using namespace std; const int maxn = 309; const int mod = 1e9 + 7; int f[maxn][maxn], C[maxn][maxn], b[maxn], a[maxn], fac[maxn]; int n; inline void update(int &x, int y) { x += y; if (x >= mod) x -= mod; } inline int read() { int x = 0, f = 1; char ch = getchar(); while (ch < '0' ||...
8
#include <bits/stdc++.h> const int N = 500005; int n, m, maxn; int a[N]; int cnt[N], ans[N]; bool vis[N]; std::stack<int> s; struct query { int l, r, id; bool operator<(const query& x) const { if (l / maxn != x.l / maxn) return l < x.l; return (l / maxn) & 1 ? r < x.r : r > x.r; } } q[N]; void add(int x) ...
8
#include <bits/stdc++.h> using namespace std; using ll = long long; const int N = 100010, LN = 17; const int M = 4 * N * LN; int t[M], L[M], R[M]; int nodes; int build(int l, int r) { int i = nodes++; if (l == r) { t[i] = 0; } else { int m = (l + r) / 2; L[i] = build(l, m); R[i] = build(m + 1, r);...
8
#include <bits/stdc++.h> using ll = long long; using ld = long double; using ull = unsigned long long; using namespace std; const int N = 2002, NN = 502, mod = 1e9 + 7, mod1 = 1e9 + 9, Base = 317, Base1 = 371; int n, K, pw[NN], pw1[NN], lcp[N], mn[N][11], id[N]; string s[N]; struct Hash { vector<pair<int, i...
7
#include <bits/stdc++.h> using namespace std; int dx[] = {0, 1, 0, -1, 1, 1, -1, -1}; int dy[] = {1, 0, -1, 0, 1, -1, 1, -1}; void fast() { std::ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); } long long arr[(int)1002]; int main() { fast(); int n; long long w; cin >> n >> w; for ...
3
#include <bits/stdc++.h> using namespace std; int pre[1000001]; void Prefix(int n, string str) { int i, j; pre[0] = 0; i = 1; j = 0; while (i < n) { if (str[i] == str[j]) { pre[i] = j + 1; i++; j++; } else { if (j == 0) { pre[i] = 0; i++; } else { ...
4
#include <bits/stdc++.h> using namespace std; int main() { int i, j, k, l; int x, y, z; bool flag = 0; int n; cin >> n; vector<long long> a(n); vector<long long> b(n); for (i = 0; i < n; i++) { cin >> a[i]; b[i] = a[i]; } int m; cin >> m; sort(b.begin(), b.end()); reverse(b.begin(), b....
4
#include <bits/stdc++.h> int main() { int la, lb, i, j, f, count, A[26] = {0}, B[26] = {0}; char a[100005], b[100005]; scanf("%s%s", a, b); la = strlen(a); lb = strlen(b); if (lb > la) { printf("0\n"); return 0; } for (i = 0; i < lb; i++) { B[b[i] - 'a']++; if (a[i] != '?') A[a[i] - 'a']...
3
#include <bits/stdc++.h> using namespace std; int a[101][101]; int main() { int n, x1, y1, x2, y2, sum = 0; memset(a, 0, sizeof(a)); cin >> n; for (int i = 0; i < n; i++) { cin >> x1 >> y1 >> x2 >> y2; for (int j = x1; j <= x2; j++) { for (int d = y1; d <= y2; d++) { a[j][d]++; sum...
1