func_code_string
stringlengths
59
71.4k
#include <bits/stdc++.h> using namespace std; int a[111111], b[111111], n, m, k; int main() { while (scanf( %d%d%d , &n, &m, &k) != EOF) { for (int i = 1; i <= n; i++) scanf( %d , &a[i]); for (int i = 1; i <= m; i++) scanf( %d , &b[i]); sort(a + 1, a + 1 + n); sort(b + 1, b + 1 + m); ...
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { string s; cin >> s; if (s.size() % 2) cout << NO n ; else { string word1 = , word2 = ; for (int i = 0; i < s.size() / 2; i++) word1 += s[i]; for (int i =...
#include <bits/stdc++.h> using namespace std; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); const int MOD = 100, MAX = 1e6 + 5; const long long INF = 1e18 + 5; int main() { string s; cin >> s; long long n = (s[1] - 0 ) + (s[3] - 0 ) * 10 + (s[4] - 0 ) * 100 + ...
#include <bits/stdc++.h> using namespace std; const long long M = 1e10; set<long long> s; void bt(long long x) { if (x >= M) return; s.insert(x); bt(x * 10 + 4); bt(x * 10 + 7); } int main() { bt(0); int l, r; cin >> l >> r; long long c = 0; for (set<long long>::iterator ...
#include <bits/stdc++.h> using namespace std; const int MAX = 2e5 + 5; int n; pair<int, int> a[MAX]; struct par { int a, b; par(int a, int b) : a(a), b(b) {} bool operator<(const par &p) const { return b < p.b; } }; multiset<par> s; multiset<int> sizes; int main() { scanf( %d , &n); ...
#include <bits/stdc++.h> using namespace std; int n, h; int main() { cin >> n >> h; for (int i = 1; i < n; i++) { double h1 = h * sqrt(1.0 * i / n); printf( %.12llf , h1); } return 0; }
#include <bits/stdc++.h> using namespace std; template <class T> void dbs(string str, T t) { cerr << str << : << t << n ; } template <class T, class... S> void dbs(string str, T t, S... s) { long long idx = str.find( , ); cerr << str.substr(0, idx) << : << t << , ; dbs(str.substr...
#include <bits/stdc++.h> namespace chtholly { char buf[1 << 23], *p1 = buf, *p2 = buf; inline int read() { int x = 0, f = 1; char c = getchar(); for (; !isdigit(c); c = getchar()) f ^= c == - ; for (; isdigit(c); c = getchar()) x = (x << 3) + (x << 1) + (c ^ 0 ); return f ? x : -x; } tem...
#include <bits/stdc++.h> using namespace std; int main() { int T; cin >> T; while (T--) { long long a, b, c, d; cin >> a >> b >> c >> d; if (c <= d) { if (a <= b * c) cout << a << endl; else { cout << -1 << endl; } } else { long...
#include <bits/stdc++.h> using namespace std; int main() { int n; int flag = 0; scanf( %d , &n); for (int i = 0; i < n; i++) { int num, num1; string str; cin >> str >> num >> num1; if (num >= 2400 && (num1 - num) > 0) { flag = 1; break; } } if (f...
#include <bits/stdc++.h> using namespace std; const int limite = 100005; pair<int, int> maximo[limite]; void inserta(int pos, int val) { pair<int, int> valor(val, pos); for (; pos < limite; pos += pos & -pos) maximo[pos] = max(maximo[pos], valor); } int computamaximo(int pos) { pair<int, int> ma...
#include <bits/stdc++.h> #pragma GCC optimize( O3 ) using namespace std; const long long inf = 1e9; const int MAXM = 1048800; const int MAXN = 1e7 + 1; bool visit[MAXM]; int a[MAXM]; int k; vector<int> v; int main() { int n, i, j, k; cin >> n; n *= 2; for (int i = 0; i < n; i++) { ...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n; cin >> n; vector<pair<string, int>> v; priority_queue<int, vector<int>, greater<int>> pq; for (int i = 0; i < n; ++i) { string s; cin >> s; ...
#include <bits/stdc++.h> using namespace std; vector<int> parent; vector<int> Rank; vector<int> Count; int root(int v) { if (parent[v] == v) return v; return parent[v] = root(parent[v]); } bool DSU(int a, int b) { a = root(a); b = root(b); if (a != b) { if (Rank[b] > Rank[a]) swa...
#include <bits/stdc++.h> struct { inline operator int() { int x; return scanf( %d , &x), x; } inline operator long long() { long long x; return scanf( %lld , &x), x; } template <class T> inline void operator()(T &x) { x = *this; } template <class T, class....
#include <bits/stdc++.h> using namespace std; int n, a[26]; char pal[111111]; inline bool is_pal(int k, int can) { vector<int> odd(0); for (int i = 0; i < n; ++i) { if (a[i] % k) return 0; if (a[i] % (2 * k)) odd.push_back(i); } if ((int)(odd).size() > 1) return 0; if ((int)(odd)...
#include <bits/stdc++.h> using namespace std; int main() { int n, k; scanf( %d %d , &n, &k); char c[200005]; scanf( %s , c); int ok[26]; memset(ok, 0, sizeof(ok)); for (int i = 0; i < k; i++) { char cc; scanf( %c , &cc); ok[cc - a ] = 1; } long long cnt = 0; ...
#include <bits/stdc++.h> using namespace std; string s, t; int l[200005], r[200005]; int dp[30][200005]; void gd() { cout << No ; exit(0); } bool check(int lr, int rl, int c) { return ((lr ? dp[c][lr - 1] : 0) - (rl ? dp[c][rl - 1] : 0) > 0); } int main() { ios_base::sync_with_stdio(0...
#include <bits/stdc++.h> using namespace std; int N, M, K; int color[200002]; vector<int> edge[200002]; int id[200002]; int ite = 1; int siz[200002]; map<int, int> m[200002]; int ans; void dfs(int a) { if (id[a]) { return; } id[a] = ite; for (int i = 0; i < edge[a].size(); i++)...
#include <bits/stdc++.h> using namespace std; template <class A, class B> ostream &operator<<(ostream &out, const pair<A, B> &a) { return out << ( << a.first << , << a.second << ) ; } template <class A> ostream &operator<<(ostream &out, const vector<A> &a) { for (const A &it : a) out << it << ...
#include <bits/stdc++.h> using namespace std; string s; const int MAXN = 100005; int tz[4 * MAXN], tx[4 * MAXN], ty[4 * MAXN]; int cntz(int v, int tl, int tr, int l, int r) { if (l > r) return 0; if (tl == l && r == tr) return tz[v]; int tm = (tl + tr) / 2; return cntz(2 * v, tl, tm, l, min(tm...
#include <bits/stdc++.h> using namespace std; int main() { int n; int m; cin >> n >> m; int c[m], a[n]; int i, j, k; for (i = 0; i < n; i++) { a[i] = 0; } for (i = 0; i < m; i++) { cin >> c[i]; a[c[i] - 1]++; } k = a[0]; for (i = 0; i < n; i++) { i...
#include <bits/stdc++.h> using namespace std; const long long inf = 1e18; const long long mod = 1e9 + 7; const long long N = 222; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); long long n, k; vector<long long> adj[N]; long long dp[N][N], dp2[N][N], a[N]; void input() { cin >...
#include <bits/stdc++.h> using namespace std; struct fenwick { long long n, fen[100005]; void resize(int _n) { n = _n + 1; memset(fen, 0, sizeof fen); } int query(int ind) { ind++; int ans = 0; while (ind >= 1) { ans += fen[ind]; ind -= ind & -ind; ...
#include <bits/stdc++.h> using namespace std; const int MAX_N = 1e6 + 5; int arr[MAX_N]; int vis[MAX_N]; void solve() { int n; scanf( %d , &n); for (int i = 1; i <= n; i++) { scanf( %d , &arr[i]); vis[i] = 0; } vector<int> stk; for (int i = 1; true; i = i - arr[i]) { ...
#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); } int main() { long long n; cin >> n; set<long long> st; for (long long i = 1; i * i <= n; i++) { if (n % i == 0) { long long a = n / gcd(n, i...
#include <bits/stdc++.h> int mat[500][500]; int N, K; int main() { scanf( %d%d , &N, &K); int Cnt = 1; int sum = 0; for (int i = 0; i < N; i++) { for (int j = 0; j < K - 1; j++) { mat[i][j] = Cnt++; } } for (int i = 0; i < N; i++) { for (int j = K - 1; j < N; j++)...
#include <bits/stdc++.h> using namespace std; const int maxn = 100010; bool visited[2][maxn]; int d[2][maxn]; string s[2]; int main() { int n, k; cin >> n >> k; cin >> s[0] >> s[1]; int dx[3] = {0, 0, 1}; int dy[3] = {1, -1, k}; queue<pair<bool, int>> q; q.push(make_pair(0, 0)); ...
#include <bits/stdc++.h> #pragma comment(linker, /STACK:102400000,102400000 ) using namespace std; unordered_set<int> dict; int main() { long long a, b, x; cin >> x >> a >> b; if (a % x != 0) { a += x - (a % x + x) % x; } if (a > b) { cout << 0 << endl; } else { cout <...
#include <bits/stdc++.h> using namespace std; void solve() { int a, b, n; cin >> n >> a >> b; vector<int> A(n); for (int &x : A) cin >> x; sort(A.begin(), A.end()); if (A[b] - A[b - 1] == 0) { cout << 0 n ; return; } cout << A[b] - A[b - 1] << n ; } int main() { ...
#include <bits/stdc++.h> using namespace std; inline int read() { register int x = 0, t = 1; register char ch = getchar(); while ((ch < 0 || ch > 9 ) && ch != - ) ch = getchar(); if (ch == - ) t = -1, ch = getchar(); while (ch <= 9 && ch >= 0 ) x = x * 10 + ch - 48, ch = getchar(); r...
#include <bits/stdc++.h> using namespace std; int main() { int n, x; while (cin >> n) { x = n - 10; if (x <= 0 || x > 11) cout << 0 << endl; else if (x == 10) cout << 15 << endl; else cout << 4 << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; int n, u, r; int a[35]; int b[35]; int k[35]; int p[35]; int op[35]; int tmpa[35]; int tmmmma[35]; long long dfs(int index, const int ta[]) { if (index == u) { long long res = 0; for (int i = (0); i < ((n)); ++i) res += (long long)ta[i] *...
#include <bits/stdc++.h> using namespace std; int main() { long long int n, sx, sy, x, y; cin >> n >> sx >> sy; vector<pair<long long int, long long int> > v; v.push_back({sx, sy + 1}); v.push_back({sx, sy - 1}); v.push_back({sx + 1, sy}); v.push_back({sx - 1, sy}); vector<long long ...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long t; cin >> t; while (t--) { long long sum = 1; long long sum1 = 0; long long sum2 = 0; long long cnt1 = 0; long long cnt2 = 0; long long res = ...
#include <bits/stdc++.h> using namespace std; const long double eps = (long double)1e-9; const long double PI = (long double)acos(-1.0); const int inf = 1e9 + 5; const long long linf = 1e18L + 5; const int mod = 1e9 + 7; void solve() { int n, q, r, c; cin >> n >> q; unordered_set<int> s[3]; ...
#include <bits/stdc++.h> using namespace std; const int N = 260; int m, n, mx[N][10], g[N][26], sl[N], L[N]; char a[N][N]; int kq; unsigned long long o[N], A[N], B[N], pw[N], P[N]; unsigned long long get(int l, int r) { return A[r] - A[l - 1] * pw[r - l + 1]; } unsigned long long Get(int l, int r) { ret...
#include<bits/stdc++.h> using namespace std; //MACROS #define ll long long #define f(i,a,b) for(i=a;i<b;i++) #define MOD 1000000007 #define pb push_back #define mp make_pair #define INF (int)1e9 #define deb(x) cout << > << #x << : << x << endl; #define cjam(t,x) cout << Case # << t << :...
#include <bits/stdc++.h> using namespace std; const long long mod = 1000000007, inf = 1000000000; const int N = 100010; inline int read() { char ch; while (!isdigit(ch = getchar())) ; int x = ch - 0 ; while (isdigit(ch = getchar())) x = (x << 1) + (x << 3) + ch - 0 ; return x; } ...
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; string str; cin >> str; vector<int> arr; for (int i = 0; i < str.size(); i++) { if (str[i] == . ) arr.push_back(i + 1); } for (int i = 0; i + 1 < arr.size(); i++) { if (arr[i] + k < arr[i...
#include <bits/stdc++.h> using namespace std; long long a[200001]; int main() { long long t, m = 0, i, n, k, ans; ; scanf( %lld%lld , &n, &k); for (i = 0; i < n; i++) scanf( %lld , &a[i]); sort(a, a + n); for (i = (n + 1) / 2; i < n; i++) { t = m; m += (a[i] - a[i - 1]) * (i - ...
#include <bits/stdc++.h> using namespace std; int n, a[4000005], t[4000005]; long long ans, now; int k; template <class T> inline T Max(T a, T b) { return a > b ? a : b; } int main() { scanf( %d , &n); for (int i = 1; i <= n; ++i) scanf( %d , a + i); int fu = 0, zh = 0; for (int i = ...
#include <bits/stdc++.h> using namespace std; void dbvar() { cerr << ] << endl; } template <class H, class... T> void dbvar(H h, T... t) { cerr << to_string(h); if (sizeof...(t)) cerr << , ; dbvar(t...); } const int INF = (int)(1e9); const long long int INFL = (long long int)(1e18); cons...
#include <bits/stdc++.h> using namespace std; int main() { int i, j, test, len; string s; cin >> test; while (test--) { cin >> s; len = s.length(); if (s[len - 2] == p && s[len - 1] == o ) { cout << FILIPINO << endl; } else if (s[len - 4] == d && s[len - 3] == ...
#include <bits/stdc++.h> using namespace std; int main() { int n, a, b; cin >> n >> a >> b; string s; cin >> s; for (int cnt1 = 0; cnt1 <= n / a; ++cnt1) { for (int cnt2 = 0; cnt2 <= n / b; ++cnt2) if (a * cnt1 + b * cnt2 == n) { cout << cnt1 + cnt2 << endl; for...
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 10; int n; int a[N]; int main() { cin >> n; for (int i = 0; i < n; i++) { cin >> a[i]; } int ans; for (int i = 30; i >= 0; i--) { int flag = 0; for (int j = 0; j < n; j++) { if ((a[j] >> i) & 1) { ...
#include <bits/stdc++.h> char s[10010]; char s1[10010], s2[10010], s3[10010]; char ans[10010]; int main() { scanf( %s , s + 1); int n = strlen(s + 1); for (int i = 1; i <= n; i++) { int b1 = i / 26 / 26; int b2 = (i / 26) % 26; int b3 = i % 26; s1[i] = b1 + a ; s2[i] =...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> A(n), B(n); vector<int> Ai(n - 1), Bi(n - 1); int t = 0; for (int i = 0; i < n; ++i) { cin >> A[i]; if (A[i] != 0) { Ai[t] = A[i]; t++; } } t = 0; for (int i ...
#include <bits/stdc++.h> using namespace std; const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1}; bool ckmin(int& a, int b) { return b < a ? a = b, true : false; } bool ckmax(int& a, int b) { return b > a ? a = b, true : false; } const long long linf = 4000000000000000000LL; const long long inf = 100000...
#include <bits/stdc++.h> using namespace std; long long n, k; int main() { scanf( %lld %lld , &n, &k); vector<long long> prime; for (int i = 2; i <= n; ++i) { if (!prime.size()) { prime.push_back(i); continue; } bool isPrime = true; for (int j = 0; j < prime.siz...
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 85 - 69; long long int a[maxn], su[maxn], dp[maxn]; int n; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cin >> n; for (int i = 1; i < n; i++) cin >> a[i]; for (int i = n - 1; i > 0; i--) { su[i] = su[i...
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5; int n; struct node { int x, y; } a[N]; int cmp(node a, node b) { return a.x < b.x; } double f[55][55][55], ans; int pd(double ans) { memset(f, 127, sizeof f); f[0][0][0] = 0; for (int i = 1; i <= n; i++) { if (a[i...
#include <bits/stdc++.h> using namespace std; const long long INF64 = 1e18; clock_t time_p = clock(); void time() { time_p = clock() - time_p; cerr << Time Taken : << (float)(time_p) / CLOCKS_PER_SEC << n ; } void doc() { freopen( input.txt , r , stdin); freopen( output.txt , w , stdo...
#include <bits/stdc++.h> using namespace std; int main() { int n = 0, m = 1, i = 0, j = 0, k = 0, x = 0; int area[51][51] = {0}; cin >> n; for (i = 0; i < n; i++) for (x = 0; x < n; x++) cin >> area[i][x]; for (i = 0; i < n; i++) for (x = 0; x < n; x++) if (area[i][x] != 1) {...
#include <bits/stdc++.h> using namespace std; const int MAXN = 205; const long long modulo = 1000000007; struct point { long long x, y; }; point operator-(point A, point B) { point C; C.x = A.x - B.x; C.y = A.y - B.y; return C; } bool operator==(point A, point B) { return (A.x == B.x...
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 50; const int maxm = 1e6 + 50; const double eps = 1e-10; const int max_index = 62; const int inf = 0x3f3f3f3f; const int MOD = 1e9 + 7; inline int read() { char c = getchar(); while (!isdigit(c)) c = getchar(); int x = 0; ...
#include <bits/stdc++.h> using namespace std; const int mod = 1000000007; int add(int a, int b) { a += b; return a >= mod ? a - mod : a; } const int MN = 1000011; int f[MN][2], n; inline void Main() { f[0][0] = f[0][1] = 1; scanf( %d , &n); for (register int i = (1), _c = (n); i <= _c;...
#include <bits/stdc++.h> using namespace std; int n, m, s, ans, tot, tot1, tot2; int siz[200010], du[200010], dep[200010], fa[200010][18]; int q[200010], head[200010], head1[200010], head2[200010], power[18]; bool v[200010]; long long dis[200010]; struct Map { int r, len, next; } line[600010]; str...
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; if (((n * m) % 2 != 0) || (n == 1 && m > 2) || (m == 1 && n > 2)) { cout << 1 << endl; cout << n << << m << 1 1 << endl; for (int i = 1; i <= m; i++) { for (int j = 1; j <= n; j++) { ...
#include <bits/stdc++.h> using namespace std; int pri[200050]; int que[200050]; int ans[200050]; int l[200050]; int r[200050]; int main() { int n; while (scanf( %d , &n) != EOF) { for (int i = 1; i <= n; i++) { scanf( %d , &pri[i]); ans[i] = 0; l[i] = r[i] = 1; ...
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 37; long long int c[1037][1037]; int main() { for (int i = 0; i < 1037; i++) { c[i][0] = 1; for (int j = 1; j < i + 1; j++) { c[i][j] = c[i - 1][j - 1] + c[i - 1][j]; } } int n, k; cin >> n >> k; i...
#include <bits/stdc++.h> using namespace std; template <class T> using lim = numeric_limits<T>; const int maxn = 2e5; int table[maxn * 2 + 2]; int find(int i) { if (table[i] == i) return i; else return table[i] = find(table[i]); } int main() { ios_base::sync_with_stdio(false); ...
#include <bits/stdc++.h> using namespace std; struct trio { int64_t first, second, trd; friend ostream &operator<<(ostream &o, trio &a) { o << ( << a.first << , << a.second << , << a.trd << ) ; return o; } }; template <typename T> inline T max() { return numeric_limits<T>::m...
#include <bits/stdc++.h> using namespace std; const long long mod = 1000000007; long long powmod(long long a, long long b) { long long res = 1; a %= mod; for (; b; b >>= 1) { if (b & 1) res = res * a % mod; a = a * a % mod; } return res; } const int N = 101000; int n, val[N];...
#include <bits/stdc++.h> using namespace std; int n; int x_search(const int &down, const int &up, const int &c) { int l = down, r = up, key = 0; while (l <= r) { int mid = (l + r) / 2, cnt; cout << ? << mid << << 1 << << n << << n << n ; cin >> cnt; if (cnt >= c) {...
#include <bits/stdc++.h> using namespace std; constexpr long long int mod = 1e9 + 7; constexpr long long int MAXN = 1e6 + 3; constexpr long long int inf = 1ll << 32; int main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; vector<int> vx(n + 2); int med = 0; for (int ...
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; int pos[11][1111]; int gra[1111][1111]; int main() { int n, m; cin >> n >> m; int x; for (int i = 0; i < m; i++) { for (int j = 0; j < n; j++) { cin >> x; pos[i][x - 1] = j; } } for (i...
#include <bits/stdc++.h> #pragma GCC optimize( O3 ) using namespace std; using ll = long long; using ii = pair<int, int>; using uint = unsigned int; const int N = 1e5 + 5, MOD = 1e9 + 7; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n; cin >> n; vector<int> deg(n + 1); ...
#include <bits/stdc++.h> using namespace std; int n, x, y; set<pair<int, int> > S, T; int solve(set<pair<int, int> >& s, set<pair<int, int> >& t) { set<pair<int, int> >::iterator it1, it2, it3, it4; it1 = s.begin(); it2 = s.end(); it2--; it3 = t.begin(); it4 = t.end(); it4--; whi...
#include <bits/stdc++.h> using namespace std; int n, sn, i, j, sum, temp, nl; map<int, int> myMap; vector<int> t[105]; int main() { cin >> n; j = 0; sn = n * n; for (i = sn; i > sn / 2; i--) { t[j % n].push_back(i); t[j % n].push_back(sn - i + 1); j++; } for (i = 0; i...
#include <bits/stdc++.h> using namespace std; int Number[12][12]; int Next[110]; double dp[110]; int main() { for (int i = 1; i <= 10; i++) for (int j = 1; j <= 10; j++) Number[i][j] = (10 - i) * 10 + (i % 2 == 0 ? j : 11 - j); for (int i = 1; i <= 10; i++) { for (int j = 1; j <= 1...
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int a, b, c, d; cin >> a >> b >> c >> d; if (a < b) swap(a, b); if (c < d) swap(c, d); cout << ((a == c && b + d == a) ? Yes n : No n ); } }
#include <bits/stdc++.h> int main() { int64_t d1, d2, d3; std::cin >> d1 >> d2 >> d3; int64_t dist = d1 + d2 + d3; dist = std::min(dist, 2 * d1 + 2 * d2); dist = std::min(dist, 2 * d1 + 2 * d3); dist = std::min(dist, 2 * d2 + 2 * d3); std::cout << dist << std::endl; return 0; }
#include <bits/stdc++.h> using namespace std; const int INF = 2e9; long long gcd(long long a, long long b) { while (b) { a %= b; swap(a, b); } return a; } int main() { long long l, r, x, y; cin >> l >> r >> x >> y; long long d = 1; long long res = 0; map<int, int> m...
#include <bits/stdc++.h> using namespace std; const int N = 50010; const int mod = 998244353; int n; const int a[16] = {0, 4, 8, -1, 16, -10, 4, -12, -48, 26, -44, 15, -16, -4, -4, -1}; int f[N] = {0, 0, 0, 24, 4, 240, 204, 1316, 2988, 6720...
#include <bits/stdc++.h> using namespace std; const int maxn = 5e2; pair<pair<int, int>, bool> pr[maxn][maxn][2]; queue<pair<pair<int, int>, bool> > q; vector<int> neighbor[maxn]; void bfs(int s, int t) { for (int i = 0; i < maxn; i++) for (int j = 0; j < maxn; j++) for (int k = 0; k < 2; ...
#include <bits/stdc++.h> using namespace std; long long n, m; pair<long long, long long> seg[500000 + 1]; long long dp[20 + 1][500000 + 1]; signed main() { cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(false); cin >> n >> m; for (long long i = 1; i < n + 1; i++) { long long l, r...
#include <bits/stdc++.h> using namespace std; int param[51][51], n, targ; vector<int> visted(51); stack<int> s; bool dfs(int root) { if (root == targ) { return true; } if (visted[root] == 0) s.push(root); visted[root] = 1; int nxt = -1; for (int i = 1; i <= n; i++) { if (pa...
#include <bits/stdc++.h> using namespace std; long long int MOD = 1e9 + 7; const int N = 1e6 + 5, M = 1e5 + 10, NM1 = N - 1; long long int OO = 1e18 + 8; int oo = 1e9 + 8; void readFile() {} int n, m, l, r, x, top, arr[N], st[N]; long long int sum[N]; int main() { readFile(); scanf( %d , &n); ...
#include <bits/stdc++.h> using namespace std; int main(void) { int n, k; int v[200001]; scanf( %d%d , &n, &k); for (int i = 0; i < n; i++) scanf( %d , v + i); sort(v, v + n); int l = 1; int r = 1000000000; int m; for (int it = 0; l <= r and it < 50; it++) { m = l + (r - l) ...
#include <bits/stdc++.h> const int MAXN = 2e5 + 7; struct Edge { int t, next; } edge[MAXN << 1]; int head[MAXN], cnt; int size[MAXN]; int dfn[MAXN], pos[MAXN], ts = 0; int n, m; int dist[MAXN], deep[MAXN]; int f[MAXN][19]; int t1 = 1, t2 = 1; struct SegmentTree; struct Questions; SegmentTr...
#include <bits/stdc++.h> using namespace std; const int MOD = 998244353; vector<vector<int>> edges; long long DP[200010]; long long fac[200010]; void solve(const int u, const int p) { DP[u] = 1; int tot = 0; for (auto& e : edges[u]) { if (e != p) { tot++; solve(e, u); ...
#include <bits/stdc++.h> long long int lcm, k, ans, a, b; using namespace std; int main() { int n; cin >> n; map<int, int> mp; mp[n] = 1; n++; int c = 1; while (1) { if (mp[n] == 1 && n % 10 != 0) break; else { if (n % 10 == 0) { while (n % 10 == 0...
#include <bits/stdc++.h> using namespace std; const long double pi = acos(-1); const long long md = 1e9 + 7; long long r, b, i, x, y; int main() { ios::sync_with_stdio(0); cin.tie(0); cin >> r >> b; for (i = 1; i <= r + b; i++) cin >> x >> y; cout << (r == b ? Yes : No ) << n ; re...
#include <bits/stdc++.h> using namespace std; int main() { int n, m, kecil, tamp1 = 0, tamp2 = 0, tambah = 0; cin >> n; cin >> m; tamp1 = n; tamp2 = m; while (n != 0) { n = tamp1; if (tambah >= 1) m += tamp2; if (m > n) { cout << -1; return 0; } ...
#include <bits/stdc++.h> using namespace std; void input(long long ara[], long long n) { for (long long i = 0; i < n; i++) cin >> ara[i]; } void output(long long ara[], long long n) { for (long long i = 0; i < n; i++) cout << ara[i] << ; } long long mx1(long long ara[], long long n) { long lo...
#include <bits/stdc++.h> using namespace std; __int128 read() { __int128 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 *...
#include <bits/stdc++.h> using namespace std; const double pi = acos(-1); const double eps = 1e-6; const long long INF = 0x3f3f3f3f3f3f3f3fll; const int inf = 0x3f3f3f3f; const int mod = 998244353; const int maxn = 1e6 + 100; long long qpow(long long a, long long b) { long long ret = 1; a %= mod...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); int n; cin >> n; string s; cin >> s; int depth = 0; for (int i = 0; i < n; i++) { depth += (s[i] == ( ? 1 : -1); } if (depth != 2 && depth != -2) { cout << ...
#include <bits/stdc++.h> using namespace std; const int MOD = int(1e9) + 7; int n; int a[100000], b[100000]; int who[200005]; bool used[200005] = {}; vector<int> g[200005]; int mul; int far[200005]; int tr[200005]; void dfs(int v) { ++mul; used[v] = true; for (int to : g[v]) { df...
#include <bits/stdc++.h> using namespace std; const int MAXN = 2e5 + 40; int num[MAXN]; int a[MAXN]; int pref[MAXN]; bool isneg = false; int n; int max_k; int mabs(int x) { if (x < 0) { return -x; } return x; } void neg() { isneg = !isneg; for (int i = 0; i < MAXN; ++i) {...
#include <bits/stdc++.h> using namespace std; const long long maxn = 2e5 + 8, inf = 1e18 + 9, mod = 1e9 + 7; char s[maxn]; long long n, m; void solve() { long long i, j, ans = 1; cin >> n >> (s + 1); for (i = 2; i <= n; i++) if (s[i] != s[i - 1]) ans++; cout << min(ans + 2, n) << endl; ...
#include <bits/stdc++.h> int main() { int x, y; scanf( %d%d , &x, &y); int i = 1; while (1) { if (y < 2 || ((100 * x) + (10 * y)) < 220) { if (i & 1 == 1) printf( Hanako ); else printf( Ciel ); return 0; } if (i & 1 == 1) { if (x >=...
#include <bits/stdc++.h> using namespace ::std; const long long maxn = 1e5 + 500; const long long mod = 1e9 + 7; const long long inf = 1e9 + 500; long long out[maxn]; long long in[maxn]; long long a[maxn]; long long b[maxn]; long long dp[2][maxn]; int main() { fill(out, out + maxn, -1); fill...
#include <bits/stdc++.h> using namespace std; int main() { int T; cin >> T; while (T--) { long long n, k; cin >> n >> k; long long cur = 1, now = 1, ans = 0; while (now <= k && cur < n) { cur += now; now <<= 1; ans++; } if (cur < n) { a...
#include <bits/stdc++.h> using namespace std; int n, a, b; int check(int p) { int res; res = a / p + b / p; if (a / p == 0 || b / p == 0) return 0; if (res >= n) return 1; else return 0; } int main() { int l, r, mid; scanf( %d%d%d , &n, &a, &b); r = a + b; l = 1...
#include <bits/stdc++.h> using namespace std; struct node { int u; long long int cost; node(int _u, long long int _cost) { u = _u; cost = _cost; } bool operator<(const node& p) const { return (long long int)cost < (long long int)p.cost; } }; int numNodes, numEdges; in...
#include <bits/stdc++.h> using namespace std; int Id[2 * 105]; int L[2 * 105]; int W[2 * 105]; long long int dp[2 * 105][3005]; bool vis[2 * 105][3005]; int n, l; long long int solve(int LastTp, int Len) { if (Len > l) return 0LL; if (Len == l) return 1LL; if (vis[LastTp][Len] == 1) return d...
#include <bits/stdc++.h> using namespace std; long long n; int sum = 1; int main() { cin >> n; for (int i = 1; i < n; i++) sum += i * 12; cout << sum; return 0; }
#include <bits/stdc++.h> using namespace std; int main(int argc, const char* argv[]) { int n, cnt = 0; cin >> n; int a[100]; memset(a, 0, sizeof(a)); for (int i = 0; i < n; i++) { int k, x = 0; cin >> k; while (k != 0) { x = x + k % 10; k = k / 10; } ...