solution
stringlengths
53
181k
difficulty
int64
0
27
#include <bits/stdc++.h> const long long mod = 1e9 + 7; using namespace std; const long long N = 1e5 + 5; long long n; long long a[N]; void fuck() { cin >> n; long long times = 0; for (long long i = 4 * n; i >= 0; i -= 2) { cout << i << ' '; times++; if (times == n) { break; } } cout << ...
0
#include <bits/stdc++.h> using namespace std; int main() { long long a, b; cin >> a >> b; vector<long long> v; while (b != a) { v.push_back(b); if (b % 2 == 0) b /= 2; else if (b % 10 == 1) b /= 10; else { cout << "NO"; return 0; } if (b < a) { cout << "NO";...
2
#include <bits/stdc++.h> using namespace std; vector<int> v[1010]; int arr[1010]; int n, ans; void dfs(int pos) { arr[pos]++; if (arr[pos] == 2) { ans = pos; cout << ans << " "; return; } dfs(v[pos][0]); } int main() { ios_base::sync_with_stdio(); cin.tie(0); cin >> n; for (int i = 1; i <= n...
2
#include <bits/stdc++.h> using namespace std; const long double pi = acos(-1); const long double eps = 1e-9; struct Point { int x, y, id, deg; Point(int _x = 0, int _y = 0, int _id = 0, int _deg = 0) : x(_x), y(_y), id(_id), deg(_deg) {} inline bool operator<(const Point &rhs) const { return deg < rhs.deg; ...
22
#include <bits/stdc++.h> using namespace std; int main() { string a, b; int i, j, k; cin >> a >> b; if (a == "0" && b == "0") { cout << "OK\n"; return 0; } sort(a.begin(), a.end()); vector<string> v; do { if (a[0] != '0') v.push_back(a); } while (next_permutation(a.begin(), a.end())); so...
3
#include <bits/stdc++.h> using namespace std; const int maxn = 3e5 + 10; vector<int> g[maxn]; int f[maxn], d[maxn], L[maxn], R[maxn], fix[maxn], gt[maxn], ans = 0; int n, k; char str[maxn]; int calc(int x) { if (fix[x]) return gt[x] ? R[x] : L[x]; else return min(L[x], R[x]); } int find(int x) { if (f[x] ...
16
#include <bits/stdc++.h> using namespace std; int n, ans = 1e9; int gcd(int a, int b) { int t; int kol = 0; if (a > b) { t = a; a = b; b = t; } while (a > 1 || b > 1) { if (b == 0) return 1000 * 1000 * 1000; kol += (a / b); a -= (a / b) * b; t = a; a = b; b = t; } retur...
11
#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 int read() { char s; int k = 0, base = 1; while ((s = getchar()) != '-' && s != EOF && !(isdigit(s))) ; if (s == EOF) exit(0); if (s == '-') base = -1, s =...
16
#include <bits/stdc++.h> int main() { long long int t, i, s, a, b, c, p, q; scanf("%lli", &t); for (i = 1; i <= t; i++) { scanf("%lli %lli %lli %lli", &s, &a, &b, &c); p = s / c; q = (p / a) * b; printf("%lli\n", p + q); } return 0; }
0
#include <bits/stdc++.h> using namespace std; const long long maxN = 1e18; const long long minN = -1e18; const int INF = 2e9; const long long MOD = 1e9 + 7; const long long MOD1 = 998244353; const int baseHash = 331; const int bigNumLength = 5000; const long double PI = acos(-1); const long long limit = 2e5 + 5; const ...
5
#include <bits/stdc++.h> using namespace std; const int maxN = 100 * 1000 + 5; const int mod = 1000 * 1000 * 1000; vector<int> v; int mp(int t) { int ps = lower_bound(v.begin(), v.end(), t) - v.begin(); return ps; } vector<pair<int, int> > c[16 * maxN]; pair<pair<int, int>, int> a[maxN]; pair<pair<int, int>, pair<i...
13
#include <bits/stdc++.h> using namespace std; const unsigned int M = 1000000007; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long int t; cin >> t; while (t--) { long long int n, x; cin >> n >> x; long long int a[n]; for (long long int i = 0; i < n; i++)...
4
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); string s, sAns; int n, p; cin >> n >> p; char temp; for (int i = 0; i < n; i++) { cin >> temp; s.push_back(temp); if (s[i] == '.') sAns.push_back('0'); else sAns.push_bac...
4
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n, k; cin >> n >> k; int arr[n]; for (int i = 0; i < n; i++) { cin >> arr[i]; } sort(arr, arr + n); int c = 0; for (int i = 1; i < n; i++) c += ((k - arr[i]) / arr[0]); cout << c...
0
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; template <class T> bool ckmin(T& a, const T& b) { return a > b ? a = b, 1 : 0; } template <class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; } mt19937 rng(chrono::steady_clock::now().time_since_epoch().cou...
16
#include <bits/stdc++.h> using namespace std; std::set<long long> S; std::map<long long, long long> mp; long long mx = 1e18 + 1; std::set<long long>::iterator it; void ini() { for (int k = 3; k <= 59; k++) { bool flag = true; for (long long i = 2;; i++) { long long pr = 1; for (long long j = 1; j ...
13
#include <bits/stdc++.h> const double PI = acos(-1); using namespace std; const int mod = 1e9 + 7; int main() { ios_base::sync_with_stdio(false); cout.tie(NULL); cin.tie(NULL); ; queue<long long> q; long long x = 0, a; string s; cin >> a >> s; for (int i = 0; i < ((int)((s).size())); i++) { if (s[...
0
#include <bits/stdc++.h> using namespace std; const int maxn = 3e3 + 5; int cnt, dp[maxn], head[maxn]; int fix; struct Edge { int s, t, next, dir; } e[maxn << 1]; void add(int s, int t, int dir) { e[++cnt].s = s; e[cnt].t = t; e[cnt].next = head[s]; e[cnt].dir = dir; head[s] = cnt; } void dfs(int u, int f, ...
13
#include <bits/stdc++.h> const int MAXN = 1e5 + 10; const int mod = 1e9 + 9; using namespace std; long long read() { long long x = 0, first = 1; char ch = getchar(); while (!isdigit(ch)) { if (ch == '-') first = -1; ch = getchar(); } while (isdigit(ch)) x = x * 10 + ch - '0', ch = getchar(); return ...
10
#include <bits/stdc++.h> using namespace std; const int N = 5e5 + 5, oo = 0x3f3f3f3f; const long long M = 1e12 + 105; int dx[] = {1, 0, -1, 0}; int dy[] = {0, -1, 0, 1}; int main() { int n, m, x, q; scanf("%d %d %d ", &n, &m, &x); char second[n][m]; vector<pair<int, int>> shift; map<char, int> mp; set<char>...
7
#include <bits/stdc++.h> using namespace std; int arr[] = {4, 5, 6, 3, 2, 1}; int main() { char c; long long n, time = 0; cin >> n >> c; time += arr[c - 'a']; if (n == 1 || n == 3) { cout << time; return 0; } if (n % 4 == 0 || n % 4 == 3) { n -= 2; } time += ((n - 1) - (n / 4) * 2) * 6 + (...
4
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5; int k = 0, id[N], n, m, st; struct node { int l, r; }; node z[N << 3]; struct edge { int to, va; edge(int a, int b) { to = a, va = b; } }; vector<vector<edge> > v(N << 3); long long dis[N << 3]; struct ni { int id; long long va; ni(int a, ...
15
#include <bits/stdc++.h> using namespace std; string to_string(char c) { return string(1, c); } string to_string(const char* s) { return (string)s; } string to_string(string s) { return s; } string to_string(bool b) { return b ? "true" : "false"; } string to_string(vector<bool> v) { string res = "{"; for (int i = 0...
13
#include <bits/stdc++.h> using namespace std; const long long modn = 998244353; long long powmod(long long a, long long p) { long long ans = 1; while (p) { if (p % 2) { ans *= a; ans %= modn; } p /= 2; a *= a; a %= modn; } return ans; } int arr[1001000]; long long tr[400400 * 4][...
16
#include <bits/stdc++.h> using namespace std; inline long long getint() { char c = getchar(); long long ret = 0, f = 1; while (c < '0' || c > '9') { if (c == '-') f = -1; c = getchar(); } while (c >= '0' && c <= '9') ret = ret * 10 + c - '0', c = getchar(); return ret * f; } const int maxn = 2e5 + 1...
15
#include <bits/stdc++.h> using namespace std; const long long maxn = 2e5 + 10, inf = 0x3f3f3f3f, mod = 1000000007; void read() {} template <typename T, typename... T2> inline void read(T &x, T2 &...oth) { x = 0; long long ch = getchar(), f = 0; while (ch < '0' || ch > '9') { if (ch == '-') f = 1; ch = get...
14
#include <bits/stdc++.h> int main() { long long int n, i, j, count = 0, a, b = 0; scanf("%lld", &n); long long int ara[n]; long long int str[n]; for (i = 0; i < n; i++) { scanf("%lld", &ara[i]); } for (i = 0; i < n; i++) { if (ara[i] == 1) { str[count] = i; count++; } } for (j ...
2
#include <bits/stdc++.h> using namespace std; #define FOR(a,b) for (int a=0; a<b; a++) #define FUR(a,b) for (int a=1; a<=b; a++) #define ROF(a,b) for (int a=b; a-->0; ) #define RUF(a,b) for (int a=b; a>0; a--) #define FORR(a,b,c) for (int a=b; a<c; a++) #define all(v) begin(v),end(v) #define rall(v) rbegin(v),rend(v) ...
16
#include <bits/stdc++.h> using namespace std; const int maxn = 210000; struct SOLVER { int n; int lazy[maxn]; int val[maxn]; void solve() { scanf("%d", &n); int cmd, x, y; int sz = 1; double ans = 0; for (int i = 1; i <= n; i++) { scanf("%d", &cmd); if (cmd == 1) { scanf(...
8
#include <bits/stdc++.h> using namespace std; const char IO_MODE = 0; inline long long ReadInt() { long long x = 0, f = 1; char ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); } ...
12
#include <bits/stdc++.h> using namespace std; long long n, m, k, q; vector<long long> b; long long d[2][200010]; vector<long long> row[200010]; vector<vector<long long> > matrix; const long long inf = 1e18; int32_t main() { ios_base::sync_with_stdio(false); cin >> n >> m >> k >> q; long long mx_x = 0; for (long...
13
#include <bits/stdc++.h> using namespace std; static bool solveOneTest(); int main() { solveOneTest(); return 0; } static const int MAX_INITIAL_LENGTH = (int)1e5; static const int MAX_QUERIES = (int)1e5; static const int MAX_TOTAL_LEN_OF_REPLACEMENTS = (int)1e5; static const int MODULO = (int)1e9 + 7; struct Entry ...
13
#include <bits/stdc++.h> using namespace std; bool rows[11], cols[11]; int main() { int n, k; cin >> n >> k; for (int i = 0; i < n + 1; ++i) { if (!i) continue; if (k > 0) { cout << n-- << " "; i--; k--; } else cout << i << " "; } return 0; }
3
#include <bits/stdc++.h> using namespace std; long long mod = 1e9 + 7; long long Pi = acos(-1); long long cnt; double epsilon = 0.0000001f; bool mark[200]; string update(string str, long long len, long long a, long long b, long long c) { for (int i = 0; i < len; i++) { if (str[i] == 'S' && mark[i] =...
4
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; for (int i = 1; i <= n; i++) { for (int j = 1; j <= n; j++) { if (j % 2 == 1) cout << (i + (n * (j - 1))) << ' '; else cout << ((j * n) + 1 - i) << ' '; } cout << endl; } return 0; }
2
#include <bits/stdc++.h> using namespace std; const double eps = 1e-11; const int inf = (int)2e9; const int mod = (int)1e9 + 7; const int N = 123456; int n; int ans; int a[10]; void Back(int k, int l) { if (k == l) { long long cur = 0; for (int i = 0; i < l; i++) cur = cur * 10 + a[i]; if (cur <= n) ans++...
4
#include <bits/stdc++.h> using namespace std; class DebugStream { } LOG; template <typename T> DebugStream &operator<<(DebugStream &s, const T &) { return s; } const int maxN = 1e5 + 9, maxV = 1e6 + 9, MOD = 1e9 + 7, SQ = 335, lg = 20, bs = 29; int main() { ios::sync_with_stdio(false); cin.tie(0); cou...
3
#include <bits/stdc++.h> using namespace std; int const MAX_N = 5010; int const MAX_Q = 410100; int const MAX_CH = 410100; long long const LL_INF = 1000000000000000009LL; int main() { int x1, y1, x2, y2; cin >> x1 >> y1 >> x2 >> y2; int go_1 = x1 + y1; int go_2 = max(x2, y2); if (go_1 <= 1) { cout << "Pol...
9
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long t = 1, n, m, ans, prev; string s; cin >> t; while (t--) { cin >> s; ans = 0; priority_queue<int> pq; prev = 0; for (int i = 0; i < s.length(); i++) { i...
0
#include <bits/stdc++.h> using namespace std; const long double INF = 1e20; vector<pair<long double, long double> > vec; struct Line { long double m, c; Line(long double x, long double y) { m = x; c = y; } long double Get(long double x) { return m * x + c; } bool operator<(const Line &other) const { r...
23
#include <bits/stdc++.h> using namespace std; void setIO() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); } int64_t xyz = 1; const int64_t N = 1e5 + 1; int64_t n; int64_t a[N]; int64_t b[N]; int64_t ao[N]; int64_t bo[N]; int64_t ans[N]; void run() { cin >> n; for (int64_t i = 1; i <=...
9
#include <bits/stdc++.h> using namespace std; int main() { int n, t, stagemax, mx = 0, i; cin >> n; stack<int> st; for (i = 0; i < n; i++) { cin >> t; if (st.empty()) { st.push(t); stagemax = 0; } else { if (st.top() == t && t >= stagemax) { st.pop(); stagemax = t; ...
14
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; const int inv2 = 500000004; const int N = 3e5 + 7; int n, q, cnt, now; int p[N], id[N], to[N], sz[N << 3]; pair<int, int> lsh[N << 1]; long long pw[N], pwinv[N], sum[N << 3], f[N << 3], g[N << 3]; void insert(int p, int id, int add, int l, int r) { ...
20
#include <bits/stdc++.h> using namespace std; map<string, int> id; struct B { string name; int t; long long w, h, brd, spa; vector<int> pak; B(string _name = "", int _t = 0, long long _w = 0, long long _h = 0) : name(_name), t(_t), w(_w), h(_h) { brd = spa = 0; } void pack(string s) { pak.push_b...
15
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); int n, x, c, y, m; cin >> n; for (int i = 1; i < n; i++) { if (n % i == 0) { c = 0; y = 0; m = i; while (m) { x = m % 10; m = m / 10; if (x == 4 || x == ...
2
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); ; long long t; cin >> t; while (t--) { long long l, r; cin >> l >> r; if (2 * l <= r) { cout << l << " " << 2 * l << '\n'; } else { cout << -1 << " " << -1 << '\n'; } } ...
0
#include <bits/stdc++.h> int main() { int x, y, z; scanf("%d%d%d", &x, &y, &z); if (x > y) { if (y + z < x) printf("+\n"); else printf("?\n"); } if (x < y) { if (x + z < y) printf("-\n"); else printf("?\n"); } if (x == y) { if (z == 0) printf("0\n"); e...
0
#include <bits/stdc++.h> using namespace std; long long Inf = 1000000000000000000; int main() { int i, j, k, n, m, u, v, s, ele, child, cnt = 0; scanf("%d %d %d", &n, &m, &k); long long dis[n], child_dis, y, len; vector<pair<int, long long> > graph[n]; set<pair<long long, int> > dijkstra; set<pair<long long...
12
#include <iostream> #include <cstdlib> #include <cstdio> #include <cmath> #define ll long long using namespace std; inline int read() { int f = 1, x = 0; char ch; do{ ch = getchar(); if (ch == '-') f = -1; }while(ch < '0' || ch > '9'); do{ x = x * 10 + ch - '0'; ch = getchar(); }while(ch >= '0' && ch ...
26
#include <bits/stdc++.h> using namespace std; const int INF = 100009; int n, s[INF], v[INF]; int ans[INF][2], cnt; queue<int> ql; int main() { ios::sync_with_stdio(0); cin >> n; for (int i = 0; i < n; i++) { cin >> s[i] >> v[i]; if (s[i] == 1) ql.push(i); } while (!ql.empty()) { int k = ql.front()...
7
#include <bits/stdc++.h> using namespace std; #pragma GCC optimize("O3") #pragma comment(linker, "/STACK:32505856") template <class T> inline T sqr(T a) { return a * a; } template <class T> inline void gmin(T &a, T b) { if (a > b) a = b; } template <class T> inline void gmax(T &a, T b) { if (a < b) a = b; } inlin...
13
#include <bits/stdc++.h> const double eps = 1e-11; int dx[] = {-1, -1, 0, 1, 1, 1, 0, -1}; int dy[] = {0, 1, 1, 1, 0, -1, -1, -1}; using namespace std; const int maxn = 1000000000; int sx, sy, ex, ey; set<pair<int, int> > mySet; map<pair<int, int>, int> myMap; bool judge(int x, int y) { if (x >= 1 && x <= 1000000000 ...
10
#include <bits/stdc++.h> using namespace std; long long n, ans; int32_t main() { ios::sync_with_stdio(false), cin.tie(0), cout.tie(0); cin >> n; long long x1 = 0; for (long long x2 = 0; x2 <= 8; x2++) { ans += max(0ll, n - x1 - x2 + 1); } for (long long x1 = 1; x1 <= 8; x1++) { for (long long x2 = 0...
12
#include <bits/stdc++.h> using namespace std; const long long N = 1e7 + 2; long long dp[2][N] = {}; signed main() { long long n; cin >> n; dp[1][0] = 1; for (long long steps = 1; steps <= n; steps++) { dp[1][steps] = (3LL * dp[0][steps - 1]) % 1000000007; dp[0][steps] = (2LL * dp[0][steps - 1] + dp[1][s...
7
#include <bits/stdc++.h> using namespace std; struct Edge { int to, next; } edges[404040]; int te = 1; int first[202020]; int du[202020]; void addE(int a, int b) { te++; edges[te].to = b; edges[te].next = first[a]; first[a] = te; te++; edges[te].to = a; edges[te].next = first[b]; first[b] = te; du[a...
22
#include <bits/stdc++.h> using namespace std; const int MN = 1e6 + 5, mod = 1e9 + 7; int N, dp[MN], nxt[MN], sum[MN]; char s[MN]; inline int get_val(int x) { return nxt[x] < N ? dp[nxt[x]] : 0; } int main() { scanf("%s", s); N = strlen(s); for (int i = 0; i < N; ++i) if (s[i] == '0') sum[i] = (i ? sum[i - 1] ...
20
#include <bits/stdc++.h> #pragma GCC optimize("O3") const long long MOD = 1e9 + 7; using namespace std; long long n_bits(long long n) { long long x = __builtin_popcount(n); return x; } template <typename... T> void read(T &...args) { ((cin >> args), ...); } template <typename... T> void write(T &&...args) { ((c...
2
#include <bits/stdc++.h> using namespace std; vector<int> primes; using ll = long long int; using dl = double; ll aarray[100000 + 10]; char magic[1][100000]; ll ar[200000 + 10]; const int N = 2e5 + 10; int a[N]; int main() { ios_base::sync_with_stdio(false); string ptr, str; ll m1, m2, m3, m4, i, j, x, y, n, k, m...
2
#include <bits/stdc++.h> using namespace std; const int N = 410, M = N * N; int n, m, l, p[N], mx[2], num[N], numb[N]; char c[N], st[N], res[N]; int e[N][N], now[N], tmp[N]; void Pre_work() { for (int k = 1; k <= n + n; ++k) for (int i = 1; i <= n + n; ++i) for (int j = 1; j <= n + n; ++j) e[i][j] |= (e[i][...
18
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; cin >> n; if (n % 3 == 0) cout << (n / 3) * 2; else cout << ((n / 3) * 2) + 1; }
0
#include <bits/stdc++.h> using namespace std; void read(int &x) { char ch = getchar(); x = 0; while (ch < '0' || ch > '9') ch = getchar(); while (ch >= '0' && ch <= '9') x = (x << 1) + (x << 3) + ch - 48, ch = getchar(); } struct EDGE { int next, to; } edge[200000 + 1]; int head[200000 + 1], fa[200000 + 1...
17
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> t(n + 1); for (int i = 0; i < n; i++) { int note; cin >> note; t[note]++; } int ans = 1; for (int i = 0; i <= n; i++) { ans += max(0, t[i] - 1); } cout << ans << endl; }
5
#include <bits/stdc++.h> using namespace std; long long int findmax(long long int a, long long int b) { if (a > b) return a; return b; } class Graph { map<long long int, vector<long long int>> adjList; public: Graph() {} void addEdge(long long int source, long long int destination, bool bidr ...
10
#include <bits/stdc++.h> using namespace std; const int N = 2002; const int M = 202; char a[N][M], b[M][N]; long long ha[N], hb[N][M]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n, m; cin >> n >> m; for (int i = 0; i < n; ++i) for (int j = 0; j < m; ++j) cin >> a[i][j]; for (int i...
12
#include <bits/stdc++.h> using namespace std; int n, mem[8010], dig[8080]; const long long mod1 = 1e9 + 7, mod2 = 1e9 + 9; long long hsh1[8010], hsh2[8010], pwr1[8080], pwr2[8080]; bool l[8080]; int dp(int x) { memset(l, 0, sizeof l); int tmp, res = 1e9, j; long long hsh11, hsh12, hsh21, hsh22; for (int i = x; ...
16
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5; int x[N]; int solve() { int n, r; scanf("%d %d", &n, &r); for (int i = 0; i < n; ++i) scanf("%d", x + i); sort(x, x + n); reverse(x, x + n); int ans = 1; for (int i = 1; i < n; ++i) { if (x[i] != x[i - 1]) { if (x[i] - ans * 1L...
5
#include <bits/stdc++.h> using namespace std; string a; int n; bool mark[3001]; int main() { memset(mark, 0, sizeof(mark)); cin >> n; cin >> a; int contr, contl; contr = contl = 0; int s = 0; for (int i = 0; i < a.size(); ++i) { bool t = false; if (a[i] == 'L') { contl++; int cant = 0;...
3
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); unsigned long long n, k, x, c = 0; cin >> n >> k; for (int i = 0; i < n; i++) { cin >> x; unsigned long long a[10] = {0}; while (x) { a[x % 10] = 1; x /= 10; } fo...
3
// Problem: B. Strange Definition // Contest: Codeforces - Codeforces Round #694 (Div. 1) // URL: https://codeforces.com/problemset/problem/1470/B // Memory Limit: 256 MB // Time Limit: 2000 ms // // Powered by CP Editor (https://cpeditor.org) #include<bits/stdc++.h> using namespace std; #define fast ios_base::sync_w...
11
#include <bits/stdc++.h> using namespace std; using ll = long long; using ull = unsigned long long; using str = string; using srt = short; const int INF = (int)1e9 + 7; const int MOD = 998244353; const ll inf = (ll)2e18; const ll mod = (int)1e9 + 7; const int N = 1000 + 5; int main() { ios::sync_with_stdio(0); cin....
11
#include <bits/stdc++.h> using namespace std; template <typename num_t> inline void addmod(num_t& a, const long long& b, const int& m) { a = (a + b) % m; if (a < 0) a += m; } template <typename num_t> inline void update_max(num_t& a, const num_t& b) { a = max(a, b); } template <typename num_t> inline void update_...
16
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 123; const int inf = 1e9 + 123; const long long INF = 1e18 + 123; const long long MAXN = 1e10 + 123; const long long MOD = 1e9 + 7; const long long mod = 555557; const double pi = acos(-1.0); vector<int> ans; long long a, b; int main() { ios_base::sync...
2
#include <bits/stdc++.h> using namespace std; char str[100005]; int a[200]; char maxx = 'a' - 1; int main() { int i, j, k; scanf("%s", str); for (i = 0; str[i]; i++) { if (a[maxx] == 0) { maxx = 'a' - 1; for (j = i; str[j]; j++) if (str[j] > maxx) { maxx = str[j]; } ...
3
#include <bits/stdc++.h> using namespace std; int N, a, b; int main(void) { cin >> N >> a >> b; int fir = N / a; for (int i = 0; i <= fir; ++i) { int sec = N - (a * i); if (sec % b == 0) { cout << "YES\n"; cout << i << ' ' << sec / b; return 0; } } cout << "NO"; return 0; }
3
#include <bits/stdc++.h> using namespace std; string line; unsigned char reverse(unsigned char a) { unsigned char res = 0; for (int i = 0; i < 8; i++) { if ((1 << i) & a) res |= (1 << (7 - i)); } return res; } int main() { getline(cin, line); unsigned char num = 0, step2 = 0; num -= reverse(line[0]); ...
5
#include <bits/stdc++.h> using namespace std; const long long N = 250005; long long n; vector<pair<int, int> > e[N]; vector<long long> vec[N]; long long du[N]; bool cmp(pair<int, int> x, pair<int, int> y) { return du[x.first] < du[y.first]; } long long nxt[N]; struct qq { priority_queue<long long> A, B; void push...
26
#include <bits/stdc++.h> using namespace std; struct node { int ai, bi; } c[1010]; int cmp(const node &a, const node &b) { if (a.bi > b.bi) return 1; else if (a.bi == b.bi) { if (a.ai > b.ai) return 1; else return 0; } else return 0; } int main() { int num, ai, bi; while (~scanf(...
3
#include <bits/stdc++.h> char s[123456]; char a[123]; char b[123]; void reverse(char *s) { char r, *t; for (t = s + strlen(s) - 1; s < t; s++, t--) { r = *s, *s = *t, *t = r; } } int find(char *s, char *a, char *b) { return (s = strstr(s, a)) != NULL && strstr(s + strlen(a), b) != NULL; } int main() { sca...
4
#include <bits/stdc++.h> using namespace std; long long n, x, y, P, sum, ans; int a[1001000]; struct matrix { long long r, c, num[5][5]; matrix() { r = 0, c = 0; memset(num, 0, sizeof(num)); } }; matrix cheng(matrix a, matrix b) { matrix c; c.r = a.r, c.c = b.c; for (int i = 1; i <= a.r; i++) fo...
18
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5; const int LOGN = 20; const int INF = 1e9 + 7; int n, m, a, b, currSize, parent[N], subTree[N], level[N], ans[N], dp[LOGN][N]; set<int> graph[N]; void dfs0(int u) { for (auto it : graph[u]) { if (it != dp[0][u]) { dp[0][it] = u; level...
16
#include <bits/stdc++.h> using std::cerr; using std::cin; using std::cout; using std::pair; using std::string; using std::vector; using ll = long long; const int INF = 1e9 + 1; int main() { std::ios_base::sync_with_stdio(false); cin.tie(0), cout.tie(0); int n, k; cin >> n >> k; std::set<vector<int>> s; vect...
7
#include <bits/stdc++.h> using namespace std; int n; char know[20][20]; int lft[1 << 7][20]; int rgt[1 << 7][20]; long long ans[1 << 14]; int main() { ios ::sync_with_stdio(0); cin >> n; for (int i = 0; i < n; ++i) cin >> know[i]; for (int i = 0; i < n; ++i) for (int j = 0; j < n; ++j) know[i][j] -= '0'; ...
18
#include <bits/stdc++.h> using namespace std; int main() { int s, m, l, xl, xxl, k, i; string d; cin >> s >> m >> l >> xl >> xxl; cin >> k; for (i = 0; i < k; i++) { cin >> d; if (d[0] == 'S') { if (s > 0) { cout << "S" << endl; s--; } else if (m > 0) { cout << "M" ...
3
#include <bits/stdc++.h> using namespace std; vector<int> G[100010]; int color[100010]; bool bfs(int src) { queue<int> q; q.push(src); color[src] = 1; while (!q.empty()) { int u = q.front(); q.pop(); for (int i = 0; i < G[u].size(); i++) { int v = G[u][i]; if (color[v] == -1) { c...
7
#include <bits/stdc++.h> using namespace std; int t; long long a, b, c, A[100]; int main() { scanf("%lld%lld%lld", &a, &b, &c); if (a == 1 && b == 1 && c == 1) puts("inf"); else if (a == b && b == c) puts("2"); else if (b == c) puts("1"); else { if (a == 1) { long long val = b; for...
20
#include <bits/stdc++.h> double eps = 1e-7; using namespace std; double v1[220]; double v2[220]; double ans; int hp1, dt1, l1, r1, p1, t1; int hp2, dt2, l2, r2, p2, t2; int att(double *v, int l, int r, int p) { int re = 0; for (int i = 1; i <= 200; i++) { if (v[i] < eps) continue; re = 1; double w = (1 ...
16
#include <bits/stdc++.h> using namespace std; const int N = 77777; const long long MOD = 777777777; struct Seg { int l, r, lc, rc; long long v[3][3]; } seg[N * 2]; int fix[N]; int segn; bool good[3][3]; bool test(int loc, int v) { return fix[loc] & (1u << (v)); } void update(Seg &ns, Seg &ls, Seg &rs) { memset(ns...
16
#include <bits/stdc++.h> using namespace std; long long int dx[] = {-1, 0, 1, 0}; long long int dy[] = {0, 1, 0, -1}; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long int n, ai, aj, bi, bj, ci, cj; cin >> n; cin >> ai >> aj >> bi >> bj >> ci >> cj; if (((bi - ai) * (ci - ai)) > 0 && (...
2
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 5; int a[N]; vector<int> g[N]; void dfs(int u, int fa) { for (int i = 0; i < g[u].size(); i++) { int v = g[u][i]; if (v == fa) continue; printf(" %d", v); a[v] *= -1; dfs(v, u); printf(" %d", u); a[u] *= -1; } if (u == 1...
11
#include <bits/stdc++.h> using namespace std; int main() { int a, v, vm, l, c; cin >> c >> v >> vm >> a >> l; int cou = 0, r = 0; while (r < c) { cou++; r += v; if (r == v) v -= l; v += a; if (v > vm - l) v = vm - l; } cout << cou << endl; }
1
#include <bits/stdc++.h> using namespace std; int main() { int num[26] = {0}; int n, m; cin >> n >> m; string s; cin >> s; for (int i = 0; i < s.length(); i++) { num[s[i] - 'A']++; } int res = 1234567890; for (int i = 0; i < m; i++) { if (res > num[i]) res = num[i]; } cout << res * m; re...
0
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; vector<string> v(n); for (int i = 0; i < n; i++) { cin >> v[i]; } long long sol = 1; for (int i = 0; i < m; i++) { vector<bool> freq(26, false); for (int j = 0; j < n; j++) { freq[v[j][i] - 'A'] = true; ...
6
#include <bits/stdc++.h> using namespace std; const int maxn = (int)2e4 + 1, INF = 0x3f3f3f3f; vector<pair<int, int> > sL[maxn << 1 | 1], sR[maxn << 1 | 1]; inline long long det(pair<int, int> p, pair<int, int> q, pair<int, int> r) { int x1 = q.first - p.first; int y1 = q.second - p.second; int x2 = r.first - q.f...
22
#include <bits/stdc++.h> using namespace std; int binomial(int n, int k) { int C[k + 1]; memset(C, 0, sizeof(C)); C[0] = 1; for (int i = 1; i <= n; i++) { for (int j = min(i, k); j > 0; j--) C[j] = C[j] + C[j - 1]; } return C[k]; } int prime(int x) { int flag = 0; for (int i = 2; i <= sqrt(x); i++) ...
2
#include <bits/stdc++.h> using namespace std; const long long MOD = 998244353; int main() { long long n, t; cin >> n >> t; long long ans = 1000 * 1000 * 1000; int ind = -1; for (int i = 0; i < n; ++i) { long long start, period; cin >> start >> period; long long k = max(0LL, (t - start + period - 1...
2
#include <bits/stdc++.h> using namespace std; long long kadane(vector<long long> temp) { long long res = 0, cur = 0; for (int i = 0; i < temp.size(); i++) { cur = max(cur + temp[i], temp[i]); res = max(cur, res); } return res; } void solve() { int n; cin >> n; vector<long long> v(n); for (long l...
8
#include <bits/stdc++.h> using namespace std; long long arr[2000001]; long long brr[2000001]; int n, m, ns, ms; long long tmp, p; int main(void) { scanf("%d %d %lld", &n, &m, &p); int chk = 0; for (int i = 0; i < n; i++) { scanf("%lld", &arr[i]); if (!chk && arr[i] % p) { chk = 1; ns = i; ...
10
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); int n, i, sum = 0, x; cin >> n; vector<int> v(n, 0); for (i = 0; i < n; i++) { cin >> x; v[x]++; } for (i = 0; i < n; i++) { sum += max(0, (v[i] - 1)); } cout << sum + 1; return 0; }
5
#include <bits/stdc++.h> using namespace std; const double eps = 1e-7; const long double PI = acos(0.0) * 2.0; mt19937_64 rng((unsigned long long)new char); const int mod = 1e9 + 7; const long long INF = 9e18; const int maxn = 2e5 + 10; const int maxl = 110; int n, m; vector<int> v[maxn]; int k[maxn]; int lad[maxn]; ve...
12
#include <bits/stdc++.h> using namespace std; const long long INF = 1 << 28; const long long LINF = 1ll << 61; int n, d, g[30111], dp[666][30611], ans; int main() { ios::sync_with_stdio(false); cin >> n >> d; int x; for (int i = 1; i <= n; i++) { cin >> x; g[x]++; } for (int i = 1; i <= 30000; i++) ...
11