solution
stringlengths
53
181k
difficulty
int64
0
13
#include <bits/stdc++.h> using namespace std; const int MAXN = 4e4 + 20; const int mod = 1e9 + 7; const int inf = 0x3f3f3f3f; const long long INF = 0x3f3f3f3f3f3f3f3f; int a[105]; int main() { int n, k; scanf("%d%d", &n, &k); for (int i = 0; i < n; i++) { scanf("%d", &a[i]); } int ans = 0, sum = 0; for ...
1
#include <bits/stdc++.h> using namespace std; int a[100010], b[100010], c[100010]; int main() { int n, m; scanf("%d%d", &n, &m); for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) { int x; scanf("%d", &x); b[j] = 1 + (x >= a[j] ? b[j] : 0); a[j] = x; c[i] = max(c[i], b[j...
4
#include <bits/stdc++.h> using namespace std; const long long int MOD = 1000000007; const long long BIG = 1446803456761533460LL; const int Big = 336860180; const long long int INF = LONG_LONG_MAX; const long long int adj4[4][2] = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}}; const long long int adj8[8][2] = {{0, 1}, {0, -1}, {...
7
#include <bits/stdc++.h> using namespace std; void fun(int n, int x); int main() { int t; int n, x; cin >> t; for (int i = 0; i < t; i++) { cin >> n; cin >> x; fun(n, x); } } void fun(int n, int x) { int sum = 2, h = 0; for (int i = 0; i <= n; i++) { sum = 2; sum += x * i; h++; ...
0
#include <bits/stdc++.h> using namespace std; using ll = long long; using ull = unsigned long long; using uint = unsigned int; constexpr int TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n - 1); } template <class T> T pow(T x, ll n) { T r = 1; while (n) { if (n & 1) r *= x; x *= x; n >>= 1; } return r...
8
#include <bits/stdc++.h> using namespace std; inline long long read() { long long x = 0, f = 1; char ch = getchar(); while (!isdigit(ch)) { if (ch == '-') f = -1; ch = getchar(); } while (isdigit(ch)) { x = x * 10 + ch - 48; ch = getchar(); } return x * f; } int n; long long x[100050], y[1...
10
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 10, MOD = 1e9 + 7, INF = 1e9 + 10, SQ = 550, LOG = 25; int n, m, x1, x2, d, z, t, y2, a[N], mini, ptr, x, y, k, ptr1, ptr2, ans; vector<int> v[N << 2]; void upd(int b, int e, int pos) { if (b > x || e <= x) return; v[pos].push_back(y); if (e - b ==...
7
#include <bits/stdc++.h> using namespace std; int c[100009], s[100009]; map<int, vector<long long> > mapa; vector<pair<int, vector<long long> > > lista; int n; bool cmp(const pair<int, vector<long long> > &A, const pair<int, vector<long long> > &B) { return A.second.size() > B.second.size(); } pair<long long...
4
#include <bits/stdc++.h> using namespace std; const long long INFLL = 2 * (long long)1e18 + 100; const int INFINT = 2 * (int)1e9 + 100; const double PI = atan(1) * 4; const double EPS = 1e-9; const int SEED = 137; const int MOD = 1e9 + 7; const int NMAX = 1e5 + 5; int n, a[NMAX]; long long dp[NMAX]; struct node { int...
7
#include <bits/stdc++.h> const int MV = 9000000; int vis[MV]; char str[MV]; int f(int x) { if (x == 0) return 1; else if (x == 1) return 0; else if (x == 2 || x == 3 || x == 5 || x == 7) { vis[x]++; return 0; } else if (x == 4) { vis[3]++; vis[2] += 2; return 0; } else if (x == 6) ...
3
#include <bits/stdc++.h> using namespace std; const int INF = (int)1e9; const int mod = (int)1e9 + 7; const int MAX = (int)1e5 + 5; int main(void) { string s; cin >> s; string a = "at", d = "dot"; string ans; int l = s.length(); bool flag = 0; for (int i = 0; i < (l); ++i) { if (i > 0 && i <= l - 4 &&...
2
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 3; long long n, m, k, ans = 0; long long p[maxn]; long long f(long long i) { return (p[i] - i + k) / k; } int main() { scanf("%lld %lld %lld", &n, &m, &k); for (long long i = 1; i <= m; i++) scanf("%lld", &p[i]); long long desp = 0; for (long ...
3
#include <bits/stdc++.h> using namespace std; int n; char s[2222]; int main() { if (0) { freopen("aaa.inp", "r", stdin); freopen("aaa.out", "w", stdout); }; scanf("%d\n", &n); gets(s); sort(s, s + n); sort(s + n, s + n + n); bool ok = 1; for (int i = 0; i < (int)n; i++) ok &= s[i] < s[i + n]; ...
1
#include <bits/stdc++.h> using namespace std; int main() { long long t; cin >> t; for (long long o = 0; o < t; o++) { long long a, b, c; cin >> a >> b >> c; if (b == 1 && c == a) { cout << -1 << " " << -1 << '\n'; } else if (c <= a) { cout << -1 << " " << b << '\n'; } else if (b ==...
1
#include <bits/stdc++.h> using namespace std; long long int degree[100010], sv[100010]; int main() { long long int n; cin >> n; vector<pair<long long int, long long int> > ans; queue<long long int> q; for (long long int i = 0; i < n; i++) { cin >> degree[i] >> sv[i]; if (degree[i] == 1) q.push(i); }...
3
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const long long LINF = 0x3f3f3f3f3f3f3f3fLL; const double PI = acos(-1.0); const double EPS = 1e-8; const int MOD = 1e9 + 7; long long qpow(long long x, long long n, long long mod = MOD) { long long res = 1; while (n) { if (n & 1) res = r...
6
#include <bits/stdc++.h> using namespace std; inline void fastRead(int *a) { register char c = 0; while (c < 33) c = getchar(); *a = 0; while (c > 33) { *a = *a * 10 + c - '0'; c = getchar(); } } inline void fastWrite(long long int a) { char snum[20]; int i = 0; do { snum[i++] = a % 10 + 48;...
7
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 5; int freq[N]; int sum[N]; int dp1[N]; int dp2[N]; int solve1(int idx) { if (freq[idx] <= 1) return idx; int &ans = dp1[idx]; if (~ans) return ans; return ans = solve1(idx + 1); } int solve2(int idx) { if (freq[idx] <= 1) return idx; int &an...
6
#include <bits/stdc++.h> using namespace std; using ll = long long; const int N = 60; ll s, x; bool S[N], X[N]; ll mem[N][2]; ll dp(int i, bool pregnant) { if (i == N - 1) { if (pregnant == 0) return 1ll; return 0ll; } if (mem[i][pregnant] != -1) return mem[i][pregnant]; ll ans = 0; for (int bt1 = 0; ...
4
#include <bits/stdc++.h> using namespace std; void solve() { int a, b, c, d; cin >> a >> b >> c >> d; if ((a + b) == (c + d) || (a + c) == (b + d) || (a + d) == (b + c)) cout << "YES"; else if ((a + b + c) == d || (a + b + d) == c || (a + c + d) == b || (b + c + d) == a) cout << "YES"; else...
0
#include <bits/stdc++.h> using namespace std; long long cdiv(long long a, long long b) { return a / b + ((a ^ b) > 0 && a % b); } long long fdiv(long long a, long long b) { return a / b - ((a ^ b) < 0 && a % b); } void solve() { string s; cin >> s; long long int n = s.size(); long long int r = ceil(n / 20.0...
2
#include <bits/stdc++.h> using namespace std; const long long r = 1e9; struct node { int a, b, c, d; }; int n, m; int t; int k, l; double a[1005]; string s; int main() { cin >> n; double minx = 0, maxx = r; for (int i = 1; i <= n; i++) cin >> a[i]; for (int i = 1; i <= n; i++) { if (minx < a[i] / i) minx ...
5
#include <bits/stdc++.h> typedef struct person { int num; int nexts[2000]; } person; person perArr[2000]; int dfs(int count, int current) { int out = 0; int cur = 0; int i = 0; if (perArr[current].num == 0) { return count; } else { for (i = 0; i < perArr[current].num; i++) { cur = dfs(count ...
0
#include <bits/stdc++.h> using namespace std; const int N = 2020; int n, Edge[N][N], deg[N], tmp[N], cnt, Min = 7; char s[N]; bool Check() { for (int i = 1; i <= n; ++i) tmp[i] = deg[i]; sort(tmp + 1, tmp + 1 + n); int sum = 0; for (int i = 1; i < n; ++i) { sum += tmp[i]; if (sum == i * (i - 1) / 2) ret...
12
#include <bits/stdc++.h> using namespace std; template <class T> inline void chmax(T &x, T &y) { if (x < y) swap(x, y); } template <class T> inline void chmin(T &x, T &y) { if (x > y) swap(x, y); } const long long INF = 0x3f3f3f3f3f3f; const long long MOD = 1e9 + 7; const long double EPS = 10e-10; void Solution() {...
1
#include <bits/stdc++.h> using namespace std; template <class T> void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()) { v.assign(a, vector<T>(b, t)); } int main() { double pi = acos(-1.0); int m, n; cin >> n >> m; vector<complex<double> > v(2 * m); double r = 1e8 - 3.0; double t = 2.0 * pi /...
7
#include <bits/stdc++.h> using namespace std; int main() { const long long MOD = 1000000009; long long n; cin >> n; if (n == 2) { cout << 10 << "\n"; return 0; } long long half = 6; long long s = n / 2 - 2; long long path = 1, p2 = 2, num = 1; for (register int i = (1); i < (int)(s + 1); ++i) ...
9
#include <bits/stdc++.h> using namespace std; bool compare(pair<int, int> p1, pair<int, int> p2) { if (p1.first == p2.first) { if (p1.second < p2.second) return true; else return false; } else if (p1.first < p2.first) return false; else return true; } int main() { ios_base::sync_with...
4
#include <bits/stdc++.h> using namespace std; template <class T, class L> bool smax(T& x, L y) { return x < y ? (x = y, 1) : 0; } template <class T, class L> bool smin(T& x, L y) { return x > y ? (x = y, 1) : 0; } const int maxn = 1e5 + 17; int n, a[maxn], b[maxn]; int main() { ios::sync_with_stdio(0), cin.tie();...
2
#include <bits/stdc++.h> using namespace std; int read() { int n; scanf("%d", &n); int prev = -99; vector<int> a(n); for (int i = 0; i < n; i++) { scanf("%d", &a[i]); } sort(a.begin(), a.end()); for (auto i : a) { if (i - prev == 1) return 2; prev = i; } return 1; } int main(int argc, ch...
0
#include <bits/stdc++.h> using namespace std; const int N = 100010; const int INF = 0x3f3f3f3f; const int iinf = 1 << 30; const long long linf = 2e18; const int MOD = 1000000007; const double eps = 1e-7; void print(int x) { cout << x << endl; exit(0); } void PRINT(string x) { cout << x << endl; exit(0); } void ...
7
#include <bits/stdc++.h> using namespace std; string intPart(string s) { int pos = s.find('.'); return s.substr(0, pos); } int main() { string s; cin >> s; int pos = s.find('.'); string inT = intPart(s); if (s[pos - 1] == '9') inT = "GOTO Vasilisa."; else if (s[pos + 1] > '4') inT[pos - 1] += 1;...
0
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { int q; cin >> q; while (q--) { ll h; int n; cin >> h >> n; vector<ll> p(n); for (int i = 0; i < n; i++) cin >> p[i]; p.push_back(0); int magic = 0; for (int i = 1; i < n; i++) { if (p[i] - p[i + ...
4
#include <bits/stdc++.h> using namespace std; int child[100005][26], cid = 1; char in[100005]; int cn; bool win[100005], lose[100005]; void build(int id, int cur) { if (cur == cn) return; int &cc = child[id][in[cur] - 'a']; if (cc == -1) { cc = cid++; } build(cc, cur + 1); } void dfs(int x) { int num = ...
5
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 50; char s[110], t[110]; int n; bool ok(int l, int r) { int po = l; for (int i = 0; i < n && po <= r; i++) { if (s[i] == t[po]) { po++; } } return (po == r + 1); } void solve() { scanf("%d", &n); scanf("%s%s", s, t); int c1...
7
#include <bits/stdc++.h> using namespace std; vector<vector<int> > graph; vector<int> h, que, d, md; int n, dist, ans1, ans2, mxh = 0, a, b; pair<int, int> res; pair<int, int> ask() { cout << "? " << que.size() << " "; for (int i = 0; i < que.size(); ++i) cout << que[i] << " "; cout << endl; que.clear(); cin ...
9
#include <bits/stdc++.h> using namespace std; long long mod(int a, int b) { if (a > b) return a - b; else return b - a; } signed main() { ios_base::sync_with_stdio(0); cin.tie(0); long long t; cin >> t; while (t--) { long long n; cin >> n; long long A[n]; long long mx = 0; long...
3
#include <bits/stdc++.h> using namespace std; int main() { int n, m, dx, dy, x, y, a[1000010], b[1000010]; scanf("%d %d %d %d", &n, &m, &dx, &dy); x = y = 0; for (int i = 0; i < n; i++) { x = (x + dx) % n; y = (y + dy) % n; a[x] = y; } for (int i = 0; i < n; i++) b[i] = 0; for (int i = 0; i < ...
6
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; if (n == 1) { cout << "YES" << endl; cout << 1 << " " << 2 << endl; } else { if (n % 2 == 0) cout << "NO" << endl; else { vector<int> v(2 * n + 1, 0); v[1] = 1; v[n + 1] = 2; v[2 * n] = 4; ...
2
#include <bits/stdc++.h> using namespace std; int xd[] = {1, 0, -1, 0}; int yd[] = {0, -1, 0, 1}; long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); } long long lcm(long long a, long long b) { return a * (b / gcd(a, b)); } inline bool isEqual(double x, double y) { const double epsilon = 1e-5...
3
#include <bits/stdc++.h> int main() { int a, b, c = 0; scanf("%d%d", &a, &b); if (b % a != 0) printf("-1\n"); else { b /= a; while (b > 1 && b % 2 == 0) { b /= 2; c++; } while (b > 1 && b % 3 == 0) { b /= 3; c++; } if (b != 1) printf("-1\n"); else ...
1
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:102400000,102400000") using namespace std; const long long mos = 0x7FFFFFFF; const long long nmos = 0x80000000; const int inf = 0x3f3f3f3f; template <typename T> inline T read(T& x) { x = 0; int f = 0; char ch = getchar(); while (ch < '0' || ch > '9') f |...
0
#include <bits/stdc++.h> using namespace std; const int mo = 998244353; const int N = 3005; int n, c, a[N]; void UPD(int &x, int y) { (x += y) >= mo ? x -= mo : 233; } namespace solver1 { long long f[N][(1 << 12) + 5]; void solve() { f[0][0] = 1; int L = (1 << c) - 1; int S = 0, ST = 0; for (int i = (int)(1); i...
13
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 5; int toi[maxn]; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); string s; long long m; cin >> s >> m; int n = s.size(); long long res = 0, tmp = 1; for (int i = 1; i <= n; i++) { toi[i] = s[i - 1] - '0'; res ...
7
#include <bits/stdc++.h> using namespace std; int n, m; int a[200000]; int b[1000]; unsigned long long answer = 1; int main(void) { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cin >> n >> m; if (n > m) { cout << 0; return 0; } int temp; for (int i = 0; i < n; i++) { cin ...
4
#include <bits/stdc++.h> using namespace std; long long n, a[200200], k, b, c; vector<int> v; bool prime[1000100]; void sieve() { int i; for (i = 1; i <= 100010; i++) { prime[i] = 1; } prime[1] = 0; i = 1; for (i = 1; i <= 1000; i++) { if (prime[i] == 1) { v.push_back(i); for (int j = i ...
2
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t > 0) { string s = ""; cin >> s; long long counter = 0, sum = 0; for (int i = 0; i < s.length(); i++) { sum += 1; if (s[i] == '+') counter += 1; else counter -= 1; if (counte...
2
#include <bits/stdc++.h> using namespace std; int n, a, b, c, d, s = 0, i; int main() { cin >> n; for (i = 1; i <= n; i++) { cin >> a >> b >> c >> d; s = s + (c - a + 1) * (d - b + 1); } cout << s; }
1
#include <bits/stdc++.h> using namespace std; bool canTell(int way, vector<vector<int>>& mark) { vector<vector<int>> tmp(5, vector<int>(5, 0)); for (int i = 0; i < 10; i++) { if (way & (1 << i)) { if (i < 5) { for (int j = 0; j < 5; j++) { tmp[i][j] = i + 1; } } else { ...
4
#include <bits/stdc++.h> using namespace std; long long n, m; signed main() { cin >> n; cin >> m; if (n > 30) { cout << m << endl; } else { long long x = 1; for (long long i = 0; i < n; i++) x *= 2; cout << m % x << endl; } }
0
#include <bits/stdc++.h> using namespace std; int main() { int m; cin >> m; int k; int discount = 100000; for (int k = 0; k < m; k++) { int temp; cin >> temp; if (temp < discount) discount = temp; } int n; cin >> n; int price[100000]; for (int k = 0; k < n; k++) cin >> price[k]; sort(p...
3
#include <bits/stdc++.h> using namespace std; void solve() { int n; cin >> n; vector<int> a(n); for (int i = 0; i < n; i++) cin >> a[i]; map<int, int> mm; for (int i = 0; i < n; i++) mm[a[i]]++; vector<int> ans = {a[0]}; for (int i = 0; i < n; i++) { for (int j = 0; j < 32; j++) { long long po...
5
#include <bits/stdc++.h> using namespace std; struct Node { int li, ri, mx, mem; Node *l; Node *r; Node(int from, int to) : li(from), ri(to), mx(0), mem(0), l(nullptr), r(nullptr) { if (from < to) { int mid = (from + to) / 2; l = new Node(from, mid); r = new Node(mid + 1, to); } ...
7
/* val = (1 << 1) == 2 val = (1 << 2) == 4 val = (1 << 3) == 8 val = (1 << 4) == 16 ------------------------------ ------------------------------ val = (1<<n) == 2^n; */ #include <bits/stdc++.h> ///#include <ext/pb_ds/assoc_container.hpp> ///#include <ext/pb_ds/tree_policy.hpp> ///using namespace __gnu_pbds; using...
0
#include <bits/stdc++.h> using namespace std; double eval(string s) { int g = 0, t = 0, f = 0, c = 0; for (unsigned int i = 0; i < s.length(); i++) { if (s[i] == 'X') t++; else if (s[i] == (t & 1 ? 'R' : 'L')) g++, t++, f = 0; else g++, t += 2, c += f, f = !f; } if (t & 1) t++, c +...
10
// Jai Shree Ram #include<bits/stdc++.h> using namespace std; #define rep(i,a,n) for(int i=a;i<n;i++) #define ll long long #define int long long #define pb push_back #define all(v) v.begin(),v.end() #define endl "\n" #define x first #define y ...
8
#include <bits/stdc++.h> using namespace std; template <class T1, class T2> void chmin(T1 &a, T2 b) { if (b < a) a = b; } long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; } vector<long long> divisors(long long n) { vector<long long> ds; for (long long i = 1; i * i <= n; i++) { if (n % i...
9
#include <bits/stdc++.h> using namespace std; const int M = 2010; const int Q = 1e9 + 7; int l[10], r[10]; int main() { srand(time(NULL)); int i, j, t, mask, n; long double p0, p, ans = 0.; scanf("%d", &n); for (i = 0; i < n; i++) scanf("%d%d", &l[i], &r[i]); for (i = 1; i <= 10000; i++) { p0 = 0.; ...
6
#include <bits/stdc++.h> using namespace std; int n, a[1000005], d, b[2000005], ans; bool vis[1000005]; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int T; cin >> T; while (T--) { cin >> n >> d, ans = 0; for (int i = 0; i < n; ++i) cin >> a[i], vis[i] = 0; for (int i = 0; i...
4
#include <bits/stdc++.h> using namespace std; using ll = long long; constexpr int MOD = 1000000007; inline void Add(int &a, int b) { a += b; if (a >= MOD) a -= MOD; } int main() { int n, m; scanf("%d %d", &n, &m); vector<string> a(n + 1); a[0] = string(m + 1, '#'); for (int i = 1; i <= n; ++i) { stati...
8
#include <bits/stdc++.h> using namespace std; long long a[305], b[305], c[305]; int main() { int n; pair<long long, long long> p[2]; long long r[2]; for (int i = 0; i < 2; i++) scanf("%lld%lld", &p[i].first, &p[i].second); scanf("%d", &n); int ans = 0; for (int i = 0; i < n; i++) { scanf("%lld%lld%lld...
4
#include <bits/stdc++.h> namespace { const int N = 500; const int M = (N - 1) * N + 1; int n, mod; void add(int &x, int a) { x += a; if (x >= mod) { x -= mod; } } int fact[N], dp[M], sum[M + 1]; } // namespace int main() { scanf("%d%d", &n, &mod); fact[n - 1] = 1; for (int i = n - 1; i > 0; -- i)...
8
#include <bits/stdc++.h> using namespace std; template <typename M> class Enumeration { private: static vector<M> fact, finv, invs; public: static void init(int n) { n = min<decltype(M::mod)>(n, M::mod - 1); int m = fact.size(); if (n < m) return; fact.resize(n + 1, 1); finv.resize(n + 1, 1);...
5
#include <bits/stdc++.h> using namespace std; template <typename T> void read(T &x) { x = 0; char ch = getchar(); int f = 1; while (!isdigit(ch)) { if (ch == '-') f *= -1; ch = getchar(); } while (isdigit(ch)) { x = x * 10 + ch - 48; ch = getchar(); } x *= f; } int n, a[5050], b[5050]; n...
13
#include <bits/stdc++.h> using namespace std; const long double INF = 1e9; vector<tuple<int, int, int> > v; map<pair<long long, tuple<int, int, int> >, long double> mp; vector<int> e[31][4]; long double pb[] = {1.0 / 6, 1.0 / 6, 1.0 / 3, 1.0 / 3}; int get_pos(vector<tuple<int, int, int> > v, tuple<int, int, int> p) { ...
8
#include <bits/stdc++.h> int main() { std::ios_base::sync_with_stdio(false); std::cin.tie(0); std::cout.tie(0); size_t t; std::cin >> t; while (t-- > 0) { size_t n, a, b, c, d; std::cin >> n >> a >> b >> c >> d; size_t min = n * (a - b); size_t max = n * (a + b); if (max - min + 2 * d >=...
0
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { ios::sync_with_stdio(0); cin.tie(0); mt19937_64 rng( chrono::high_resolution_clock::now().time_since_epoch().count()); int n; cin >> n; vector<array<int, 3>> v(n); for (auto &[x, y, z] : v) cin >> x >> y >> z; map<arr...
7
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 7; int n, m; int ans[N]; int last[N]; vector<int> G[N]; vector<int> in[N]; int main() { scanf("%d %d", &n, &m); for (int i = 1; i <= m; ++i) { int u, v; scanf("%d %d", &u, &v); G[u].push_back(v); G[v].push_back(u); } for (int i = ...
4
#include <bits/stdc++.h> using namespace std; const int MOD = 1000000007; const int MAXN = 1010, MAXK = 60; inline int add(int a, int b) { int ret = a + b; if (ret >= MOD) ret -= MOD; return ret; } inline int mul(int a, int b) { long long int ret = (long long int)a * b; if (ret >= MOD) ret %= MOD; return re...
7
#include <bits/stdc++.h> void solve() { int n, m; std::cin >> n >> m; std::vector<std::vector<int>> E(n); for (int i = 0; i < m; ++i) { int u, v; std::cin >> u >> v; --u, --v; E[u].push_back(v); E[v].push_back(u); } std::vector<bool> vis(n); std::vector<int> fa(n), dep(n); std::funct...
9
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; long long f, w, h, pref[200005], suff[200005], sum, sum1; long long BinPow(long long x, long long n) { if (n == 0) return 1LL; else if (n == 1) return x % mod; else { long long sum = BinPow(x, n / 2) % mod; sum *= sum; ...
7
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5, INF = 1e9; struct T { int l, r, d[3], mn[3], mx[3]; } t[N]; int n, m, q, a, b, c, lx, rx, ly, ry, lz, rz, rt, h[N], D; inline bool cmp(int a, int b) { return t[a].d[D] < t[b].d[D]; } inline void update(int x) { int l = t[x].l, r = t[x].r; for (i...
9
#include <bits/stdc++.h> using namespace std; int get() { char ch; while (ch = getchar(), (ch < '0' || ch > '9') && ch != '-') ; if (ch == '-') { int s = 0; while (ch = getchar(), ch >= '0' && ch <= '9') s = s * 10 + ch - '0'; return -s; } int s = ch - '0'; while (ch = getchar(), ch >= '0' &...
9
#include <bits/stdc++.h> using namespace std; int rd() { int x = 0, f = 1; char c = getchar(); while (c > '9' || c < '0') f = c == '-' ? -1 : 1, c = getchar(); while (c >= '0' && c <= '9') x = x * 10 + c - 48, c = getchar(); return x * f; } const int N = 3e5 + 10; const int inf = 1e6 + 10; map<int, int> mp; i...
11
#include <bits/stdc++.h> using namespace std; const int MAX = 1e6 + 9; set<int> ist; map<string, int> msi; map<string, string> mss; map<int, string> mis; map<int, int> mii; pair<int, int> pii; vector<int> v; vector<pair<int, int> > vv; int cc[] = {1, -1, 0, 0}; int rr[] = {0, 0, 1, -1}; void LIFT_OFF_SHARK_AP20() { i...
2
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; const int N = 1e6 + 6; ll inv(ll a, ll m) { return a == 1 ? 1 : m - m * inv(m % a, a) / a; } int main() { ios::sync_with_stdio(0); cin.tie(0); int p; ll a, b, x; cin >> a >> b >> p >> x; ll per = p * (p - 1LL); ll ...
6
#include <bits/stdc++.h> #define INF 0x3f3f3f3f #define Inf 1000000000000000000LL #define LL long long #define pb push_back #define mp make_pair #define F first #define S second using namespace std; typedef pair<int,int>pii; const int mod=1e9+7; int n,a[100010]; vector<int>w; string s; LL pre[100010],sum[100010],dp[100...
9
#include <bits/stdc++.h> using namespace std; bool f(string s, string t) { long long int j = 0; for (long long int i = 0; i < s.size(); i++) { if (s[i] == t[j]) { j++; } } if (j == t.size()) { return true; } else { return false; } } int main() { ios_base::sync_with_stdio(false); ci...
0
#include <bits/stdc++.h> using namespace std; bool borj(int n, int i) { int a = pow(2, ((double)i)); int g = (a - 1) * a / 2; if (n % g == 0) return true; return false; } int main() { int n; int m = 0; scanf("%d", &n); for (int i = 1; i <= n; i++) { if (borj(n, i) == true) { int a = pow(2, ((d...
1
#include <bits/stdc++.h> using namespace std; const int INF = 1e9 + 10; const int MK = 37, MN = 1e5 + 10; int dp[MK][MN], a, b, h, w, n; int ext[MN], Ans = INF; void solve() { memset(dp, 0, sizeof dp); dp[0][1] = 1; for (int i = 0; i < n; ++i) { for (int val = 1; val < MN; ++val) { int F = min((long lon...
6
#include <bits/stdc++.h> using namespace std; const long long N = 111111; pair<long long, long long> stud[N]; long long ttoi[N], ans[N]; set<long long> off[N]; long long n, m; signed main() { ios_base::sync_with_stdio(false); cin.tie(0); cin >> n >> m; for (long long i = (1); i <= (n); i++) { long long t, x...
3
#include <bits/stdc++.h> using namespace std; int main() { int i = 0, s = 2015; printf("2000\n"); for (i = 1; i <= 1000; i++) printf("%d 1 %d 2\n", i, i); for (i = 1000; i >= 1; i--) printf("%d 1 %d 2\n", i, i); }
4
#include <bits/stdc++.h> using namespace std; struct tria { int p[3]; } trias[100010]; vector<int> p2t[100010]; int i, j, n, m; bool checked[100010]; int di[100010]; vector<pair<int, int> > que; vector<int> ans; bool cmp(pair<int, int> a, pair<int, int> b) { return a.first > b.first; } map<pair<int, int>, int> edgeC;...
8
#include <bits/stdc++.h> using namespace std; int n, k, l; deque<long long> a, pr, dp; long long f[2048], C[2048][2048], mod = 1000000007; int main(int argc, char const* argv[]) { cin >> n; f[0] = 1; for (int i = 1; i <= n; i += 1) f[i] = ((f[i - 1] * ((long long)i)) % mod); for (int i = 0; i <= n; i += 1) { ...
6
#include <bits/stdc++.h> using namespace std; template <typename T> T GCD(T a, T b) { long long t; while (a) { t = a; a = b % a; b = t; } return b; } template <typename T> string toString(T a) { return to_string(a); } template <typename T> void toInt(string s, T &x) { stringstream str(s); str ...
4
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; int i = 0, x = -1, ans = 0; while (i < s.length()) { if (s[i] % 3 == 0) { x = i; ans++; } else { int j = i, sum = 0; while (j > x) { sum += s[j]; if (sum % 3 == 0) { j = x; ...
3
#include<bits/stdc++.h> #define ll long long #define Il inline #define Re register #define mem(u,v) memset(u,v,sizeof(u)) #define rep(i,a,b) for(Re ll i=(a);i<=(b);i++) #define drep(i,a,b) for(Re ll i=(a);i>=(b);i--) #define go(u) for(ll i=head[u],v=e[i].to;i;i=e[i].nxt,v=e[i].to) #define writesp(x) write(x),putchar(' ...
5
#include <bits/stdc++.h> using namespace std; const int MAX = 1e6 + 10; const int MOD = 998244353; const int INF = 1e9 + 7; char s[MAX]; long long n, m, L; long long sum[MAX]; pair<long long, long long> d[MAX]; long long cal(long long val) { d[0] = {0, 0}; for (int i = 1; i <= n; i++) { d[i] = d[i - 1]; d[i...
10
#include <bits/stdc++.h> using namespace std; const int sz = 5e5 + 30; const int INF = 1e9 + 7; class codeforces { public: void solve(); }; map<pair<int, int>, int> m; void codeforces ::solve() { int n, r1, c1, r2, c2; cin >> n >> r1 >> c1 >> r2 >> c2; pair<int, int> p; for (int i = 0; i < 4 * n; ++i) { ...
2
#include <bits/stdc++.h> int main() { bool color[27]; char board[101][101], str[120]; int n, m, tmp; char pres, ent; int cnt = 0; for (int i = 0; i < 27; i++) color[i] = false; scanf("%d %d %c", &n, &m, &pres); scanf("%c", &ent); while (ent != '\n') scanf("%c", &ent); for (int i = 0; i < n; i++) { ...
1
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; if (n <= 10 or n >= 22) cout << 0; else if (n >= 11 and n != 20) cout << 4; else cout << 15; }
0
#include <bits/stdc++.h> using namespace std; void solve() { int n; cin >> n; vector<int> a(n); vector<pair<int, int>> b(n); for (int i = 0; i < n; i++) { cin >> a[i]; b[i].first = a[i]; b[i].second = i; } sort(b.begin(), b.end()); for (int i = 1; i < n; i++) { if (b[i].first == b[i - 1]...
5
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 1; long long in() { long long x; cin >> x; return x; } int In() { int x; cin >> x; return x; } void solve() { long long n; cin >> n; string s; cin >> s; int ca = 0, cb = 0; for (long long i = 0; i < n; i++) { long long ca = 0,...
0
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; for (int i = -n; i <= n; i++) { int upto = n - abs(i); for (int j = 0; j < 2 * n - 2 * upto; j++) { cout << " "; } for (int j = -upto; j <= upto; j++) { cout << upto - abs(j) << "\n "[j < upto]; } } ret...
1
#include <bits/stdc++.h> using namespace std; long long gcd(long long a, long long b) { if (b == 0) return a; return gcd(b, a % b); } const int MOD = 1000000007; int pd[2003][2003]; long long v[2003]; int n, h; int solve1(int p, int c) { if (p == n) return c == 0; if (pd[p][c] == -1) { long long ans = 0; ...
6
#include <bits/stdc++.h> using namespace std; const int N = 1050; long long p1, p2, v1, v2, x, sz, Num, R1S, R1E, R2S, R2E, R3S, R3E, R4S, R4E, arr[N]; double All, Good; bool Valid1, Valid2, Valid3, Valid4, Same; void Go(int length) { if (length > 9) return; arr[sz++] = Num; Num *= 10; Num += 4, Go(length +...
5
#include <bits/stdc++.h> using namespace std; template <typename T, typename U> inline void smin(T &a, U b) { if (a > b) a = b; } template <typename T, typename U> inline void smax(T &a, U b) { if (a < b) a = b; } template <class T> inline void gn(T &first) { char c, sg = 0; while (c = getchar(), (c > '9' || c ...
9
#include <bits/stdc++.h> using namespace std; const int MOD = 1e9 + 7; const int N = 200005; int n; vector<int> g[N]; int par[N], par2[N], dis[N]; int deg[N]; int sub[N]; void calc_sub(int v, int p = 0) { sub[v] = 1; for (int i : g[v]) { if (i == p) continue; calc_sub(i, v); sub[v] += sub[i]; } } int ...
6
#include <bits/stdc++.h> using namespace std; void solve() { long long n, s; cin >> n >> s; vector<vector<long long>> tree(n + 1); for (long long i = 0; i < n - 1; i++) { long long a, b; cin >> a >> b; tree[a].push_back(b); tree[b].push_back(a); } long long leaf = 0; for (long long i = 1; ...
4
#include <bits/stdc++.h> #pragma optimization_level 3 #pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx") using namespace std; const long double PI = 3.14159265358979323846; const long long MOD = 1e+9 + 7; const long long INF = LLO...
1