func_code_string
stringlengths
59
71.4k
#include <bits/stdc++.h> using namespace std; long long gcd(long long a, long long b) { if (a < 0) a = -a; if (b < 0) b = -b; return b == 0 ? a : gcd(b, a % b); } template <typename T> void read(T &res) { bool flag = false; char ch; while (!isdigit(ch = getchar())) (ch == - ) && (flag...
#include <bits/stdc++.h> #pragma GCC optimize( O2 ) using namespace std; void __print(int x) { cerr << x; } void __print(long x) { cerr << x; } void __print(long long x) { cerr << x; } void __print(unsigned x) { cerr << x; } void __print(unsigned long x) { cerr << x; } void __print(unsigned long long x)...
#include <bits/stdc++.h> using namespace std; template <typename T> inline int read(T &a) { a = 0; char c = getchar(), f = 1; while (c > 9 || c < 0 ) { if (c == - ) f = (~f) + 1; if (c == -1) return -1; c = getchar(); } while (c <= 9 && c >= 0 ) a = (a << 1) + (a...
#include <bits/stdc++.h> int b[12][12]; int main() { int a; int i, j; int sum; scanf( %d , &a); memset(b, 0, sizeof(b)); for (i = 1; i <= 10; i++) for (j = 1; j <= 10; j++) { b[1][j] = b[i][1] = 1; b[i][j] = b[i - 1][j] + b[i][j - 1]; } printf( %d , b[a][a]); ...
#include <bits/stdc++.h> using namespace std; int n, Cnt = 0, Num = 0; int l[200000 + 10], r[200000 + 10]; map<int, int> mp; int Di[200000 + 10]; vector<int> f[200000 + 10], No[200000 + 10]; int cur[200000 + 10]; bool b[200000 + 10]; int Ans[200000 + 10]; int Check() { int Now = -1, ODD = 0; ...
#include <bits/stdc++.h> using namespace std; int n, k, a[100005]; int main() { ios_base::sync_with_stdio(0); cin.tie(); cout.tie(); cin >> n >> k; if (k < n / 2 || (n == 1 && k)) { cout << -1; return 0; } if (n == 1 && k == 0) { cout << 1; return 0; } k...
#include <bits/stdc++.h> using namespace std; void qmax(long long &x, int y) { if (x < y) x = y; } void qmin(long long &x, long long y) { if (x > y) x = y; } inline long long read() { char s; long long k = 0, base = 1; while ((s = getchar()) != - && s != EOF && !(isdigit(s))) ; ...
#include <bits/stdc++.h> using namespace std; string s; int pos[1000]; int n, a, b; int main() { cin >> n; cin >> s; for (int i = 0; i < s.size(); i++) { if (s[i] == x ) a++; else b++; } cout << abs(n / 2 - a) << endl; int t = abs(n / 2 - a); if (a > b)...
#include <bits/stdc++.h> using namespace std; int main() { int t, n; cin >> t; while (t--) { int ans = 0; cin >> n; cout << n / 2 << endl; } }
#include <bits/stdc++.h> using namespace std; void checkDefine(); long long int a, b, c, d; int main() { cin >> a >> b >> c >> d; long long int t1 = max(3 * a / 10, a - (a * c) / 250); long long int t2 = max(3 * b / 10, b - (b * d) / 250); if (t1 > t2) { cout << Misha ; } else if (t1 ...
#include <bits/stdc++.h> using namespace std; long long n, k, cnt[200005], x, y, ans; vector<long long> v[200005]; void dfs(long long pos, long long pre) { long long len = v[pos].size(); for (long long i = 0; i < len; i++) { long long xx = v[pos][i]; if (xx != pre) { dfs(xx, pos); ...
#include <bits/stdc++.h> using namespace std; bool cmp(pair<long long, int> l, pair<long long, int> r) { return l.first < r.first; } int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); ; long long n, A, cf, cm, money; cin >> n >> A >> cf >> cm >> money; vector<pair<lon...
#include <bits/stdc++.h> int nextInt() { int x; scanf( %d , &x); return x; } double nextDouble() { double x; scanf( %lf , &x); return x; } long long nextLong() { long long x; scanf( %I64d , &x); return x; } char nextChar() { char x; scanf( %c , &x); return x...
#include <bits/stdc++.h> using namespace std; int main() { set<int> co[2]; set<pair<int, int> > delta[2]; int w, h, n; scanf( %d%d%d , &w, &h, &n); co[0].insert(0); co[0].insert(w); delta[0].insert(make_pair(w, 0)); co[1].insert(0); co[1].insert(h); delta[1].insert(make_pair(...
#include <bits/stdc++.h> using namespace std; struct node { int l, r, x, y; }; vector<node> p[500010]; int a[500010], b[500010], c[500010]; int main() { int i, j, k, n, m, s; node e; scanf( %d%d , &n, &m); for (i = 1; i <= n; i++) scanf( %d , &a[i]); b[0] = 0; for (i = 1; i <= n ...
#include <bits/stdc++.h> using namespace std; void func() { string s; cin >> s; long long n = s.length(); long long i = 1, len = 0, pre[n]; pre[0] = 0; while (i < n) { if (s[i] == s[len]) { len++; pre[i++] = len; } else { if (len == 0) { pre[i++]...
#include <bits/stdc++.h> using namespace std; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); struct item { long long t, d, p, idx; }; item sh[200005]; bool cmp(item x, item y) { return x.d < y.d; } long long n; long long dp[105][2005]; long long sol(long long i, long long cur...
#include <bits/stdc++.h> int n, m, i, j, k, l, a, b, c; char s[200][200]; bool bo; void fail() { bo = false; } bool work(int x, int y, int o, int p, int a, int b, int c) { int i, j; if (x > o) { return true; } if ((a < 0) || (b < 0) || (c < 0)) return false; if (x == o) { j = 0...
#include <bits/stdc++.h> using namespace std; const long long MOD = 1e9 + 7; const long long INF = 4e18; const long long MAX = 1e5; const long long MV = 1e18; const long double PI = 3.14159265358979323846; long long MA = -INF, MI = INF; long long PO(long long x, long long y) { if (y == 0) return 1; ...
#include <bits/stdc++.h> using namespace std; static long long mod = 998244353; long long pow(long long x, long long y) { x = x % mod; int res = 1; while (y > 0) { if (y & 1) { res = (res * x) % mod; } y = y >> 1; x = (x * x) % mod; } return res; } long long...
#include <bits/stdc++.h> using namespace std; long long a[100010]; vector<pair<long long, long long> > people; long long Free[100010]; int main() { long long ts, tf, t; cin >> ts >> tf >> t; int n; scanf( %d , &n); if (n == 0) { cout << ts << endl; return 0; } for (int ...
#include <bits/stdc++.h> using namespace std; int main() { long int co = 0, i, n, y, m, j, k, t, x = 0; cin >> n; int a[n + 1]; for (i = 1; i <= n; i++) cin >> a[i]; co = 0; int c = 1; j = 0; vector<int> v; map<int, int> mp; for (i = 1; i <= n; i++) { mp[a[i]]++; ...
#include <bits/stdc++.h> using namespace std; int n, tot; long long ans, sum; char s[100010], t[100010]; void print(int x, int opt) { tot++; printf( %d %d n , x, opt); if (tot == 100000) exit(0); } bool check(int i, int opt) { if (i == n) return 0; if (opt == -1) { if (s[i + 1] >...
#include <bits/stdc++.h> using namespace std; char s[100005]; int c[100005], N, full; int LG; void read() { scanf( %d n , &N); for (int line = 1; line <= N; ++line) { scanf( %s , s + 1); s[0] = # ; int len = strlen(s) - 1; LG = len; for (int i = 1; i <= len; ++i) { ...
#include <bits/stdc++.h> using namespace std; const int INF = (int)2e9; const double EPS = 1e-6; const double PI = 3.1415926535; const int MOD = 1000003; int last[100000]; int main() { int a, b, m, now, i = 2; cin >> a >> b >> m >> now; last[now] = 1; while (1) { now = (a * now + b) ...
#include <bits/stdc++.h> using namespace std; struct Expr { char a[1010], b[1010]; int v; int op; }; Expr exps[5010]; char ansMin[1010], ansMax[1010]; char buf[10010]; map<string, int> varIndex; int calc(int a, int b, int op) { if (op == 1) return a & b; else if (op == 2) ...
#include <bits/stdc++.h> using namespace std; int main() { int n, m; map<int, vector<int>> mappu; cin >> n >> m; for (long long i = (0); i < (m); i++) { int a, b; cin >> a >> b; mappu[a].push_back(b); mappu[b].push_back(a); } for (long long i = (1); i < (n + 1); i++) ...
#include <bits/stdc++.h> using namespace std; int a[105]; struct Fenwick_Tree { int sz, c[305]; void init(int n) { sz = n; for (int i = 1; i <= n; i++) c[i] = 0; } int lowbit(int x) { return x & (-x); } void update(int p, int v) { for (int i = p; i <= sz; i += lowbit(i)) c[i]...
#include <bits/stdc++.h> using namespace std; const int MAX_N = 1000011; const long long INF = (1 << 29) + 123; const long long MOD = 1000000007; const long double PI = 4 * atan((long double)1); int main() { ios_base::sync_with_stdio(false); cin.tie(0); int n, w; cin >> n >> w; int l[n];...
#include <bits/stdc++.h> #pragma GCC optimize( Ofast ) #pragma GCC target( sse4 ) using namespace std; constexpr long long mod = 1000000007; const long long INF = mod * mod; const double eps = 1e-12; const double pi = acosl(-1.0); long long mod_pow(long long x, long long n, long long m = mod) { long...
#include <bits/stdc++.h> using namespace std; int a, b, t, n, m, f[100010], ans, trl; struct node { int next, ar, flow, b; } k[100010 * 20]; int first[100010], dis[100010], len; int X[100010], y[100010], v[100010], e[100010]; int t1[100010], t2[100010], tl1, tl2, ANS; void add(int a, int b, int t) {...
#include <bits/stdc++.h> using namespace std; int a[10005], cnt[305], dp[10005], inf = 1e8; int main() { int n, t; scanf( %d %d , &n, &t); int max_num = 0, len = n * min(n / 2, t); if (len <= 0) len = n; for (int i = 1; i <= n; ++i) { scanf( %d , a + i); max_num = max(max_num, ++cn...
#include <bits/stdc++.h> const int MAXN = 1e5 * 5; const int INF = 1e9 + 7; const int N = 5000; using namespace std; int n, m, h[N], c[N], cnt; char a[N][N]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> n >> m; for (int i = 1; i <= n; ++i) for (int j = 1; j <= m; ++j...
#include <bits/stdc++.h> using namespace std; const int N_MAX = 1e9, MAX = 4000001, MOD = 1000000007; int t, n, k, ans[200001]; vector<int> cnt[200001]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> t; while (t--) { cin >> n >> k; int sum = 0; ...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); int t; cin >> t; while (t--) { string aba; cin >> aba; int ab = 0; int ba = 0; if (aba[0] != aba[aba.size() - 1]) { aba[0] = aba[aba.size() - 1]; for (int i = 0;...
#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, in...
#include <bits/stdc++.h> using namespace std; int n, T; vector<int> intp; vector<int> t; vector<double> p; vector<vector<long double> > dp; vector<vector<long double> > pows; long double ans; void addAns(const vector<long double>& prob, int index) { for (int j = 1; j <= T; j++) { if (index =...
#include <bits/stdc++.h> using namespace std; ostream &operator<<(ostream &out, string str) { for (char c : str) out << c; return out; } template <class L, class R> ostream &operator<<(ostream &out, pair<L, R> p) { return out << ( << p.first << , << p.second << ) ; } template <class T> ...
#include <bits/stdc++.h> using namespace std; char getc() { char c = getchar(); while ((c < A || c > Z ) && (c < a || c > z ) && (c < 0 || c > 9 )) c = getchar(); return c; } long long gcd(long long n, long long m) { return m == 0 ? n : gcd(m, n % m); } long long read() { long l...
#include <bits/stdc++.h> int main() { long long a, b, k = 0; bool flag = true; std::stack<long long> st; std::cin >> a >> b; st.push(b); while (b > a && flag) { if (b % 10 == 1) { b = b / 10; st.push(b); k++; } else if (b % 2 == 0) { b = b / 2; ...
#include <bits/stdc++.h> using namespace std; int fin[100005]; int main() { int n; while (cin >> n) { int l, r; int flag = 1; int temp; for (int i = 0; i < n; i++) { cin >> l >> r; if (i == 0) fin[0] = l > r ? l : r; else { temp = l > r ?...
#include <bits/stdc++.h> using namespace std; const int N = 3005; int n, m, k, p[N]; bool vis[N]; inline void mk(int v) { for (int i = v; !vis[i]; i = p[i]) vis[i] = 1; } int main() { while (~scanf( %d , &n)) { for (int i = 0; i < n; ++i) scanf( %d , &p[i]), --p[i]; scanf( %d , &m); ...
#include <bits/stdc++.h> using namespace std; struct crew { string name; string pos; }; int main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; vector<crew> a(n); for (int i = 0; i < n; i++) cin >> a[i].name >> a[i].pos; for (int i = 0; i < n; i++) { if (...
#include <bits/stdc++.h> using namespace std; int m, n, t, k; long long a[10]; long long x[10]; int cnt; bool ok(int n) { for (int i = 2; i <= n; i++) if (a[i] == i) return 0; for (int i = 2; i <= n; i++) { int t = a[i]; int cnt = 0; while (t != 1) { cnt++; t ...
#include <bits/stdc++.h> using namespace std; int main() { char s[5000], a[5000]; char b[] = bear ; int count = 0, j = 0; scanf( %s , &s); int i = 0; int n = strlen(s); printf( %s , a); for (i = 0; i < n; i++) { for (j = i; j < n; j++) { if (s[j] == b && s[j + 1] == ...
#include <bits/stdc++.h> using namespace std; using ll = long long int; using ull = unsigned long long int; bool odd(ll num) { return ((num & 1) == 1); } bool even(ll num) { return ((num & 1) == 0); } ll sum(ll n) { return ((n * (n + 1)) / 2); } ll ceil(ll a, ll b) { return ((a + (b - 1)) / b); } void I...
#include <bits/stdc++.h> int main() { int n, m, i, j, b = 0; scanf( %d %d , &n, &m); int pass[n]; int finger[m]; int print[m]; for (i = 0; i < n; i++) { scanf( %d , &pass[i]); } for (i = 0; i < m; i++) { scanf( %d , &finger[i]); } for (i = 0; i < n; i++) { for...
#include <bits/stdc++.h> using namespace std; void in(int &r) { static char c; r = 0; while (c = getchar(), !isdigit(c)) ; do r = (r << 1) + (r << 3) + (c ^ 48); while (c = getchar(), isdigit(c)); } const int mn = 100005; int head[mn], ne[mn << 1], to[mn << 1], cnt1; int fa[mn]; ...
#include <bits/stdc++.h> using namespace std; int main() { int n, k; scanf( %d%d , &n, &k); int z = k - 1; while (n % z) z--; int y = n / z; printf( %d n , y * k + z); }
#include <bits/stdc++.h> using namespace std; unordered_map<string, vector<string> > m; set<string> q; string SS(char C) { string p = ; p += C; return p; } void dfs(string s, long n) { if (n == 0) { q.insert(s); return; } for (auto i : m[SS(s[0])]) dfs(i + s.substr(1, s...
#include <bits/stdc++.h> using namespace std; const int maxn = 3700, maxd = 1850, mod = 998244353; int h, w, tr[maxn], tc[maxn], x, y, n; vector<int> rs, cs; long long f[maxd], c[maxn][maxn], dpr[maxn][maxd], dpc[maxn][maxd], ans; long long C(int a, int b) { if (a < 0 || b < 0 || a < b) return 0; re...
#include <bits/stdc++.h> using namespace std; template <typename T1, typename T2> istream& operator>>(istream& in, pair<T1, T2>& a) { in >> a.first >> a.second; return in; } template <typename T1, typename T2> ostream& operator<<(ostream& out, pair<T1, T2> a) { out << a.first << << a.second;...
#include <bits/stdc++.h> using namespace std; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); int main() { ios::sync_with_stdio(false); cin.tie(0); int t; cin >> t; while (t--) { int n; cin >> n; string s; cin >> s; string a(n, 0 ); str...
#include <bits/stdc++.h> using namespace std; const double PI = acos(-1); const double eps = 1e-12; const int inf = 2000000000; const long long int infLL = (long long int)1e18; long long int MOD = 1000000007; int MOD1 = 1000000007; int MOD2 = 1000000009; inline bool checkBit(long long int n, long long...
#include <bits/stdc++.h> using namespace std; const long long N = 1e6; const long long MX = -1e7 - 3; const long long MN = 1e7 + 3; long long n, m, cnt, ans, x, y, mx = MX, mn = MN, a, b, c, d, T, l, r, k; float p = 3.14159; bool bl, bl1; string str = , s; map<char, long long> mp, mp1; vector<long...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); long long ts, tf, t; cin >> ts >> tf >> t; int n; cin >> n; map<long long, int> T; for (int i = 0; i < n; ++i) { long long t; cin >> t; ++T[t]; } long long bt = 0...
#include <bits/stdc++.h> using namespace std; const int MAX = 200010, INF = 1e9; int cnt[MAX]; int n, c, ans = INF; int mx[MAX], v[MAX]; bool f[MAX]; vector<int> a; bool ok(int x, int y) { if (x == 0) return 1; if (y == 0) return 0; x -= a[y] * min(cnt[a[y]], x / a[y]); if (mx[x] > y - 1...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; set<int> s; for (int i = 0; i < n; i++) { int x; cin >> x; s.insert(x); } set<int>::iterator it = s.begin(); int c = 0; while (it != s.end()) { if (*it == 0) c++; it++; } ...
#include <bits/stdc++.h> inline int read() { int data = 0, w = 1; char ch = getchar(); while (ch != - && (ch < 0 || ch > 9 )) ch = getchar(); if (ch == - ) w = -1, ch = getchar(); while (ch >= 0 && ch <= 9 ) data = data * 10 + (ch ^ 48), ch = getchar(); return data * w; } const in...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> vec(n); for (int i = 0; i < n; i++) { cin >> vec[i]; } if (n == 1) { if (vec[0] == 15) cout << DOWN << endl; else if (vec[0] == 0) cout << UP << endl; else ...
#include <bits/stdc++.h> using namespace std; int n, a[100010], g, cnt; int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); } int main() { scanf( %d , &n); for (int i = 0; i < n; i++) scanf( %d , &a[i]), g = g == 0 ? a[i] : gcd(a[i], g), cnt += a[i] & 1; printf( %d n , cnt > 1 ? 0 : g);...
#include <bits/stdc++.h> using namespace std; vector<int> V; void dfs(long long x) { if (x < 1000000000) { V.push_back(x); dfs(x * 10 + 4); dfs(x * 10 + 7); } } int main() { dfs(0); V.push_back(INT_MAX); sort(V.begin(), V.end()); int pl, pr, vl, vr, k; cin >> pl >...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); int n; cin >> n; int cnt = 0; string ans = 1 ; for (int i = 0; i < n; i++) { string str; cin >> str; while (str.size() && str.back() == 0 ) str.pop_back(), cnt++; if (str.size()...
#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 = 16; int n, a[maxn], b[maxn][maxn], ex; bool mark[maxn]; vec...
#include <bits/stdc++.h> int main() { char p[1000001]; int n, m, y2; int y1 = -1; long long ans = 1; scanf( %d %d , &n, &m); scanf( %s , p); int plen = strlen(p); for (int i = 0; i < m; ++i) { scanf( %d , &y2); if (-1 == y1) { n -= plen; } else if (y2 - y1 < p...
#include <bits/stdc++.h> int main() { int tcase; for (scanf( %d , &tcase); tcase--;) { long long l, r; scanf( %lld%lld , &l, &r); if (l == r) { printf( %lld n , r); continue; } int p = 63 - __builtin_clzll(l ^ r); long long temp = 0; for (int i = 63; i...
#include <bits/stdc++.h> using namespace std; const long long inf = 1e18; struct dsu { vector<int> par, rnk, size; int c; dsu(int n) : par(n + 1), rnk(n + 1, 0), size(n + 1, 1), c(n) { for (int i = 1; i <= n; ++i) par[i] = i; } int find(int i) { return (par[i] == i ? i : (par[i] = find(p...
#include <bits/stdc++.h> using namespace std; bool b[31]; struct trie { trie* nt[2]; int tot; trie() { nt[0] = nt[1] = NULL; tot = 0; } }; trie* root = new trie(); void insert(trie* cur, int idx) { if (idx == -1) return; else { int x = b[idx]; if (cur->n...
#include <bits/stdc++.h> using namespace std; const int maxn = 300000 + 100; int n, m, sz, l, r; int head[maxn], Next[maxn], to[maxn], in[maxn], out[maxn], deg[maxn], q[maxn]; void init() { sz = 0; memset(deg, 0, sizeof(deg)); memset(head, -1, sizeof(head)); } void add_edge(int a, int b) { ...
#include <bits/stdc++.h> using namespace std; int main() { long long n; cin >> n; if (n == 1 || n == 2 || n == 3) { cout << NO << endl; return 0; } cout << YES << endl; if (n % 2 == 0) { printf( 1 * 2 = 2 n ); printf( 2 * 3 = 6 n ); printf( 6 * 4 = 24 n ); ...
#include <bits/stdc++.h> using namespace std; int r[105][105], d[105][105], vis[105][105]; int w, h, n; int bfs(int x, int y) { queue<pair<int, int> > q; q.push({x, y}); vis[x][y] = 1; int area = 0; while (!q.empty()) { int cx = q.front().first, cy = q.front().second; q.pop(); ...
#include <bits/stdc++.h> using namespace std; const long long INF = 1e18; struct data { int points; string name; data(int p, string n) { points = p; name = n; } data() { points = -1; name = ; } }; inline bool cmp(data d1, data d2) { return (d1.points > d2.poin...
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 10, M = 1e6 + 5; long long T, l[N], dp[N], fen[M][2]; vector<int> adj[N]; int n, x[N], t[N]; void add(int p, int x) { for (long long y = 1LL * x * p; p < M; p += p & -p) fen[p][0] += x, fen[p][1] += y; } long long get(int p, int...
#include <bits/stdc++.h> using namespace std; long long f[(1 << 20) + 10], num[21], sum[21][21]; int main() { int n, m = 20; scanf( %d , &n); for (int i = 1, x; i <= n; i++) { scanf( %d , &x); x--, num[x]++; for (int j = 0; j < 20; j++) { sum[j][x] += num[j]; } } ...
#include <bits/stdc++.h> using namespace std; long long a[7]; long long T, X, Y, ans; long long ABS(long long x) { return (x > 0) ? x : -x; } int main() { scanf( %lld , &T); while (T--) { scanf( %lld%lld , &X, &Y); for (int i = 1; i <= 6; i++) scanf( %lld , &a[i]); a[1] = min(a[1], a...
#include <bits/stdc++.h> using namespace std; int n, m; bool check(int s) { return (int)sqrt(s) * (int)sqrt(s) == s; } int main() { int i, j, a, b, c, d, s1, s2, s3, s4; scanf( %d%d , &n, &m); for (a = 1; a <= 100; a++) for (b = 1; b <= 100; b++) for (c = 1; c <= 100; c++) fo...
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; vector<float> coordinates; for (int i = 0; i < (int)(n); ++i) { float a, b; cin >> a >> b; coordinates.push_back(a); coordinates.push_back(b); } float sum = 0; std::cout << fixed; ...
#include <bits/stdc++.h> using namespace std; vector<int> v[300005], one[300005]; map<pair<int, int>, int> mp; int size[300005], ji[300005], xx[300005], yy[300005]; char ans[300005]; void dfs1(int p, int fa) { size[p] = 1; ji[p]++; for (int i = 0; i < v[p].size(); i++) { int to = v[p][i]; ...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, k; cin >> n >> k; vector<string> notes, names(55); for (int i = 0; i <= n - k; i++) { string m; cin >> m; notes.push_back(m); } for (int i = ...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); double d, h, v, e; cin >> d >> h >> v >> e; double ans = (3.14159265358979323846 * pow(d, 2) * h) / (4 * v - 3.14159265358979323846 * pow(d, 2) * e); if (ans < 0) ...
#include <bits/stdc++.h> using namespace std; int n; bool taken[1001]; int a[1001], b[1001], ans[1001]; vector<int> problem; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> n; for (int i = 0; i < n; ++i) { cin >> a[i]; } for (int i = 0; i < n; ++i) { cin >> ...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(NULL); multiset<int> s; s.insert(0); int q; cin >> q; while (q--) { char c; int x; cin >> c >> x; if (c == + ) { s.insert(x); } else if (c == - ) { ...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); int n; long long mmax = 0; long long sum = 0; long long num; cin >> n; for (int i = 1; i <= n; i++) { cin >> num; sum += num; mmax = max(mmax, num); } cout << 2 * mmax - sum + 1 ...
#include <bits/stdc++.h> template <int MOD> struct Integral { int v_ = 0; template <typename T> Integral(T v) : v_(norm(v)) { static_assert(std::is_integral<T>::value, input should be an integral. ); } Integral() = default; ~Integral() = default; template <typename T> T norm(T...
#include <bits/stdc++.h> using namespace std; int main() { std::cin.tie(0); std::ios::sync_with_stdio(false); int t; cin >> t; while (t--) { int n, m, k; cin >> n >> m >> k; int nn = n - (n % 2 == 1); int mm = m - (m % 2 == 1); long long maxx = (nn / 2) * (mm / 2) *...
#include <bits/stdc++.h> using namespace std; int n, m, k; vector<vector<pair<long long, long long> > > g; void fun() { cin >> n >> m >> k; g.resize(n); map<pair<int, int>, int> index; for (long long i = 0; i < m; i++) { long long x, y, z; cin >> x >> y >> z; x--; y--; ...
#include <bits/stdc++.h> using namespace std; int main() { int n; long long m, k; scanf( %d%lld%lld , &n, &m, &k); long long a[n], asum[n + 1]; asum[0] = 0; for (int((i)) = (0); ((i)) < ((n)); ++((i))) { scanf( %lld , &a[i]); asum[i + 1] = asum[i] + a[i]; } long long dp[m...
#include <bits/stdc++.h> using namespace std; const int E9 = 1e9; const int E8 = 1e8; const int E7 = 1e7; const int E6 = 1e6; const int E5 = 1e5; const int E4 = 1e4; const int E3 = 1e3; const int N = 5e5 + 7; const int MOD = 1e9 + 7; const long long INF = 1e18; int n; bool dp[101][51][2][201];...
#include <bits/stdc++.h> using namespace std; int main() { unsigned long long n, sum = 0; cin >> n; if (n % 2 == 0) { if ((n / 2) % 2 == 0) cout << 0 << endl; else cout << 1 << endl; } else { if ((n / 2) % 2 == 0) cout << 1 << endl; else cout <...
#include <bits/stdc++.h> using namespace std; long long inf = 1e9 + 7; long long mod = 998244353; using namespace std; vector<long long> g[200005]; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); long long T, N, i, j, k, L, l, m, n; long long s; cin >> N >> s;...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n, m; cin >> n >> m; vector<int> debt(n + 1, 0); for (int i = 0; i < m; i++) { int poor, rich, amt; cin >> poor >> rich >> amt; debt[poor] -= amt; debt[rich...
#include <bits/stdc++.h> using namespace std; const int maxn = 1000 + 10, INF = 1e9; double arr[maxn]; int main() { int n; double mina = 0, maxa = INF; cin >> n; for (int i = 0; i < n; i++) cin >> arr[i]; for (int i = 0; i < n; i++) { mina = max(mina, arr[i] * 10 / (i + 1)); maxa...
#include <bits/stdc++.h> using namespace std; const int maxn = 3e5 + 10; const int INF = 1e9; vector<int> p[maxn]; bool vis[maxn]; int nmultiple[maxn], N, tag[maxn], a[maxn]; int gcd(int x, int y) { return x == 0 ? y : gcd(y % x, x); } int main() { for (int i = 2; i < maxn; ++i) { if (!vis[i])...
#include <bits/stdc++.h> using namespace std; long long f[203][203][2], g[203][203][2], A[203], B[203], C[203], SA[203], SB[203], N, T, K; int main() { cin >> N >> T >> K; for (int i = 1; i <= N; ++i) cin >> A[i] >> B[i] >> C[i]; ++N; A[N] = C[N] = 1e15; memset(f, 0x3f, sizeof(f)); m...
#include <bits/stdc++.h> using namespace std; int A[100000]; void solve() { int n; cin >> n; int prv = -1; for (int i = 0; i < (n); i++) cin >> A[i]; int res = 1; for (int i = 0; i < (n); i++) { int x = A[i]; ; ; if (x == 0) { if (prv == 0) { cout ...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false), cin.tie(0), cout.tie(0); int n, i, lim, cnt = 0, other = 0; string str; cin >> n >> str; lim = str.size(); int petya = (n - 11) / 2; for (i = 0; i < lim; i++) { if (str[i] == 8 ) cnt++;...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int a, b; cin >> a >> b; int ans = a; while (a >= b) { int t = a / b; ans += t; a = t + (a - b * t); } cout << ans << n ; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ; int n, a, b; cin >> n >> a >> b; string s; cin >> s; if (s[a - 1] == s[b - 1]) cout << 0 << n ; else { cout << 1 << n ; } retu...
#include <bits/stdc++.h> using namespace std; int main() { long long t, a, b, x; cin >> t; while (t--) { cin >> a >> b; if (a == b) { cout << 0 << endl; continue; } if (a < b) { x = (b / 10) - (a / 10); } else { x = (a / 10) - (b / 10); ...
#include <bits/stdc++.h> using namespace std; const int INF = 0x3fffffff; const int SINF = 0x7fffffff; const long long LINF = 0x3fffffffffffffff; const long long SLINF = 0x7fffffffffffffff; const int MAXN = 1007; const int MAXS = 107; const int MAXM = 13; const int MAXL = 13; const int BASE = 4; c...