solution
stringlengths
53
181k
difficulty
int64
0
27
#include <bits/stdc++.h> int main() { puts("3"); return 0; }
12
#include <bits/stdc++.h> using namespace std; struct _ { ios_base::Init i; _() { cin.sync_with_stdio(1); cin.tie(0); } } _; struct SAT2 { int n, group_label; vector<vector<int> > edge, reverse_edge; vector<int> traversed_order, group_number; vector<bool> vis; SAT2() {} SAT2(int n) : n(n)...
18
#include <bits/stdc++.h> using namespace std; int n, jc[2002], f[2002], g[2002], h[2002][2002], a[2002][2002], c[2002], d[2002]; bool b[2002], bb[2002]; int pow(int x, int y) { int res = 1; for (; y; y >>= 1, x = 1LL * x * x % 998244353) if (y & 1) res = 1LL * res * x % 998244353; return res; } int main()...
21
#include <bits/stdc++.h> using namespace std; long long n; long long m[305][305]; long long g[305][305]; vector<long long> dijkstra(long long source) { typedef struct pair { long long vertex, distance; bool operator<(const pair& ot) const { return !(this->distance < ot.distance); } } PAIR; prior...
11
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); int n; cin >> n; pair<int, int> p[n]; for (int i = 0; i < n; i++) { cin >> p[i].first; p[i].second = i + 1; } sort(p, p + n); int t1 = n / 2 + (n % 2), t2 = n / 2; cout << t1 << endl; for (int i = 0;...
7
#include <bits/stdc++.h> using namespace std; int main() { long long int n, m = INT_MIN, r, l, i, in, sum = 0, maxlen = 1, c; float avg = INT_MIN; cin >> n; long long int arr[n]; for (i = 0; i < n; i++) { cin >> arr[i]; if (arr[i] > m) { in = i; m = arr[i]; } } l = in; r = in; ...
3
#include <bits/stdc++.h> using namespace std; const int MAXN = 2e5 + 100; int best[MAXN]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t; cin >> t; while (t--) { int n; cin >> n; int a[n + 1]; for (long long i = 0; i < n; i++) { cin >> a[i]; best[i] = 0...
9
#include <bits/stdc++.h> using namespace std; int main() { int m, n; scanf("%d%d", &n, &m); int i, a[n + 2], b[m + 2], ans; for (i = 0; i < n; i++) { scanf("%d", &a[i]); } for (i = 0; i < m; i++) { scanf("%d", &b[i]); } sort(a, a + n); sort(b, b + m); if (b[0] <= a[n - 1] || 2 * a[0] >= b[0]...
4
#include <bits/stdc++.h> using namespace std; inline long long read() { long long f = 1, x = 0; char s = getchar(); while (s < '0' || s > '9') { if (s == '-') f = -1; s = getchar(); } while (s >= '0' && s <= '9') { x = x * 10 + (s - '0'); s = getchar(); } return x * f; } const int jzm = 10...
15
#include <bits/stdc++.h> using namespace std; int a[1000005], f[1000005][7][7], n, m; int main() { cin >> n >> m; for (int i = 1; i <= n; i++) { int u; cin >> u; a[u]++; } for (int i = 0; i < 1000005; i++) { for (int j = 0; j < 7; j++) { for (int k = 0; k < 7; k++) { f[i][j][k] = -...
14
#include <bits/stdc++.h> using namespace std; const long long INFL = 1LL << 60; const long long INF = INFL; long long MOD = 1000000007; vector<long long> dy = {0, 0, 1, -1, 1, 1, -1, -1, 0}; vector<long long> dx = {1, -1, 0, 0, 1, -1, 1, -1, 0}; void BinarySay(long long x, long long y = 60) { for (long long i = 0; i ...
12
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5; const int MOD = 1000000007; void solve() { long long p, q; cin >> p >> q; if (p % q) cout << p << "\n"; else { long long x = 1; bool f = false; for (long long i = 2; i * i <= q; i++) { if (q % i == 0) { f = true; ...
7
#include <bits/stdc++.h> using namespace std; const long long N = 1000005; long long n, a[N], root, d[N]; priority_queue<long long, vector<long long>, greater<long long>> heap; signed main() { ios::sync_with_stdio(false); cin >> n; for (long long i = 2; i <= n; i++) cin >> a[i]; root = a[2]; cout << root << e...
14
#include <bits/stdc++.h> using namespace std; int a1, a2, a3, a4; deque<char> ans; int32_t main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); ; cin >> a1 >> a2 >> a3 >> a4; if (a3 > min(a1, a2) || a4 > min(a1, a2) || abs(a3 - a4) > 1) { cout << "-1"; return 0; } for (int i = 1; i <= a3; ...
10
#include <bits/stdc++.h> using namespace std; #define N 200001 set<pair<int, char>> graph[N]; void solve() { int n, m; cin >> n >> m; int br1 = 0, br2 = 0; for (int i = 0; i < m; i++) { char c; cin >> c; if (c == '?') { int k; cin >> k; if (k...
16
#include <bits/stdc++.h> using namespace std; vector<pair<int, int> > p; int n, a, b, ans[102]; int area(int i, int j) { return (p[i].first * p[i].second) + (p[j].first * p[j].second); } bool chk(int i, int j) { int x = p[i].first + p[j].first; int y = max(p[i].second, p[j].second); if (max(x, y) <= max(a, b) &...
7
#include <bits/stdc++.h> using namespace std; int a[2000005]; map<int, int> mp; int getcnt(int l, int r) { map<int, int>::iterator it1, it2; int sb; it1 = mp.lower_bound(l); if (it1 != mp.begin()) { it1--; sb = it1->second; } else { sb = -1; } it2 = mp.upper_bound(r); it2--; return it2->se...
12
#include <bits/stdc++.h> using namespace std; inline void Rd(int &res) { char c; res = 0; while (c = getchar(), c < '0') ; do { res = (res << 1) + (res << 3) + (c ^ 48); } while (c = getchar(), c >= '0'); } const int M = 200005; struct Node { int to, nxt; } Edge[M << 1]; int Head[M], tot; int n, k; ...
13
#include <bits/stdc++.h> using namespace std; void dfs(vector<vector<int>> &g, vector<int> &vis, stack<int> &st, int u, int &flag) { vis[u] = 1; for (auto v : g[u]) { if (vis[v] == 0) { dfs(g, vis, st, v, flag); } else if (vis[v] == 1) { flag = 1; } } st.push(u); vis[u] = 2; }...
10
#include <bits/stdc++.h> #pragma GCC optimize("O3") #pragma GCC target("avx2") using namespace std; const int mxN = 3e5; int n, m, t, a[mxN], cnt[mxN]; bool vis[mxN]; int main() { cin >> t; for (; t > 0; --t) { cin >> n >> m; for (int i = 0; i < n; ++i) { cin >> a[i], --a[i]; } memset(cnt, 0, ...
13
#include <bits/stdc++.h> using namespace std; uint64_t ar[300003]; uint64_t dp[2][1 << 20]; int main() { int t, tc = 0; uint64_t n; cin >> n; for (uint64_t i = 0; i < n; i++) cin >> ar[i]; dp[1][0] = 1; uint64_t ans = 0, x = 0; for (uint64_t i = 0; i < n; i++) { x ^= ar[i]; ans += dp[i % 2][x]; ...
8
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); int t; cin >> t; while (t--) { int n; cin >> n; int a[n]; for (int i = 0; i < n; ++i) cin >> a[i]; for (int i = 1; i < n; i += 2) a[i] = -1 * a[i]; for (int i = 0; i < n; i +...
0
#include <bits/stdc++.h> using namespace std; using ll = long long; const int N = 1e1 + 4; vector<int> circle; bool vis[N]; int parent[N]; ll chk[N]; int color[N]; int tim[N]; int dis[N]; int position[N]; vector<int> adj[N]; vector<int> adj1[N]; vector<int> graph[N]; bool has_cycle; int maxdis, maxnode, Totnode, depth ...
7
#include <bits/stdc++.h> using namespace std; int main() { long long int n, m, a, b, s1 = 0, s2 = 0; cin >> n >> m >> a >> b; s1 = (m - (n % m)); s2 = n % m; s1 = (s1 * a <= s2 * b) ? s1 * a : s2 * b; cout << s1 << endl; return 0; }
2
#include <bits/stdc++.h> using namespace std; map<long long, pair<int, int> > am; map<long long, int> ma; int cost[1000005]; pair<int, int> qu[1000005], c, d; set<pair<int, int> > se; int a1, b1, a2, b2, res = 1e9; void normalize(int& a, int& b) { if (a > b) swap(a, b); } void bfs1() { normalize(a1, b1); int fr =...
11
// Problem Statement: https://codeforces.com/contest/1474/problem/E/ /** * Author: Ravi Kanth Gojur * Code Forces: ravireddy07 * Code Chef: ravireddy115 * Github: ravireddy07 **/ #include <bits/stdc++.h> #define ll long long int #define ravireddy07 return #define ii(a) scanf("%d", &a) #define ii2(a, b) scanf...
17
#include <bits/stdc++.h> using namespace std; void start(istream& str) {} bool* b; string solve(istream& cin) { int n; cin >> n; int* ord = new int[n]; for (int i = 0; i < n; i++) cin >> ord[i]; int m = n; int last = 0; string res = ""; b = new bool[n + 1]; for (int i = 0; i < n + 1; i++) { b[i] =...
3
#include <bits/stdc++.h> using namespace std; const int maxn = 5e5 + 5; struct LBase { int n, basis[20]; LBase() { n = 0; } inline void insert(int x) { if (n == 20) return; for (int i = 0; i < n; i++) x = min(x, x ^ basis[i]); if (x != 0) { basis[n++] = x; for (int k = n - 1; k > 0 && basi...
17
#include <bits/stdc++.h> using namespace std; int n; int a[100010]; int minn = 0x3fffffff; int ans = 0x3fffffff, pre = -0x3fffffff; int main() { int i, j, k; scanf("%d", &n); for (i = 1; i <= n; ++i) { scanf("%d", a + i); minn = min(minn, a[i]); } for (i = 1; i <= n; ++i) { if (a[i] == minn) { ...
3
#include <bits/stdc++.h> using namespace std; long long n, c, a[100005], b[100005]; int i; long long check(long long x) { int i; long long sum = 0; for (i = 1; i <= n; ++i) { if (1. * x * a[i] / b[i] > c + 1) return c + 1; sum += 1ll * x * a[i] / b[i] + 1; if (sum > c) return c + 1; } return sum; ...
11
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 6; const int maxl = 1e6 + 6; const int mod = 1e9 + 7; using ll = long long; using pii = pair<int, int>; string s[maxn]; int nxt[maxl]; vector<int> sorted[maxn]; int dp[2][maxl]; vector<ll> h[maxn][2]; ll Pow(ll a, ll b, int p) { ll ret = 1; while ...
20
#include <bits/stdc++.h> using namespace std; const long long N = 2e5 + 100; void testcase() { long long n; cin >> n; vector<long long> a(n); for (auto &x : a) cin >> x; sort(a.begin(), a.end()); vector<long long> fa(N), fb(N); for (auto x : a) { fa[x] = 1; } for (long long i = 1; i < N - 1; i++) ...
10
#include <bits/stdc++.h> using namespace std; using ll = long long; double eps = 0.0000001; int p1_ = 63; int m1_ = 1000000009; void get_h(string &s, vector<int> &h_pref, vector<int> &pow_p, long long p = p1_, int m = m1_) { pow_p[0] = 1; int n = pow_p.size(); for (int i = 1; i < n; i++) { pow_p[i]...
10
#include <bits/stdc++.h> using namespace std; int bucatal, bucatac; string s[20]; bool nuefull() { for (int i = bucatal; i < bucatal + 3; ++i) { for (int j = bucatac; j < bucatac + 3; ++j) { if (s[i][j] == '.') { return true; } } } return false; } int main() { int l, c; for (int i ...
6
#include <bits/stdc++.h> using namespace std; const long long int inf = 1e15; const int mx = 2e5 + 5; const int x_move[] = {1, -1, 0, 0, 1, 1, -1, -1}; const int y_move[] = {0, 0, 1, -1, 1, -1, 1, -1}; int main() { int t, q, ca = 1; int n; long long int pa, pb, pc; long long int ans = 0; pa = pb = pc = inf; ...
14
#include <bits/stdc++.h> using namespace std; const long long D = 31; const long long N = 100010; struct constraint { long long l, r, q; constraint(long long _l, long long _r, long long _q) { l = _l; r = _r; q = _q; } }; void err() { cout << "NO" << '\n'; exit(0); } long long n, m; long long a[N][...
10
#include <bits/stdc++.h> using namespace std; vector<int> vec[10500]; int main() { int n; cin >> n; int x = 0; while (x * (x + 1) / 2 <= n) x++; cout << x << endl; int k = 1; for (int i = 1; i <= x; i++) { for (int j = i + 1; j <= x; j++, k++) { vec[i].push_back(k); vec[j].push_back(k); ...
8
#include <bits/stdc++.h> int prevAmplifyingLine, isAmplifyingLine, firstLine; char S[1100000]; int i, L; int main() { prevAmplifyingLine = 0; firstLine = 1; while (1) { S[0] = 0; fgets(S, 1100000 - 2, stdin); if (S[0] == 0) break; isAmplifyingLine = 0; L = strlen(S); for (i = 0; i < L; i++...
9
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; char A[n][n]; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if ((i + j) % 2 == 0) A[i][j] = 'W'; else A[i][j] = 'B'; cout << A[i][j]; } cout << endl; } }
3
#include <bits/stdc++.h> constexpr auto INF = 9223372036854775807; using namespace std; auto seed = chrono::high_resolution_clock::now().time_since_epoch().count(); mt19937 mt(seed); int myrand(int mod) { return mt() % mod; } long long int gcd(long long int a, long long int b) { if (b == 0) return a; return gcd(b, ...
8
#include <bits/stdc++.h> using namespace std; int dp[510][510]; int main() { int n; cin >> n; vector<int> s(n), t; for (int i = 0; i < n; ++i) { cin >> s[i]; } for (int i = 0; i < 510; ++i) for (int j = 0; j < 510; ++j) dp[i][j] = 0; for (int l = 1; l <= n; ++l) { for (int i = 0, j = l - 1; j ...
11
#include <bits/stdc++.h> using namespace std; const int inf = 2e9 + 7; const long long Inf = 1e18 + 7; const int maxn = 2e5 + 5; const long long mod = 998244353; int n; int a[maxn], t[maxn]; struct cmp { bool operator()(const pair<int, int>& a, const pair<int, int>& b) { return a.second < b.second; } }; priorit...
9
#include <bits/stdc++.h> #pragma GCC optimize("O3") #pragma GCC target("sse4,avx2,abm,fma,tune=native") #pragma GCC optimize("fast-math") using namespace std; const char nl = '\n'; const double INF = 1e36; const double EPS = 1e-9; mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count()); struct pt {...
21
#include <bits/stdc++.h> using namespace std; bool cmp(char a, char b) { return a > b; } signed main() { long long t; cin >> t; while (t--) { long long ch[27] = {}; char ans[55] = {}; string s; vector<long long> v; long long n, pos, a[55]; cin >> s >> n; long long ac = n; for (long...
10
#include <bits/stdc++.h> using namespace std; int n, a, ans[200005], A[200005], root = -1, f; bool b[200005]; vector<int> v[200005]; vector<int> cyc; void dfs(int u, int p) { for (auto x : v[u]) { if (b[x] && x != p) { if (A[x] == u) cyc.push_back(x); else cyc.push_back(u); } else ...
9
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> v(n); for (int &x : v) { cin >> x; } int len = ceil((int)v.size() / 2.0); int d = 0; for (int i = -1000; i <= 1000; i++) { if (i == 0) continue; int pos = 0; for (int j = 0; j < n; j++) { if (v[...
0
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, k; cin >> n >> k; auto And = [&](int x, int y) { cout << "and " << x + 1 << " " << y + 1 << endl; int ret; cin >> ret; return ret; }; auto Or = [&](int x, int y) { cout...
10
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const long long llINF = 1e18; const int MAXN = 3e5 + 5; namespace FastIO { char buf[1 << 23], *p1 = buf, *p2 = buf; int read() { static int x, f; static char ch; x = 0, f = 1; ch = (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 21, st...
15
#include <bits/stdc++.h> using namespace std; int main() { int k; cin >> k; if (k % 2 == 0) { cout << "NO" << endl; return 0; } cout << "YES" << endl; if (k == 1) { cout << 2 << " " << 1 << endl; cout << 1 << " " << 2 << endl; return 0; } int n = k + 2; int m = n * k; cout << 2 *...
11
#include <bits/stdc++.h> using namespace std; const int N = 60; long long n, arr[N], dp[N][2]; long long fun(long long i, long long flag) { if (i > n) { return 0; } if (dp[i][flag] != -1) { return dp[i][flag]; } if (flag == 1) { return dp[i][flag] = max(arr[i] + fun(i + 1, (long lon...
7
#include <bits/stdc++.h> using namespace std; string s[60]; int dp[60][60][60][60]; inline bool can(int i, int j) { return ((s[i][0] == s[j][0]) || (s[i][1] == s[j][1])); } int rec(int len, int x, int y, int z) { if (len == 3) return 1; if (dp[len][x][y][z] != -1) return dp[len][x][y][z]; int ret = 0; if (can...
11
#include <bits/stdc++.h> using namespace std; const long long inf = 1e18; const long long mod = 1e9 + 7; const long long N = 2e5 + 1; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); long long power(long long a, long long b = mod - 2) { long long res = 1; while (b > 0) { if (b & 1) res = res...
0
#include <bits/stdc++.h> using namespace std; const int cnt[3000] = { 4784, 8978, 12981, 16901, 20732, 24523, 28249, 31916, 35585, 39176, 42818, 46430, 49962, 53516, 57023, 60523, 64040, 67489, 70985, 74417, 77879, 81285, 84679, 88055, 91433, 94878, 98240,...
14
#include <bits/stdc++.h> #pragma GCC optimize("O3,no-stack-protector") #pragma GCC target("tune=native") using namespace std; using ll = long long; const int N = 120005; struct node_t { int tag, time, value, number; ll answer; } tree[N << 2]; int n, m, top_max, top_min, a[N], stack_max[N], stack_min[N]; vector<pair...
22
#include <bits/stdc++.h> using namespace std; const int MAX = 100007; long long int n, k, ans, arr[MAX]; int main() { std::ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cout.precision(10); cout << fixed; cin >> n >> k; for (int i = 0; i < n; i++) { cin >> arr[i]; } long long int...
2
#include <bits/stdc++.h> using namespace std; const int maxn = 2005; char s[maxn], p[maxn]; int _dp[maxn * maxn * 2]; int ans[maxn]; int ls, lp; int& dp(int poss, int posp, int alrp) { return _dp[poss * 2 * maxn + alrp * lp + posp]; } void updDp(int a, int b, int c, int d) { int& x = dp(a, b, c); if (x == -1 || x...
14
#include <bits/stdc++.h> using namespace std; long long int mi(long long int n, long long int m) { long long int pw = n; long long int ex = m - 2; long long int ans = 1; while (ex) { if (ex & 1) ans = ans * pw % m; pw = pw * pw % m; ex >>= 1; } return ans; } long long int pw(long long int a, lon...
10
#include <bits/stdc++.h> using namespace std; int main() { char a[100][100]; int v[100][100]; int n, count = 0; int check = 0; cin >> n; for (int i = 0; i < n; i++) { cin >> a[i]; for (int j = 0; j < n; j++) { if (a[i][j] == '#') count++; } } for (int i = 0; i < n; i++) { for (int ...
3
#include <bits/stdc++.h> using namespace std; int main() { int n, k, i, j, sum = 0; string s; cin >> n >> k >> s; sort(s.begin(), s.end()); sum = sum + s[0] - 96; k--; for (i = 0; i < n - 1 && k > 0; i = j) { for (j = i + 1; j < n; j++) if (s[j] - s[i] > 1) { sum += s[j] - 96; k-...
1
#include <bits/stdc++.h> using namespace std; map<string, int> number; string name[146]; int need[146][146]; int cnt[146][146]; vector<pair<string, int> > v; int toint(string s) { stringstream ss(s); int n; ss >> n; return n; } int main() { int k, n, m, q; cin >> k >> n >> m >> q; for (int i = 0; i < n; i...
12
#include <bits/stdc++.h> using namespace std; template <class T> inline void rd(T &x) { x = 0; char c = getchar(); int f = 1; while (!isdigit(c)) { if (c == '-') f = -1; c = getchar(); } while (isdigit(c)) x = x * 10 - '0' + c, c = getchar(); x *= f; } int mod; inline int Pow(int x, int y) { int...
24
#include <bits/stdc++.h> using namespace std; long long int mod = 1000000007; long long int powmod(long long int a, long long int b) { long long int res = 1; a %= mod; assert(b >= 0); for (; b; b >>= 1) { if (b & 1) res = res * a % mod; a = a * a % mod; } return res; } long long int gcd(long long in...
4
#include <bits/stdc++.h> using namespace std; int main() { int n, m, count = 0, i, j; string s, t = ""; getline(cin, s); for (i = 0; i < s.size(); i++) { if (s[i] == '}' || s[i] == '{' || s[i] == ',' || s[i] == ' ') continue; else { t += s[i]; } } sort(t.begin(), t.end()); for (i =...
0
#include <bits/stdc++.h> using namespace std; using namespace std; const int mod = (int)1e9 + 7; const int N = 100005; class Point { public: double x, y; Point(double x, double y) : x(x), y(y) {} Point operator-(const Point& b) { return Point(x - b.x, y - b.y); } Point operator+(const Point& b) { return Point(...
15
#include <bits/stdc++.h> using namespace std; const int inf = 1e9; int n, a[100100], b[100100]; long long h[100100], tr[800100]; int c[100100]; vector<int> G; bool cmp(const int &o, const int &p) { if (b[o] == b[p]) { return a[o] > a[p]; } return b[o] > b[p]; } long long Q(int o, int L, int R, int l, int r) {...
12
#include <bits/stdc++.h> using namespace std; int main(void) { char t[4][4]; for (int i = 0; i < 4; i++) for (int j = 0; j < 4; j++) cin >> t[i][j]; for (int i = 0; i < 3; i++) for (int j = 0; j < 3; j++) { int w = 0, b = 0; for (int l = 0; l < 2; l++) for (int k = 0; k < 2; k++) ...
3
#include <bits/stdc++.h> int n, m; double fun(int x, int y) { double ans = 1, temp = 1.0 * x / y; int t = m; while (t > 0) { if (t & 1) ans *= temp; temp = temp * temp; t >>= 1; } return ans; } int main() { while (scanf("%d%d", &n, &m) != EOF) { double ans = 0, temp = 0; for (int i = 1; ...
8
#include <bits/stdc++.h> using namespace std; void fast() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); } void in(long long int *a, long long int n) { for (long long int i = 0; i < n; i++) { cin >> a[i]; } } void out(long long int *a, long long int n) { for (long long int i = 0; i <...
5
#include <bits/stdc++.h> using namespace std; string c[2005]; bool p[2005][2005], q[2005][2005], l[2005][2005], r[2005][2005]; int main() { long long ans = 0; int n, m, i, j; scanf("%d%d", &n, &m); for (i = 0; i < n; i++) cin >> c[i]; for (i = 0; i < n; i++) { for (j = 0; j < m; j++) { p[i][j] = (i ...
15
#include <bits/stdc++.h> using namespace std; const int N = 1005; int n, p[N], idx, vis[N], ty; char s[N][N]; int main() { cin >> n; for (int i = (1); i <= (n); i++) for (int j = (1); j <= (n); j++) s[i][j] = '.'; for (int i = (1); i <= (n); i++) scanf("%d", &p[i]); for (int i = (1); i <= (n); i++) if (...
22
#include <bits/stdc++.h> using namespace std; const long long INF = 1e18; const int mod = 1e9 + 7; const int N = 1e5 + 10; inline int add(int x, int y) { x += y; if (x >= mod) x -= mod; return x; } inline int mul(int x, int y) { x = (1LL * x * y) % mod; return x; } long long n, h; long long binary_search(long...
13
#include <bits/stdc++.h> using namespace std; #define MOD 1000000007 int main(){ #ifndef ONLINE_JUDGE freopen("input.txt","r",stdin); freopen("output.txt","w",stdout); #endif ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long t=1; cin>>t; while(t--){ long long p,a,b,c; cin>>p>>a>>b>>c; long l...
0
#include <bits/stdc++.h> using namespace std; long long int a, b, c, d, e, f, g, low[800009], high[800009], sum[800009], leaf[200009], x[200009]; void Inp() { memset(x, 0, sizeof(x)); for (int i = 1; i <= a; i++) { cin >> d >> e; x[d]++; x[e + 1]--; } x[0] = 0; for (int i = 1; i <= 200008; i++...
6
#include <bits/stdc++.h> using namespace std; void ritikio(); const long long int inff = LLONG_MAX; const long long int minff = LLONG_MIN; const long long int inf = 1e18; const long long int pmod = 998244353; const long long int mod = 1e9 + 7; const long long int maxm = 2e6 + 3; const long long int maxN = 1e5 + 3; long...
6
#include <bits/stdc++.h> using namespace std; const long long INF = 1e18; const long long SIZE = 1e5 + 5; const long long mod = 1e9 + 7; vector<pair<long long, long long> > adj[SIZE]; vector<long long> dis(SIZE, INF); long long par[SIZE]; bool marked[SIZE]; long long ans; void dijkstra() { dis[1] = 0; priority_queu...
10
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); ; int n; cin >> n; char ch; int idx; cin >> ch >> idx; int loc = 0, roc = 0; map<int, int> dfc; map<int, char> where; dfc[idx] = 0; for (int i = 1; i < n; i++) { cin >> c...
6
#include <bits/stdc++.h> using namespace std; long long i, n, m, k, d[100002]; int main() { cin >> n >> m >> k; for (i = 0; i < n; i++) { cin >> d[i]; cout << d[i] * m % k / m << " "; } return 0; }
7
#include <bits/stdc++.h> using namespace std; void scanint(int &x) { register int c = getchar(); x = 0; for (; (c < 48 || c > 57); c = getchar()) ; for (; c > 47 && c < 58; c = getchar()) { x = (x << 1) + (x << 3) + c - 48; } } int modpow(int a, int b) { int x = 1ll, y = a; while (b) { if (b %...
6
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> V; int x, pr; for (int i = 0; i < n; i++) { pr = 1; for (int j = 0; j < n; j++) { cin >> x; if ((j != i) && ((x == 1) || (x == 3))) { pr = 0; } } if (pr == 1) { V.push_back(i...
1
#include <bits/stdc++.h> #pragma GCC optimize("O3") using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t; cin >> t; for (int q = 0; q < t; ++q) { long long s, n, k; cin >> s >> n >> k; if (s == k) { cout << "YES" << endl; continue; } ...
16
#include <bits/stdc++.h> #define int long long #define ll long long #define endl '\n' #define mod 1000000007 #define pb push_back #define fi first #define se second #define all(v) (v).begin(), (v).end() #define ii pair<int, int> #define vi vector<int> #define vii vector<ii> #define rep(i, l, r) for (int i = (int)(l); ...
8
#include <bits/stdc++.h> using namespace std; int main(void) { long long n, m; long long x; int res = 0; cin >> n >> m >> x; n -= 2 * (x - 1); m -= 2 * (x - 1); if (n <= 0 || m <= 0) { cout << 0; return 0; } if (n == 1) res = m / 2 + (m & 0x01); if (m == 1) res = n / 2 + (n & 0x01); el...
8
#include <bits/stdc++.h> using namespace std; const int maxn(1e6 + 5); const int mod(1e9 + 7); inline void Inc(int &x, int y) { x = x + y >= mod ? x + y - mod : x + y; } inline int Add(int x, int y) { return x + y >= mod ? x + y - mod : x + y; } inline void Dec(int &x, int y) { x = x - y < 0 ? x - y + mod : x - y; } in...
19
#include <bits/stdc++.h> using ll = long long; const int C = 5001, M = 998244353; inline ll pow(ll a, ll b, ll M) { if (b == 0) return 1; ll c = 1; while (b > 0) { if (b % 2 == 1) c = (c * a) % M; b /= 2; a = (a * a) % M; } return c; } ll fac[C], af[C], inv[C], pw[C]; void formulate_fac(int n) { ...
18
#include <bits/stdc++.h> using namespace std; const long long INF = 1e9 + 1; const int N = 2e6; int main() { map<int, int> m; int a, b; int n; cin >> n; while (n--) { cin >> a >> b; m[a] = b; } for (auto &it : m) { int x = it.first + it.second; if (!m.count(x)) continue; auto it1 = m.f...
2
#include <bits/stdc++.h> using namespace std; const int mod = 1000000007; const int inf = numeric_limits<int>::max(); const int N = 21; int memo[1 << 21], cost[21][21]; bool vis[1 << 21]; int cost0[1 << 21], cnt[1 << 21], m; int dp(int mask) { int n = __builtin_popcount(mask); if (n == m) return 0; if (vis[mask])...
14
#include <bits/stdc++.h> using namespace std; const int INF = 1e9; const int N = 305; int c[N][N], first[N][N], cost[N][N], cnt[30], second, t, n; string need; int par[N], d[N]; bool use[N]; queue<int> q; bool FBellman(int x, int y) { for (int i = 0; i <= t; ++i) d[i] = INF; q.push(x); d[x] = 0; while (!q.empty...
12
#include <bits/stdc++.h> int main(void) { int i = 0; int n = 0; char line[256] = {0}; int ans = 0; int one = 0; scanf("%d", &n); getchar(); fgets(line, 256, stdin); for (i = 0; i < n; ++i) { if (' ' == line[i]) { if (one > ans) ans = one; one = 0; } else if (line[i] >= 'A' && line[...
0
#include <bits/stdc++.h> using namespace std; vector<int> g[100010]; bitset<100010> coler; long long ans; const int mod = 1e9 + 7; long long d[100010][2]; void dfs(int x, int p) { for (int i = 0; i < g[x].size(); i++) { if (g[x][i] != p) dfs(g[x][i], x); } d[x][coler.test(x)] = 1; for (int i = 0; i < g[x].s...
12
#include <bits/stdc++.h> using namespace std; template <class P, class Q> inline void smin(P &a, Q b) { if (b < a) a = b; } template <class P, class Q> inline void smax(P &a, Q b) { if (a < b) a = b; } const int maxn = 100000 + 100; int n, OL, OW; vector<pair<int, int> > adj[maxn]; bool mark[maxn]; int sub_size[max...
19
#include <bits/stdc++.h> using namespace std; int main() { vector<string> nor = {"great", "cool", "don't think so", "not bad", "don't touch me", "no"}; for (int i = 0; i < 10; i++) { cout << i << endl; cout << flush; string s; getline(cin, s); if (s == "no") c...
11
#include <bits/stdc++.h> using namespace std; int ans[200000], n, k; void f(vector<int> v, int l, int r, int &k) { if (k == 0 || l + 1 == r || k == 1) { for (int i = 0; i < v.size(); ++i) ans[i + l] = v[i]; return; } vector<int> R, L; int mid = (l + r) / 2; int pos = 0; for (int i = mid; i < r; ++i)...
10
#include <bits/stdc++.h> using namespace std; const long long MOD = 1e9 + 7; int target; int best = 10; int op1[15], op2[15], op3[15], bop1[15], bop2[15], bop3[15]; int reg[15]; int N; void dfs(int lv) { if (lv >= best) return; int i, j, k; for (i = 0; i < N; i++) if (lv < best && reg[i] == target) { be...
17
#include <bits/stdc++.h> using namespace std; int w; int sum = 0; int value = 0; vector<int> nums; vector<int> ans; struct Saver { int index; int save; Saver(int i) : index(i) { ans.push_back(index); save = ::value; } ~Saver() { ans.push_back(index); ::value = save + 1; --nums[index]; } ...
16
#include <bits/stdc++.h> using namespace std; struct Candy { Candy() = default; Candy(int from, int to) : m_from(from), m_to(to) {} int m_from; int m_to; }; int Distance(const Candy &candy, int n) { const int d = candy.m_to - candy.m_from; return d < 0 ? d + n : d; } int Solve(int n, int start, const vector...
9
#include <bits/stdc++.h> using namespace std; long n, m, c, q, u, v, par[100005]; char type; set<long> s[100005]; map<long, long> color[100005]; long find(int i) { if (par[i] == i) { return i; } else { return par[i] = find(par[i]); } } void uni(int u, int v) { long par_u = find(u), par_v = find(v); if...
16
#include <bits/stdc++.h> using namespace std; template <typename T> inline void read(T &x) { char ch = getchar(); bool flag = false; x = 0; while (!isdigit(ch)) flag |= (ch == '-'), ch = getchar(); while (isdigit(ch)) x = x * 10 + ch - '0', ch = getchar(); if (flag) x = -x; } const int inf = 0x3f3f3f3f; con...
15
#include <bits/stdc++.h> using namespace std; long long int a[102]; int main() { long long int n, i, j, sum, temp_sum; while (cin >> n) { for (i = 0; i < n; ++i) { cin >> a[i]; } sum = 100000000; for (i = 1; i <= n; ++i) { temp_sum = 0; for (j = 1; j <= n; ++j) { temp_sum =...
2
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const double eps = 1e-9; int sg[100001], mex[100001], _xor[100001]; int main() { int n; while (cin >> n) { for (int i = 1; i <= n; ++i) { for (int k = 2;; ++k) { int mul = k * (k - 1) / 2; if (mul >= i) break; ...
12
#include <bits/stdc++.h> using namespace std; const int maxn = 100004; int n; int pre[maxn], countx[maxn] = {0}; bool a[maxn], vis[maxn]; int main() { scanf("%d", &n); for (int i = 1; i <= n; i++) { int t; scanf("%d", &t); a[i] = t; } for (int i = 1; i <= n; i++) { scanf("%d", &pre[i]); coun...
7