solution
stringlengths
53
181k
difficulty
int64
0
13
#include <bits/stdc++.h> using namespace std; template <class T> inline void CLR(T& A) { A.clear(); } inline bool insize(int c, int l, int r) { if (c >= l && c <= r) return true; return false; } template <class T> inline void checkmin(T& a, T b) { if (a == -1 || a > b) a = b; } template <class T> inline void ch...
6
#include <bits/stdc++.h> using namespace std; vector<vector<pair<int, int> > > divs(100006); vector<vector<int> > ans(100006); int dp[100006]; int rec(int n) { int &ret = dp[n]; if (ret != -1) return ret; if (divs[n].size() == 0) return ret = 0; int i, g = 0, st, nd; set<int> G; G.clear(); for (i = 0; i <...
6
#include <bits/stdc++.h> using namespace std; const int N=2e3+7; int n,k,A,B,x[N],y[N],f[N],g[N],xf[N<<1],yf[N<<1]; bool fl[N]; double F[N]; inline bool cmp(int a,int b){ return atan2(y[a]-B,x[a]-A)<atan2(y[b]-B,x[b]-A); } inline bool check(int a,int b){ memset(fl,0,sizeof(fl)); while(!fl[a]) fl[a]=1,a=f[a]; if(!fl...
11
#include <bits/stdc++.h> using namespace std; void cnt_pref(vector<int> &a) { for (int i = 1; i < a.size(); ++i) a[i] = a[i - 1] + a[i]; } void solve(void) { int n, m; cin >> n >> m; string s; cin >> s; vector<string> tp = {"abc", "acb", "bac", "bca", "cab", "cba"}; vector<int> nota0(n + 1, 0), nota1(n + ...
4
#include <bits/stdc++.h> using namespace std; int main() { int v1, v2, t, d, ans = 0, temp; cin >> v1 >> v2 >> t >> d; if (v1 > v2) swap(v1, v2); ans = v1; temp = v1; if (d == 0) { ans = v2 * t; } else for (int i = 2; i <= t; i++) { for (int j = d; j >= -d; j--) { if ((abs(temp + j -...
3
#include <bits/stdc++.h> using namespace std; const int N = 113; int go[N][26], dp[N][N][N]; struct Triple { int first, second, third; }; Triple anc[N][N][N]; vector<int> prf(string s) { int n = s.size(); vector<int> ans(n); for (int i = 1; i < n; i++) { int t = ans[i - 1]; while (t > 0 && s[t] != s[i])...
6
#include <bits/stdc++.h> using namespace std; int a[105]; int main() { int n; cin >> n; string s; cin >> s; string ans = "z"; for (int i = 0; i < s.length(); i++) { string a = "", b = ""; for (int j = 0; j < i; j++) { int x = ((s[j] - s[i]) + 10) % 10; b += (char)(x + '0'); } for...
3
#include <bits/stdc++.h> using namespace std; const int INF = 1000000000 + 7; const long long LL_INF = 1ll * INF * INF; const int MAX_N = 300000 + 7; template <typename T> inline void addmod(T& a, const long long& b, const int& MOD = INF) { a = (a + b) % MOD; if (a < 0) a += MOD; } int n; int a[MAX_N]; int sum[MAX_...
6
#include <bits/stdc++.h> using namespace std; bool bit(int n, int k) { return ((1 << k) & n) != 0; } int main() { int n, m; cin >> n >> m; int mmax = 0; if (m * n <= 16) { for (int k = 0; k < 1 << (m * n); ++k) { bool ok = true; for (int i1 = 0; i1 < n; ++i1) for (int j1 = 0; j1 < m; ++j...
5
#include <bits/stdc++.h> const int N = (int)1e5; int arr[2][N]; int main() { std::ios_base::sync_with_stdio(false); std::cin.tie(0); int n, q, bad = 0; std::cin >> n >> q; while (q--) { int x, y; std::cin >> x >> y; --x, --y; arr[x][y] ^= 1; for (int j = std::max(0, y - 1); j <= std::min(n...
3
#include <bits/stdc++.h> template <typename T> T gcd(T a, T b) { if (!b) return a; return gcd(b, a % b); } template <typename T> T lcm(T a, T b) { return a * b / gcd(a, b); } template <typename T> void chmin(T& a, T b) { a = (a > b) ? b : a; } template <typename T> void chmax(T& a, T b) { a = (a < b) ? b : a;...
5
#include <bits/stdc++.h> using namespace std; const int DP_HI = 10000; long long a[9], w, w0; bool dp[DP_HI]; bool dodaj(int x) { bool nesto = 0; for (int i = DP_HI - 1; i >= x; i--) { if (dp[i - x] && !dp[i]) nesto = dp[i] = 1; } return nesto; } int main() { ios_base::sync_with_stdio(false); cin.tie(nu...
7
#include <bits/stdc++.h> using namespace std; const long long int mod = 1e9 + 7; const long long int cmod = 998244353; const long long int N = 2e5 + 10; const long long int inf = 1e16 + 2; vector<vector<pair<long long int, long long int>>> store; long long int sz; long long int cal(pair<long long int, long long int> a,...
6
#include <bits/stdc++.h> using namespace std; long long n, m, k, x, n1 = 1, m1 = 1; char ch; struct item { long long len, pr, su, mx; } a[777777], b[777777]; void upd1(long long pos) { a[pos].su = 0; pos /= 2; while (pos) { a[pos].pr = a[pos * 2].pr; if (a[pos].pr == a[pos * 2].len && a[pos * 2].su > 0)...
3
#include <bits/stdc++.h> using namespace std; long long n, a, b; bool check(long long x) { long long l = 0, r = 1000000; while (l != r) { long long m = (l + r + 1) / 2; if (m * m * m > x) { r = m - 1; } else { l = m; } } bool ok = (l * l * l == a * b); return (ok && !(a % l) && !(b...
4
#include <bits/stdc++.h> using namespace std; unordered_map<string, vector<vector<int>>> mp; unordered_map<string, int> tp, tk; vector<int> v; int main() { int n; stringstream ss; string s, t, u; tp["int"] = 1; tp["double"] = 2; tp["string"] = 3; tp["T"] = -1; cin >> n; getchar(); for (int i = 0; i ...
5
#include <bits/stdc++.h> using namespace std; int a[200001]; int n; double f(double x) { double sum = 0, min_sum = 0, max_sum = 0, res = -1e18; for (int i = 1; i <= n; i++) { sum += a[i] - x; res = max(res, fabs(sum - min_sum)); res = max(res, fabs(sum - max_sum)); min_sum = min(min_sum, sum); m...
6
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<pair<int, int>> vec; for (int i = 0; i < n; i++) { int a, b; cin >> a >> b; if (a > b) swap(a, b); vec.push_back({a, b}); } vector<int> sum; sort(vec.begin(), vec.end()); int a = vec[0].first, b = vec[0].s...
5
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { long long int n, i, j, ans; cin >> n; long long int l[n]; long long int r[n]; for (i = 0; i < n; i++) { cin >> l[i] >> r[i]; } long long int lans = *max_element(l, l + n); long long int ...
1
#include <bits/stdc++.h> using namespace std; int main() { long long n, k; int p; cin >> n >> k >> p; for (int ctr1 = 0; ctr1 < p; ctr1++) { bool ok = false; long long t; cin >> t; if (k == 0) cout << "."; else if (k == n) cout << "X"; else if (t == n) cout << "X"; ...
5
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> a(n); for (int i = 0; i < n; i++) { cin >> a[i]; a[i] += i; } sort(begin(a), end(a)); for (int i = 0; i < n - 1; i++) { if (a[i] + 1 > a[i + 1]) { cout << ":(" << endl; return 0; } } for...
7
#include <bits/stdc++.h> using namespace std; bool prime[100005]; void sieve() { memset(prime, true, sizeof(prime)); for (long long p = 2; p * p < 100005; p++) { if (prime[p] == true) { for (long long i = p * p; i < 100005; i += p) prime[i] = false; } } } long long powmod(long long x, long long y, l...
5
#include <bits/stdc++.h> using namespace std; void vin(vector<int>& v) { int i, p; int n = (int)v.size(); for (i = 0; i < n; i++) { scanf("%d", &v[i]); } } void vin(vector<long long>& v) { long long i, p; int n = v.size(); for (i = 0; i < n; i++) { scanf("%lld", &v[i]); } } void vout(const vecto...
1
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:65536000") using namespace std; const double eps = 1e-8; void solve() { string s, t, p; cin >> s >> t >> p; int t_pos = 0; vector<int> a(26); for (int i = 0; i < (int)(s.size()); ++i) { while (t_pos < t.size() && s[i] != t[t_pos]) a[t[t_pos] - 'a']+...
2
#include <bits/stdc++.h> using namespace std; int A[10003]; int N, M; vector<int> t[100000]; int found; vector<int> init(int l, int r, int node) { if (l == r) return t[node] = vector<int>({A[l]}); int mid = (l + r) / 2; vector<int> L = init(l, mid, 2 * node); vector<int> R = init(mid + 1, r, 2 * node + 1); ve...
2
#include <bits/stdc++.h> using namespace std; int t; long long l, r; void solve() { long long a = 2 * l; if (a <= 2 * (r - l)) { cout << "NO" << '\n'; return; } cout << "YES" << '\n'; } int main() { cin >> t; for (int i = 1; i <= t; i++) { cin >> l >> r; solve(); } return 0; }
0
#include <bits/stdc++.h> using namespace std; const int fx[4][2] = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}}; const int fxx[8][2] = {{0, 1}, {1, 1}, {1, 0}, {1, -1}, {0, -1}, {-1, -1}, {-1, 0}, {-1, 1}}; struct debugger { template <typename T> debugger& operator,(const T& v) { cerr << v << "...
3
#include <bits/stdc++.h> using namespace std; int main() { int T; scanf("%d", &T); while (T--) { long long n; scanf("%lld", &n); int turn = 0; long long me = 0; while (n > 0) { if (n & 1) { --n; if (!turn) me++; } else { if (n == 4 || ((n / 2) & 1)) { ...
3
#include <bits/stdc++.h> using namespace std; int n; map<int, int> dp, prime; int get_mask(int mask, int sh) { int nm = 0; for (int i = 1; i <= 30; ++i) { if (mask & (1 << i)) { if (i < sh) nm |= (1 << i); if (i > sh) nm |= (1 << (i - sh)); } } return nm; } int fn(int mask) { if (mask == 0...
7
#include <bits/stdc++.h> using namespace std; int main() { string st; getline(cin, st); string s = ""; bool b = false; for (int i = 0; i < (int)st.size(); i++) { if (st[i] == '\"') b = !b; else if (b == false && st[i] == ' ') { if (!s.empty() || (i > 0 && st[i - 1] == '\"')) { cout...
2
#include <bits/stdc++.h> using namespace std; const int MAXN = 3003; const long long INF = (1LL << 60LL); int n; pair<int, int> a[MAXN]; long long dp[MAXN][MAXN]; int main() { cin.sync_with_stdio(0); cin >> n; for (int i = 1; i <= n; i++) cin >> a[i].first >> a[i].second; sort(a + 1, a + n + 1); dp[1][1] = a[...
5
#include <bits/stdc++.h> using namespace std; int main() { int n, nr0 = 0, nr1 = 0, i; char a[200005]; cin >> n; cin >> a; for (i = 0; i < n; i++) { if (a[i] == '0') nr0++; if (a[i] == '1') nr1++; } if (nr0 == nr1) cout << 0 << " "; else if (nr0 < nr1) cout << n - 2 * nr0; else cou...
0
#include <bits/stdc++.h> using namespace std; inline int read() { int s = 0, f = 1; char c = getchar(); while (c < '0' || c > '9') { if (c == '-') f = 0; c = getchar(); } while (c >= '0' && c <= '9') s = (s << 1) + (s << 3) + (c ^ 48), c = getchar(); return f ? s : -s; } const int N = 2e7 + 10; ...
10
#include <bits/stdc++.h> using namespace std; int main() { int n; string number; int c = 0; scanf("%d", &n); cin >> number; for (int i = 0; i < number.size(); i++) { if (number[i] == '8') ++c; } printf("%d\n", min(c, (n / 11))); return 0; }
0
#include <bits/stdc++.h> using namespace std; const int inf = (int)1e9; const int mod = inf + 7; const double pi = acos(-1.0); const double eps = 1e-9; struct ppc { long long l, res, r; ppc() { l = -(1ll << 50); res = -(1ll << 50); r = -(1ll << 50); } } t[4 * 200100], p1; long long d[4 * 200100], h[4 ...
7
#include <bits/stdc++.h> using namespace std; int main() { int c1, c2, c3, c4, n, m, i, x, y; scanf("%d", &c1); scanf("%d", &c2); scanf("%d", &c3); scanf("%d", &c4); scanf("%d", &n); scanf("%d", &m); int b1[n + 1]; int s1[m + 1]; for (i = 1; i <= n; i++) scanf("%d", &b1[i]); for (i = 1; i <= m; i+...
1
#include <bits/stdc++.h> using namespace std; template <class T> bool umin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } template <class T> bool umax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } map<pair<int, int>, bool> mark; int vis[200009]; bool check(vector<int>& t...
7
//W4P3R /* ---------------------------------------------------------------------------------------------------------- ---------------------------------------------------------------------------------------------------------- -----------------------------------------------------------------------------------------------...
7
#include <bits/stdc++.h> using namespace std; template <class Read> void in(Read &x) { x = 0; int f = 0; char ch = getchar(); while (ch < '0' || ch > '9') { f |= (ch == '-'); ch = getchar(); } while (ch >= '0' && ch <= '9') { x = (x << 1) + (x << 3) + (ch ^ 48); ch = getchar(); } x = f ?...
7
#include <bits/stdc++.h> const int inf = 0x3f3f3f3f; const double eps = 1e-8; const double pi = acos(-1.0); using namespace std; int main() { int a, b; scanf("%d %d", &a, &b); printf("%d\n", ((a - 1) * (6) + 5) * b); for (int i = 0; i < a; ++i) { printf("%d %d %d %d\n", (6 * i + 1) * b, (6 * i + 2) * b, (6 ...
5
#include <bits/stdc++.h> using namespace std; int main() { long long int a, w1 = 0, w2 = 0, l; string s; cin >> s; l = s.length(); for (int i = 0; i < l; ++i) { if (s[i] == '^') { a = i; break; } } for (int i = 0; i < l; ++i) { if (isdigit(s[i])) { if (i > a) { w1 += ...
0
#include <bits/stdc++.h> using namespace std; int main() { long long int x, i, s = 0, k = 0; cin >> x; long long n[x]; for (i = 0; i < x; i++) { cin >> n[i]; s = s + n[i] * k; k = k + 4; } cout << s << endl; }
1
#include <bits/stdc++.h> using namespace std; long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); } const int STALPH = 26; struct STNode { char *s; int len; int childs[STALPH]; int suffix; STNode(char *s, int len) : s(s), len(len) { memset(childs, -1, sizeof(childs)); suffix =...
13
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout << fixed; cout << setprecision(10); int n; cin >> n; double angle[n]; for (int i = 0; i < n; i++) { int x, y; cin >> x >> y; angle[i] = atan2(y, x) * 180 / 3.14159265359; } so...
5
#include <bits/stdc++.h> long long mullog(long long a, long long b, long long c) { long long ret = 0ll; while (b) { if (b & 1ll) ret = (ret + a) % c; a = (a + a) % c; b >>= (1ll); } return ret; } long long powlog(long long a, long long b, long long c) { long long ret = 1ll; while (b) { if (b...
7
#include <bits/stdc++.h> using namespace std; long long prime[22] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53}; int n; long long ans; void dfs(int pos, long long tmp, long long num) { if (num > n) return; if (num == n && ans > tmp) { ans = tmp; return; } for ...
6
#include <bits/stdc++.h> using namespace std; int al, br, bl, ar; inline void read() { cin >> al >> ar; cin >> bl >> br; } inline int check(int a, int b) { int maxx = (a + 1) << 1; int minn = a - 1; return (b >= minn && b <= maxx); } int main() { read(); int ret = 0; ret |= check(al, br); ret |= check...
2
#include <bits/stdc++.h> using namespace std; int main() { int y; cin >> y; int Y = y; while (true) { set<int> s; Y = Y + 1; int y = Y; int a = y % 10; y = y / 10; s.insert(a); int b = y % 10; y = y / 10; s.insert(b); int c = y % 10; y = y / 10; s.insert(c); i...
0
#include <bits/stdc++.h> using namespace std; int main() { long long t, n, k, d, i, l, j, min; cin >> t; while (t--) { cin >> n >> k >> d; min = 10000000; long long a[n]; for (i = 0; i < n; i++) { cin >> a[i]; } for (i = 0; i <= n - d; i++) { set<long long> s; for (j = i;...
1
#include <bits/stdc++.h> using namespace std; int n, a[1001], k; int main() { scanf("%d%d", &n, &k); n = 2 * n + 1; for (int i = 1; i <= n; ++i) scanf("%d", &a[i]); for (int i = 2; i < n; i += 2) if (k && a[i - 1] + 1 < a[i] && a[i] > a[i + 1] + 1) { a[i]--; k--; } for (int i = 1; i <= n; ...
1
#include <bits/stdc++.h> using namespace std; int a[100], k; long long dp[100000][100]; long long f(long long x, int i) { if (i == -1) return x; long long cnt = x; if (x < 100000 && dp[x][i] != -1) { return dp[x][i]; } for (int k = 0; k <= i && a[k] <= x; k++) cnt -= f(x / a[k], k - 1); if (x < 100000) ...
9
#include <bits/stdc++.h> using namespace std; const int maxn = 8e5 + 50; int n, q; char s[200005]; struct node { int d, m1, m2, m3, m4, m5; } a[maxn]; void pushup(int rt) { a[rt].d = a[rt << 1].d + a[rt << 1 | 1].d; a[rt].m1 = max(a[rt << 1].m1, a[rt << 1 | 1].m1 + a[rt << 1].d); a[rt].m2 = max(a[rt << 1].m2, a...
9
#include <bits/stdc++.h> using namespace std; template <class A, class B> ostream& operator<<(ostream& out, const pair<A, B>& p) { return out << "(" << p.first << ", " << p.second << ")"; } template <class A> ostream& operator<<(ostream& out, const vector<A>& v) { out << "["; for (int i = 0; i < int((v).size()); ...
2
#include <bits/stdc++.h> using namespace std; string int2string(int x) { stringstream ss; ss << x; string tmp; ss >> tmp; return tmp; } int string2int(string s) { stringstream ss; ss << s; int x; ss >> x; return x; } long long power(long long a, long long b) { long long res = 1; while (b > 0) { ...
0
#include <bits/stdc++.h> using namespace std; const int N = 2e3 + 3, M = 1e9 + 7, OO = 0x3f3f3f3f; int n, m, x, y, mem[N][N][2]; int freq_dot[N], freq_tag[N]; string grid[N]; string origin[N]; int get_cost(int col, char ch) { grid[0][col] = ch; if (ch == '.' && freq_tag[col] != -1) return freq_tag[col]; if (ch ==...
4
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; int *a = new int[n]; int *b = new int[m]; for (int i = 0; i < n; i++) { cin >> a[i]; } for (int i = 0; i < m; i++) { cin >> b[i]; } int c = 0, index = 0, j; bool flag = false; for (int i = 0; i < m; i++) { ...
0
#include <bits/stdc++.h> using namespace std; struct point { int x, y; }; bool follow_y(const point& a, const point& b) { return a.y < b.y; } bool follow_x(const point& a, const point& b) { return a.x < b.x; } void push(int node, vector<int>& st, vector<int>& lazy) { if (!lazy[node]) return; st[node << 1] += lazy...
7
#include <bits/stdc++.h> using namespace std; int main() { long long int n; cin >> n; long long int A[n]; for (long long int i = 0; i < n; i++) cin >> A[i]; sort(A, A + n); long long int first = 0, sec = 0, three = 0; for (long long int i = 0; i < n; i++) { if (A[i] == A[0]) first++; } for (long l...
3
#include <bits/stdc++.h> using namespace std; const int mx = 2e4 + 5; void solve() { int n; cin >> n; string s; cin >> s; stack<char> st; for (int i = 0; i < n; i++) { if (!st.empty()) { if (st.top() == '(' && s[i] == ')') st.pop(); else st.push(s[i]); } else st.pus...
1
#include<bits/stdc++.h> #define ll long long #define pb push_back #define endl "\n" #define super ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); #define cn cout<<"NO"<<endl; #define cy cout<<"YES"<<endl; using namespace std; int main() { super; int t=1; //cin>>t; while(t--) { ...
0
#include <bits/stdc++.h> using namespace std; const int NMAX = 100000; const int MMAX = 1000000; const int MOD = 1000000007; const int MOD1 = 402653189; const int MOD2 = 1000000009; const int BASE1 = 196613; const int BASE2 = 786433; vector<int> spell[MMAX]; int factorial[MMAX + 1]; int main(void) { cin.tie(0); ios...
5
#include <bits/stdc++.h> using namespace std; int main() { int n, m; scanf("%d%d", &n, &m); long long lo[1502] = {}, hi[1502] = {}, dp[1501]; fill(hi + 1, hi + 1502, -99999999999ll); for (int i = 0; i < n; i++) { long long sum = 0, me = 0; dp[0] = -99999999999ll; for (int j = 1; j <= m; j++) { ...
5
#include <bits/stdc++.h> using namespace std; map<int, int> t[300005]; vector<int> tr[300005]; set<int> s[300005]; vector<pair<int, pair<int, int> > > all; int n, m, a, b, w; void update(int v, int r, int val) { for (; r < (int)tr[v].size(); r = (r | (r + 1))) tr[v][r] = max(tr[v][r], val); } int get(int v, int r...
5
#include <bits/stdc++.h> using namespace std; struct point { double x, y, z; inline bool operator<(const point t) const { return y * t.x - x * t.y > 0; } inline bool operator>(const point t) const { return y * t.x - x * t.y < 0; } inline bool operator==(const point t) const { return y * t.x - x * t.y == 0; } ...
9
#include <bits/stdc++.h> using namespace std; template <class F, class T> T convert(F a, int p = -1) { stringstream ss; if (p >= 0) ss << fixed << setprecision(p); ss << a; T r; ss >> r; return r; } template <class T> void db(T a, int p = -1) { if (p >= 0) cout << fixed << setprecision(p); cout << a << ...
6
#include <bits/stdc++.h> using namespace std; const int MAX = (2e5) + 5; int n, ara[MAX]; void solve() { cin >> n; for (int i = 1; i <= n; i++) cin >> ara[i]; sort(ara + 1, ara + n + 1); reverse(ara + 1, ara + n + 1); int p = 0; for (int i = 1; i <= n; i++) { if (ara[i] >= i) p = i; } cout << p << e...
0
#include <bits/stdc++.h> using namespace std; int n, a[210], ch[210][30], fail[210], cnt; long long g[210], m; char s[210]; queue<int> q; struct zx { long long a[210][210]; zx() { memset(a, -127 / 3, sizeof(a)); } zx operator*(zx b) { zx ret; for (int i = 0; i <= cnt; ++i) for (int j = 0; j <= cnt; ...
8
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:100000000") using namespace std; template <class T> void read(T &x) { char c, mi = 0; while (c = getchar(), c <= 32) ; if (c == '-') mi = 1, x = 0; else if (c < 48 || c > 57) return void(x = c); else x = c - 48; while (c = getchar(), c...
9
#include <bits/stdc++.h> using namespace std; long long i, j, k, n, m, x, y, T, ans, big, cas, num, len; bool flag; stack<char> tt; stack<long long> an; char ss[5005]; char s[5005]; long long calc(long long l, long long r) { long long i, j; while (!tt.empty()) tt.pop(); long long nn = 0; for (i = 0; i < len; i+...
6
#include <bits/stdc++.h> using namespace std; using i64 = long long; using Pii = pair<int, int>; constexpr int MAX = 16; int ch[MAX], adj[MAX]; vector<int> sub[1 << MAX], lca[MAX]; i64 dp[MAX][1 << MAX]; bool Check(int x, int y, int mask) { if ((mask & ch[y]) != ch[y]) return false; if (((mask | (1 << x)) & adj[y])...
9
#include <bits/stdc++.h> using namespace std; pair<int, int> input[1010]; int Set[1010]; int findSet(int x) { if (x == Set[x]) return x; else return Set[x] = findSet(Set[x]); } bool check(int n, int m, int index) { for (int i = 1; i <= n; i++) Set[i] = i; for (int i = 1; i <= m; i++) { if (i != inde...
2
#include <bits/stdc++.h> using namespace std; template <class T> inline T bigmod(T p, T e, T M) { if (e == 0) return 1; if (e % 2 == 0) { long long t = bigmod(p, e / 2, M); return (T)((t * t) % M); } return (T)((long long)bigmod(p, e - 1, M) * (long long)p) % M; } template <class T> inline T gcd(T a, T ...
6
#include <bits/stdc++.h> using namespace std; using ll = long long; int n; int w[200020]; int h[200020]; int h2[200020]; int main() { scanf("%d", &n); for (int i = 0; i < n; i++) { scanf("%d %d", w + i, h + i); h2[i] = h[i]; } sort(&h2[0], &h2[n]); ll w_ = 0; ll h_ = h[0] == h2[n - 1] ? h2[n - 2] : ...
1
#include <bits/stdc++.h> using namespace std; template <class X, class Y> void minimize(X& x, const Y& y) { if (x > y) x = y; } template <class X, class Y> void maximize(X& x, const Y& y) { if (x < y) x = y; } const int MAXN = 160; const int INF = (int)1E9 + 10; int n, k, s; int a[MAXN], f[2][151][5626]; int main()...
7
#include <bits/stdc++.h> using namespace std; int kmp(char needle[10000], char haystack[10000]) { int counter = 0; int m = strlen(needle); vector<int> border(m + 1); border[0] = -1; for (__typeof(m) i = 0; i < m; i++) { border[i + 1] = border[i]; while (border[i + 1] > -1 && needle[border[i + 1]] != n...
4
#include <bits/stdc++.h> using namespace std; template <typename T, typename U> std::istream& operator>>(std::istream& i, pair<T, U>& p) { i >> p.first >> p.second; return i; } template <typename T> std::istream& operator>>(std::istream& i, vector<T>& t) { for (auto& v : t) { i >> v; } return i; } templat...
6
#include <bits/stdc++.h> using namespace std; const int MOD = 1e9 + 7; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); ; int tt; cin >> tt; while (tt--) { int n, k; cin >> n >> k; int ans = k, to_add = k / n; int rem = (n - k % n) % n; if (to_add < rem) { ans += to...
2
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); int n, m; cin >> n >> m; vector<vector<char>> v(n, vector<char>(m, '.')); bool tes = true; for (int i = 0; i < n; i++) { if (i % 2 == 0) { for (int j = 0; j < m; j++) v[i][j] = '#'; } else { ...
0
#include <bits/stdc++.h> int main() { int n, i, j, a[101][101], b[101], p, k = 0, f; scanf("%d", &n); for (i = 1; i <= n; i++) { for (j = 1; j <= n; j++) { scanf("%d", &a[i][j]); } } if (n == 1) { printf("1\n1\n"); } else { for (j = 1; j <= n; j++) { for (i = 1; i <= n; i++) { ...
0
#include <bits/stdc++.h> using namespace std; const long long int INF = 1e18; const int inf = 1e9; const int MOD = 1e9 + 7; const int nax = 1000000 + 10; int n, arr[nax]; int main() { ios::sync_with_stdio(0); string s; cin >> s; string s1 = s; reverse(s1.begin(), s1.end()); cout << s << s1 << "\n"; return...
0
#include <bits/stdc++.h> using namespace std; const int dr[]{-1, -1, 0, 1, 1, 1, 0, -1}; const int dc[]{0, 1, 1, 1, 0, -1, -1, -1}; void run() { ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); } const int sqrtQ = 250; class suffix_array { const static int alpha = 128; int getOrder(int a) const { r...
11
#include <bits/stdc++.h> using namespace std; const int maxn = 200010, inf = 1e9; int n, m, a[maxn], b[maxn], minn[maxn << 2][2], tag[maxn << 2][2]; void pushup(int o) { minn[o][0] = min(minn[o * 2][0], minn[o * 2 + 1][0]); minn[o][1] = min(minn[o * 2][1], minn[o * 2 + 1][1]); } void pushdown(int o) { for (int i ...
9
#include <bits/stdc++.h> using namespace std; const int maxn = 200005; struct event { int x, t, p; event(int _x = 0, int _t = 0, int _p = 0) { x = _x; t = _t; p = _p; } bool operator<(const event &a) const { if (a.x != x) return x < a.x; if (a.t != t) return t > a.t; return p < a.p; } ...
7
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 7; string s; void out(int cnt) { if (cnt % 2) cout << '1'; else cout << '0'; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n, k; cin >> n >> s; int cnt = 0; for (int i = 0; i < n; i++) { ...
3
#include <bits/stdc++.h> using namespace std; const long long MOD = 1e9 + 7; const int MAXN = 1e6 + 10; inline long long pow(long long a, long long b) { long long ans = 1; while (b) { if (b & 1) ans = ans * a % MOD; b >>= 1; a = a * a % MOD; } return ans; } long long n, k; long long fact[MAXN], anti...
8
#include <bits/stdc++.h> using namespace std; int n, a[1000000], b[1000000]; int main() { cin >> n; for (int i = 0; i < n; ++i) cin >> a[i]; for (int i = 0; i < n - 1; ++i) b[i] = a[i] + a[i + 1]; b[n - 1] = a[n - 1]; for (int i = 0; i < n; ++i) cout << b[i] << ' '; return 0; }
0
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 7; const int maxm = 2e5 + 7; const int mod = 1e9 + 7; int n; long long a[maxn]; int main() { ios::sync_with_stdio(false); cin.tie(0); cin >> n; long long ans = 0; for (int i = (1); i <= (n); ++i) { cin >> a[i]; if (a[i] < a[i - 1]) a...
3
#include <bits/stdc++.h> using namespace std; long long int gcd(long long int x, long long int y) { if (y > x) { return gcd(y, x); } if (y == 0) { return x; } return gcd(y, x % y); } bool prime(long long int x) { for (long long int i = 2; i <= sqrt(x); i++) { if (x % i == 0) { return 0; ...
0
#include <bits/stdc++.h> using namespace std; const int N = 55; const int MOD = 1000000000 + 7; int dp[N][N][N][N]; int c[N]; long long ceven[N]; long long codd[N]; long long fact[N]; long long inv_fact[N]; long long pow2[N]; long long power(long long s, long long p) { long long base = s; long long val = 1; long ...
8
#include <bits/stdc++.h> using namespace std; long long n, i, j, x; bool yes = true; vector<long long> myv; int main() { cin >> n; for (i = 0; i < n; i++) { yes = true; for (j = 0; j < n; j++) { cin >> x; if (x == 1 || x == 3) yes = false; } if (yes) myv.push_back(i + 1); } cout << m...
0
#include <bits/stdc++.h> using namespace std; char a[1000010]; long long sum[1000010]; int main() { scanf("%s", a); if (strlen(a) < 5) { printf("0\n"); return 0; } for (long long i = 1; i < strlen(a); i++) { if (i > 0 && a[i] == 'v' && a[i - 1] == 'v') { sum[i] = sum[i - 1] + 1; } else { ...
2
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t) { int n; cin >> n; string s; while (n) { if (n % 2 == 1) { s += '7'; n -= 3; } else { s += '1'; n -= 2; } } cout << s << endl; t--; } return 0; }
0
#include <bits/stdc++.h> using namespace std; struct al { int s, a; }; bool cmp1(const al& a, const al& b) { return a.s < b.s; } bool cmp2(const al& a, const al& b) { return a.a < b.a; } int main() { ios::sync_with_stdio(false); cin.tie(0); int n, d; cin >> n >> d; vector<al> t1, t2; for (int i = 0; i < n...
9
#include <bits/stdc++.h> using namespace std; template <class T> ostream& operator<<(ostream& os, const vector<T>& v) { for (T i : v) os << i << ' '; return os; } template <class T> ostream& operator<<(ostream& os, const set<T>& v) { for (T i : v) os << i << ' '; return os; } template <class T, class S> ostream...
4
#include <bits/stdc++.h> using namespace std; inline int read() { int 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(); } return x * f; } int n, q, root[200005];...
6
#include <bits/stdc++.h> using namespace std; int main() { int n, i, j, sum1, sum2, maxx; int a[1010], b[1010]; cin >> n; for (i = 1; i <= n; i++) cin >> a[i]; for (i = 1; i <= n; i++) cin >> b[i]; maxx = -1; for (i = 1; i <= n; i++) { sum1 = a[i]; sum2 = b[i]; maxx = max(maxx, sum1 + sum2); ...
0
#include <bits/stdc++.h> using namespace std; vector<long long> v; long long x, y, z, a, b, c, sum, ans, total, t, cnt, n, m, k, p, kase; string s1, s2; map<long long, long long> mp; set<long long> s; map<long long, long long>::iterator itr1, ptr1; set<long long>::iterator itr, ptr; int main() { ios_base::sync_with_s...
3
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; if (m % n != 0) { cout << "-1" << endl; return 0; } int mul = m / n, total = 0; while (mul != 1) { if (mul % 3 == 0) { mul /= 3; total++; } else if (mul % 3 != 0 && mul % 2 == 0) { mul /= 2;...
1
#include <bits/stdc++.h> using namespace std; long long f[55]; int n; long long k; void solve(int x, long long last) { if (x > n) return; if (f[n - x] >= last) { printf("%d ", x); solve(x + 1, last); } else { printf("%d %d ", x + 1, x); solve(x + 2, last - f[n - x]); } } int main() { scanf("%d...
5
#include<bits/stdc++.h> #pragma GCC optimize(2) using namespace std; typedef long long LL; typedef pair<int,int> pii; typedef pair<LL,LL> pLL; typedef pair<double,double> pdd; const int N=1e6+5; const int M=3e3+5; const int mod=998244353; const int inf=0x3f3f3f3f; #define fi first #define se second #define ls (i<<1) #d...
3