func_code_string
stringlengths
59
71.4k
#include <bits/stdc++.h> using namespace std; struct query { int n, str_l, id; friend bool operator<(query a, query b) { return a.str_l < b.str_l; } }; const long long MOD = 1e9 + 7; const int maxn = 1e5 + 5; int n, str_len; char str[maxn]; long long ans[maxn], fac[maxn], ifac[maxn], inv[maxn], ...
#include <bits/stdc++.h> using namespace std; template <class T> T abs(T x) { return x > 0 ? x : -x; } int n; int m; int x[100]; int main() { scanf( %d%d , &n, &m); int s = 0, f = 0; for (int i = 0; i < n; i++) { scanf( %d , &x[i]); s += x[i]; f = max(f, x[i]); } ...
#include <bits/stdc++.h> const int N = 110; using namespace std; inline int read() { int x = 0, f = 1; int ch = getchar(); while (ch < 0 || ch > 9 ) { if (ch == - ) { f = -1; } ch = getchar(); } while (ch <= 9 && ch >= 0 ) { x = (x << 1) + (x << 3) + ch -...
#include <bits/stdc++.h> 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) { cerr << x; } void __prin...
#include <bits/stdc++.h> using namespace std; int main() { int n = 0; int answer = 0; cin >> n; int last = -1; int xs = 0, ys = 0, x = 0, y = 0; for (int i = 0; i < n; i++) { int px = x, py = y; char c; cin >> c; if (c == L ) x--; else if (c == R ) ...
#include <bits/stdc++.h> using namespace std; const long long INF = (long long)1000 * 1000 * 1000 * 1000 * 1000 * 100; const int MOD = 1000 * 1000 * 1000 + 9; const int SIZE = 5000; int main() { std::ios_base::sync_with_stdio(false); int n; cin >> n; vector<int> a(n); vector<vector<int> > ...
#include <bits/stdc++.h> using namespace std; const int maxn = 100010; const int inf = 1e9; int n, l[maxn], c[maxn], ans, cnt, pri[maxn], lst, cur, p[maxn], st[maxn], f[maxn]; bool tf[maxn]; int main() { scanf( %d , &n); for (int i = 1; i <= n; i++) scanf( %d , l + i); for (int i = 1; i <=...
#include <bits/stdc++.h> using namespace std; int n, m; char st[55][25]; int f[1100005], dx[1100005]; long long ms[1100005]; double dp[1100005], cf[1100005]; int main() { int i, j, k, sum, s; double ans = 0, t; cin >> n; for (i = 1; i <= n; i++) scanf( %s , st[i]); m = strlen(st[1]); ...
#include <bits/stdc++.h> using namespace std; long long num[200000]; pair<long long, long long> p[200000]; int main() { long long n, m, k, sum = 0, cnt = 1; cin >> n >> m >> k; for (int i = 1; i <= n; i++) { cin >> p[i].first; p[i].second = i; } sort(p + 1, p + n + 1); for (i...
#include <bits/stdc++.h> using ll = long long; using ld = long double; using ull = unsigned long long; using namespace std; const int N = 1e5 + 2, SQ = 400; int n, q, a[N], jump[N], cost[N]; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cin >> n >> q; for (int i = (0); i...
#include <bits/stdc++.h> #pragma comment(linker, /STACK:102400000,102400000 ) #pragma GCC optimize( Ofast ) #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native ) using namespace std; const int maxn = 2e5 + 5; map<int, int> dp, pos; int pre[maxn]; int main() { ios::sync_with_...
#include <bits/stdc++.h> using namespace std; int main() { vector<vector<char> > v(4); for (int i = 0; i < 4; i++) v[i].resize(4); for (int i = 0; i < 4; i++) { for (int j = 0; j < 4; j++) { cin >> v[i][j]; } } for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) {...
#include <bits/stdc++.h> using namespace std; int main() { long long a[100], b[100], i, n, m, r; cin >> n >> m >> r; long long ans = r; for (i = 0; i < n; ++i) { cin >> a[i]; } for (i = 0; i < m; ++i) { cin >> b[i]; } long long minn = *min_element(a, a + n); long long...
#include <bits/stdc++.h> using namespace std; int main() { int n, x = 0; cin >> n; string s; while (n-- != 0) { cin >> s; if (s.find( + ) != string::npos) x++; else x--; } cout << x; return 0; }
#include <bits/stdc++.h> #pragma GCC optimize(2) #pragma GCC optimize(3, Ofast , inline ) using namespace std; void err(istream_iterator<string> it) { cerr << endl; } template <typename T, typename... Args> void err(istream_iterator<string> it, T a, Args... args) {} namespace fastIO { bool IOerror = 0...
#include <bits/stdc++.h> using namespace std; struct mat { int num[4][4]; }; mat m1 = {{{1, 1, 1, 0}, {1, 0, 0, 0}, {0, 0, 1, 0}, {0, 0, 0, 1}}}, m2 = {{{1, 1, 0, 1}, {1, 0, 0, 0}, {0, 0, 1, 0}, {0, 0, 0, 1}}}; mat mult(mat &a, mat &b) { mat ret; for (int i = 0; i < 4; i++) for (int j ...
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; string a, b; map<pair<string, string>, int> m; int f(string aa, string bb) { if (aa == bb) return 2; if (aa.size() % 2) return 1; if (m[{aa, bb}] != 0) return m[{aa, bb}]; string a1, b1, a2, b2; for (int i = 0; i ...
#include <bits/stdc++.h> using namespace std; const int N = 102, M = 102 * 102; int n, m; vector<pair<int, int> > g[N]; char ans[N][N]; char dp[N][N][28] = {0}; void input() { cin >> n >> m; for (int i = (0); i < (m); ++i) { int u, v; char ch; cin >> u >> v >> ch; u--, v--;...
#include <bits/stdc++.h> using namespace std; const int N = 2e3 + 7; const int inf = 1e9 + 7; int T, n, dp[N][N], cnt[N], qzs[N][26], qzt[N][26]; char s[N], t[N]; void Min(int &x, int y) { if (x > y) x = y; } void Main() { fill(cnt, cnt + 26, 0); scanf( %d , &n); for (int i = 0, iE = n; ...
#include <bits/stdc++.h> using namespace std; int n, s[1000006], top, a[1000006]; int solve(int n, int mul) { if (n == 1) return s[++top] = mul; if (n == 2) return s[++top] = mul, s[++top] = mul * 2; if (n == 3) return s[++top] = mul, s[++top] = mul, s[++top] = mul * 3; for (int i = 1; i <= (n - n...
#include <bits/stdc++.h> using namespace std; const int SCALE = 101; int g[SCALE * 2][SCALE * 2]; int tx, ty; int stepr[4] = {0, -1, 0, 1}; int stepc[4] = {-1, 0, 1, 0}; string s; bool BuildMap(const string& s) { int x = 0; int y = 0; memset(g, 0, sizeof(g)); g[(x + SCALE)][(y + SCALE)] ...
#include <bits/stdc++.h> using namespace std; template <typename T> istream& operator>>(istream& is, vector<T>& a) { for (T& ai : a) is >> ai; return is; } template <typename T> ostream& operator<<(ostream& os, vector<T> const& a) { os << [ ; for (const T& ai : a) os << ai << ; retu...
#include <bits/stdc++.h> using namespace std; struct basis { int vis[29 + 1]; void ins(int x) { for (int i = 29; i >= 0; i--) if ((1 << i) & x) { if (vis[i]) x ^= vis[i]; else { vis[i] = x; break; } } } int minim...
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 5; int n, m; vector<long long> b(N, 0); void add(int x, int k) { while (x < N) { b[x] += k; x += x & -x; } } long long sum(int x) { long long ret = 0; while (x) { ret += b[x]; x -= x & -x; } r...
#include <bits/stdc++.h> const double PI = 3.141592653589793238462643383279502884197169399375105820974944; using namespace std; long long arr[] = {0, 9, 90, 900, 9000, 90000, 900000, 9000000, 90000000, 900000000}; long long arr1[] = {0, 9, 99, 999, ...
#include <bits/stdc++.h> using namespace std; int A[500][500]; int B[500][500]; int main() { ios::sync_with_stdio(false); cin.tie(NULL); int n, m; cin >> n >> m; for (int i = 0; i < n; ++i) for (int j = 0; j < m; ++j) cin >> A[i][j]; int mx = -1e9; for (int i = 0; i < n; ++i) ...
#include <bits/stdc++.h> #pragma GCC optimize( Ofast ) #pragma GCC target( avx,avx2,fma ) #pragma comment(linker, /stack:200000000 ) #pragma GCC optimize( unroll-loops ) using namespace std; template <typename A> ostream &operator<<(ostream &cout, vector<A> const &v); template <typename A, typename B> ...
#include <bits/stdc++.h> using namespace std; template <typename T, size_t N> int SIZE(const T (&t)[N]) { return N; } template <typename T> int SIZE(const T &t) { return t.size(); } string to_string(const string s, int x1 = 0, int x2 = 1e9) { return + ((x1 < s.size()) ? s.substr(x1, x2 -...
#include <bits/stdc++.h> using namespace std; int main() { long long int t, n; cin >> t; while (t--) { cin >> n; if (n % 2) cout << (n + 1) / 2 << endl; else cout << n / 2 << endl; } }
#include <bits/stdc++.h> using namespace std; int ans[2010][2], n; bool vis[510][510]; bool query(int x1, int y1, int x2, int y2) { printf( ? %d %d %d %d n , x1, y1, x2, y2); fflush(stdout); char ch[5]; scanf( %s , ch); if (ch[0] == Y ) return 1; else return 0; } void ou...
#include <bits/stdc++.h> using namespace std; int main() { int n, k; scanf( %d%d , &n, &k); int width = 2 * k + 1; if (width >= n) { printf( 1 n ); printf( %d , n / 2 + n % 2); return 0; } if (n % width == 0) { printf( %d n , n / width); for (int out = k + 1; ou...
#include <bits/stdc++.h> using namespace std; int n, k; long long m, f[1005][105][2]; long long dfs(int Index, int y, int now, int flag) { if (Index > n) return (flag == 0); if (f[Index][y][flag] != -1) return f[Index][y][flag]; int st = Index == n ? 1 : 0, y1; long long res = 0; for (int i ...
#include <bits/stdc++.h> using namespace std; int arr[100001]; int a, b, n, best; int main() { bool dima = true; scanf( %d , &n); for (int i = 0; i < n; ++i) { scanf( %d%d , &a, &b); arr[a] = b; } for (int i = 0; i < 100001; ++i) { if (arr[i] > 0) if (arr[i] > best)...
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 10, INF = 0x3f3f3f3f, MOD = 1e9 + 7; struct P { long long x, y; P() {} P(long long x, long long y) : x(x), y(y) {} P rotate() { return P(-y, x); } P operator-(const P& rhs) const { return P(x - rhs.x, y - rhs.y); } long long...
#include <bits/stdc++.h> using namespace std; int gcd(int x, int y) { if (y == 0) return x; return gcd(y, x % y); } int lcm(int x, int y) { return x * y / gcd(x, y); } long long int gcd(long long int x, long long int y) { if (y == 0) return x; return gcd(y, x % y); } long long int lcm(long...
#include <bits/stdc++.h> using namespace std; const int MAXN = 100000 + 10; long long A, B, N; long long l, t, m; int main() { cin >> A >> B >> N; for (int i = 1; i <= N; i++) { cin >> l >> t >> m; if (t < A + (l - 1) * B) { cout << -1 << endl; continue; } long ...
#include <bits/stdc++.h> using namespace std; const int MAX = 305; bool u[301][301][30][8]; int a[500][500], t[40], n; int dx[8] = {-1, -1, 0, 1, 1, 1, 0, -1}; int dy[8] = {0, 1, 1, 1, 0, -1, -1, -1}; void dfs(int x, int y, int z, int w) { if (z >= n) return; if (u[x][y][z][w]) return; u[x][y]...
#include <bits/stdc++.h> using namespace std; const int N = 265000; int n, q, a[N]; double s; int main() { scanf( %d%d , &n, &q); for (int i = (0); i <= (int)(1 << n) - 1; i++) scanf( %d , &a[i]), s += a[i]; printf( %.10lf n , 1.0 * s / (1 << n)); for (int i = (1); i <= (int)q; i++) { in...
#include <bits/stdc++.h> using namespace std; int n, p, q, r, now; int a[500050], b[500050], c[500050], id[500050], mxx[500050], mxy[500050]; long long ans; struct seg { int mark[500050 << 2], mx[500050 << 2], mn[500050 << 2]; long long sum[500050 << 2]; void push_up(int id) { sum[id] = sum[...
#include <bits/stdc++.h> using namespace std; int n; int info[200005], sz[200005], Prev[200005 << 1], to[200005 << 1], cst[200005 << 1], cnt_e; void Node(int u, int v, int c) { Prev[++cnt_e] = info[u], info[u] = cnt_e, to[cnt_e] = v, cst[cnt_e] = c; } long long G, B; void dfs(int u, int ff) { ...
#include <bits/stdc++.h> using namespace std; signed main() { long long n, k; scanf( %lld%lld , &n, &k); long long coin = 0, sum = 0; for (long long i = 1; i <= k; i++) { long long a, b; scanf( %lld%lld , &a, &b); sum = (sum + a * b) % n; coin += b; } if (coin > n) { ...
#include <bits/stdc++.h> using namespace std; const int mod = 1000000009, N = 4005; int cal[N][N], fac[N]; inline int add(int a, int b) { if (a < 0) a += mod; if (b < 0) b += mod; int ret = a + b; if (ret >= mod) return ret %= mod; else return ret; } inline int mul(int a, int...
#include <bits/stdc++.h> using namespace std; const int mx = 5005; int type[mx], dp[mx]; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n, m; cin >> n >> m; for (int i = 1; i <= n; i++) { double x; cin >> type[i] >> x; } for (int i = 1; i ...
#include <bits/stdc++.h> using namespace std; using ll = long long; using ull = unsigned long long; using ld = long double; using pii = pair<int, int>; using pll = pair<ll, ll>; using pci = pair<char, int>; using vi = vector<int>; using vll = vector<ll>; using vpii = vector<pii>; const ll infll = ...
#include <bits/stdc++.h> using namespace std; int n; string s; vector<string> text; vector<int> lens; bool check(int w) { int c = 0, lines = 1; for (int i = 0; i < (int)(lens).size(); i++) { if (lens[i] > w) return false; if (c + lens[i] > w) { lines++; i--; c = 0...
#include <bits/stdc++.h> using namespace std; long long ans = 0; int n; long long a[200200]; long long mn = 21000000000; int main() { cin >> n; for (int i = 0; i < n; i++) { cin >> a[i]; mn = min(mn, a[i]); } int id; for (int i = n - 1; i >= 0; i--) { if (a[i] == mn) { ...
#include <bits/stdc++.h> using namespace std; int v[200003],mMst[200003],mMdr[200003],Mmst[200003],Mmdr[200003]; int aib[200003]; int lsb (int x) { return x&-x; } void reset () { for(int i=1;i<=200000;++i) aib[i]=0; } void upd (int pz, int val) { for(int i=pz;i<=200000;...
#include <bits/stdc++.h> using namespace std; const int N = 131072 | 5, mod = 998244353; int add(int x, int y) { return (x += y) >= mod ? x - mod : x; } void ADD(int &x, int y) { (x += y) >= mod ? x -= mod : 0; } int qpow(int a, int b) { int ans = 1; for (; b >= 1; b >>= 1, a = (long long)a * a % mod)...
#include <bits/stdc++.h> using namespace std; int main() { int n, m, h, k; cin >> n >> m >> h >> k; cout << ((n > m) ? First : Second ) << endl; return 0; }
#include <bits/stdc++.h> #pragma GCC optimize( Ofast ) using namespace std; mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); long long int myRand(long long int B) { return (unsigned long long)rng() % B; } const int N = 51; int vld[N][N][N][N]; int main() { cin.tie(nullptr); ...
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 10; int n, a[N]; int main() { cin >> n; for (int i = 1; i <= n; i++) cin >> a[i]; int s = 0; for (int i = 1; i <= n; i++) s ^= a[i]; if (n % 2 == 0) { if (s != 0) { cout << NO n ; return 0; } ...
#include <bits/stdc++.h> using namespace std; int nums[105]; int main() { int n, m, mayor; cin >> n >> m; for (int i = 0; i < n; i++) { cin >> nums[i]; } sort(nums, nums + n); reverse(nums, nums + n); int maximo = nums[0] + m; mayor = nums[0]; for (int i = 0; i < n; i++) ...
#include <bits/stdc++.h> const int oo = 0x3f3f3f3f; template <typename T> inline bool chkmax(T &a, T b) { return a < b ? a = b, true : false; } template <typename T> inline bool chkmin(T &a, T b) { return a > b ? a = b, true : false; } template <typename T> T read(T &first) { int f = 1; ...
#include <bits/stdc++.h> using namespace std; int a[107], b[107]; int main() { int m, s; cin >> m >> s; int ss = s; if (s >= 2 and s <= m * 9) { s--; a[m] = 1; for (int i = 1; i <= m; i++) { if (s > 9) { a[i] += 9; s -= 9; } else { a[...
#include <bits/stdc++.h> using namespace std; long long F[401000], Mod = 998244353, InvF[401000]; long long Pow(long long a, long long b) { long long r = 1; while (b) { if (b & 1) r = r * a % Mod; a = a * a % Mod; b >>= 1; } return r; } int A[201000], n, K; long long S[2010...
#include <bits/stdc++.h> int n, p[110], i, j, cnt; char s[110]; int main() { scanf( %d , &n); for (i = 0; i < n; i++) scanf( %d , &p[i]); gets(s); for (i = 0; i < n; i++) { gets(s); cnt = 0; for (j = 0; s[j]; j++) if (s[j] == a || s[j] == e || s[j] == i || s[j] == ...
#include <bits/stdc++.h> using namespace std; const long long N = 1e6 + 7; long long n, q; long long a[N]; long long l[N], r[N]; void read() { cin >> n >> q; for (long long i = 0; i < n; ++i) cin >> a[i]; for (long long i = 0; i < q; ++i) cin >> l[i]; for (long long i = 0; i < q; ++i) cin >>...
#include <bits/stdc++.h> using namespace std; template <class t> inline t read(t &x) { x = 0; char c = getchar(); bool f = 0; while (!isdigit(c)) f |= c == - , c = getchar(); while (isdigit(c)) x = (x << 1) + (x << 3) + (c ^ 48), c = getchar(); if (f) x = -x; return x; } template ...
#include <bits/stdc++.h> using namespace std; int main() { int a, b, s; scanf( %d%d%d , &a, &b, &s); int req = abs(a) + abs(b); if (req > s) { printf( No n ); } else { int cur = s - req; if (cur & 1) { printf( No n ); } else { printf( Yes n ); } ...
#include <bits/stdc++.h> using namespace std; int dx[] = {0, 0, 1, -1}; int dy[] = {1, -1, 0, 0}; int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1}; int dy8[] = {1, -1, -1, 0, 1, -1, 0, 1}; int kx8[] = {1, 1, 2, 2, -1, -1, -2, -2}; int ky8[] = {2, -2, 1, -1, 2, -2, 1, -1}; long long poww(long long a, long long b)...
#include <bits/stdc++.h> using namespace std; struct node { int x, y; int num; }; node point[303]; char str[5][105]; int t, n, k; int flag = 0; int Flag[5][105]; queue<node> Q; void bfs() { while (!Q.empty()) { node D = Q.front(), R; Q.pop(); if (D.x >= n) { fla...
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; int arr[100]; for (int counter = 0; counter < n; counter++) { cin >> arr[counter]; } sort(arr, arr + n); int sum = 0; for (int counter = n - 1; counter >= 0; counter--) { sum += arr[counte...
#include <bits/stdc++.h> using namespace std; template <class T> inline T bigmod(T p, T e, T M) { long long ret = 1; for (; e > 0; e >>= 1) { if (e & 1) ret = (ret * p) % M; p = (p * p) % M; } return (T)ret; } template <class T> inline T gcd(T a, T b) { if (b == 0) return a; ...
#include <bits/stdc++.h> using namespace std; const int MAXN = 32768 - 1; int ans[100500]; bool use[100500]; int res; string s = ; int eval_num(int n, int &i); int eval_product(int n, int &i); int eval_sum(int n, int &i); bool eval_logick(int n, int &i); int eval_op(int n, int &i); int eval_op...
#include <bits/stdc++.h> using namespace std; const double pi = acos(-1.0); const int mod = 1000 * 1000 * 1000 + 7; const long long inf = 1e18; void rd(int &x) { scanf( %d , &x); } void rd(long long &x) { scanf( %lld , &x); } void rd(double &x) { scanf( %lf , &x); } void rd(int &x, int &y) { scanf( %d%d...
#include <bits/stdc++.h> using namespace std; const int __ = 1000000; bool pri[__ + 5]; int num[__ + 5]; void era() { int x = (int)sqrt(__ + 0.01); for (int i = 2; i <= x; i++) if (!pri[i]) { num[++num[0]] = i; for (int j = i * i; j <= __; j += i) pri[j] = true; } for (...
#include <bits/stdc++.h> using namespace std; int main() { string s1; while (cin >> s1) { string s2 = ; for (int i = 0; i < s1.size(); i++) { if (s1[i] != + ) s2 += s1[i]; } sort(s2.begin(), s2.end()); for (int i = 0; i < s2.size(); i++) { if (i) cout << + ;...
#include <bits/stdc++.h> using namespace std; long long ara[200005]; long long aray[200005]; int main() { long long a, b, c, d, t, i, j, k, n, m; cin >> t; while (t--) { long long ans = 0; cin >> n >> m >> k; a = n / k; if (m > a) { m -= a; if (m % (k - 1) == ...
#include <bits/stdc++.h> using namespace std; int main() { int sum = 0, n; scanf( %d , &n); for (int i = 1; i <= n; i++) { sum += (n - i) * (i - 1) + i; } printf( %d n , sum); }
#include <bits/stdc++.h> using namespace std; const double error = 1e-7; double v, r; bool puede(double t, double dist) { dist -= v * t; if (dist <= 0) return true; double tvuelta = r * 2 * M_PI / v; t -= int(t / tvuelta) * tvuelta; double a = t * v / r; return dist <= 2 * r * sin(a / 2....
#include <bits/stdc++.h> using namespace std; long long n, l, v1, v2, k; int main() { cin >> n >> l >> v1 >> v2 >> k; long long g = (n + k - 1) / k; double le = 0, ri = l / (double)v1; while ((ri - le) >= 5e-7) { double mid = (le + ri) / 2; double t = 0; for (int i = 1; i <= g; i...
#include <bits/stdc++.h> using namespace std; #define ll long long typedef pair<ll, ll> pll; typedef pair<ll, int> pli; typedef pair<int, ll> pil; typedef pair<int, int> pii; typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<bool> vb; typedef vector<vb> vvb; typedef vector<char>...
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n, o; string s; cin >> n >> s; o = s[n - 1] - 0 ; for (int i = 0; i < n - 1; i++) o += (s[i] == 0 ? 0 : s[i] - 47); cout << o << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; const long long MAX = 9999999999999999; int t, n; vector<long long> ans; vector<long long> graphSize; vector<long long> aToFirst, aToLast, bToFirst, bToLast; void countLength(vector<long long> &toFirst, vector<long long> &toLast, long long v...
#include <bits/stdc++.h> using namespace std; class Reduced_Indexs { vector<int> idxs; int n; public: Reduced_Indexs() = default; template <typename InputIterator> Reduced_Indexs(InputIterator first, InputIterator last) { idxs = vector<int>(first, last); sort(idxs.begin(), idxs...
#include <bits/stdc++.h> using namespace std; int n, ar[3100], cur; vector<int> v; bool valid, used[10000]; pair<int, string> tab[3100]; int main() { cin >> n; for (int i = 0; i < n; i++) { cin >> tab[i].second >> tab[i].first; } sort(tab, tab + n); valid = true; for (int i = 0...
#include <bits/stdc++.h> using namespace std; int a[500010], n, ans = 0; int main() { scanf( %d , &n); for (int i = 1; i <= n; i++) scanf( %d , &a[i]); int x = 1; while (x < n) { while ((x < n) && (a[x] == a[x + 1])) x++; int y = x; while ((x < n) && (a[x] != a[x + 1])) x++; ...
#include <bits/stdc++.h> using namespace std; void readInput() {} void solve() {} priority_queue<pair<int, int>> pq; int n, x, y, res, a[100004], b[100004], T, cnt, vitri[100004]; vector<int> pos[100004], ans; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); readInput(); solve...
#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 MAXLEN = 200; char s[MAXLEN + 1]; int n; void run() { scanf( %d%s , &n, s); n = strlen(s); int ret = 0; for (int at = 0, to = at; at < n; at = to) { if...
#include <bits/stdc++.h> using namespace std; long long n, m, c, l, r, i, j, x1, x2, x3, x, r_y, r_y1, r_y2, r_y3, k, g, sum, maxy, maxx, qy, qx; long long kk; long long fact(long long a) { unsigned long long k = 1, i; for (i = 1; i <= a; i++) k *= i; return k; } int main() { cin >> x1...
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; int cor[n], wro[m]; for (int i = 0; i < n; i++) cin >> cor[i]; for (int i = 0; i < m; i++) cin >> wro[i]; int tl; sort(cor, cor + n); sort(wro, wro + m); int v = max(2 * cor[0], cor[n - 1]); i...
#include <bits/stdc++.h> using namespace std; const int maxn = 500; const int maxm = 500000 + 10; struct Edge { int next, v; Edge() {} Edge(int next, int v) : next(next), v(v) {} } e[maxm << 1]; int n, m, timer, num, len; int head[maxm], cnt; int dfn[maxn], low[maxn], belo[maxn]; bool inst...
#include <bits/stdc++.h> using namespace std; const long long MX = 3009; long long x[MX], par[MX], num[MX], ans = 0; pair<long long, pair<long long, long long> > edg[MX]; void MS(long long v) { par[v] = -1; num[v] = x[v]; } long long FS(long long v) { if (par[v] < 0) return v; return par[v...
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const long long LINF = 0x3f3f3f3f3f3f3f3fll; unordered_map<int, int> dp; int msb(int x) { return __builtin_clz(1) - __builtin_clz(x); } int solve(int mask) { if (mask <= 1) return 0; if (dp.count(mask)) return dp[mask]; in...
#include <bits/stdc++.h> using namespace std; long long int arr[200001]; int cnt[200001]; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); long long int n; bool flag; int T; cin >> T; while (T--) { cin >> n; for (int i = 0; i < n; i++) { ...
#include <bits/stdc++.h> using namespace std; int n, m; int pos, neg, tmp, x, y, len; int main() { scanf( %d%d , &n, &m); pos = 0; neg = 0; for (int i = 0; i < n; ++i) { scanf( %d , &tmp); if (tmp > 0) ++pos; else ++neg; } while (m--) { scanf( %d%d...
#include <bits/stdc++.h> using namespace std; long long int mypow(long long int a, long long int b) { long long int res = 1; while (b) { if (b & 1) res = res * a; b >>= 1; if (b) { a = a * a; } } return res; } long long int modpow(long long int a, long long int b,...
#include <bits/stdc++.h> using namespace std; unordered_map<int, int> Task; unordered_map<int, int> Idle; int main() { ios_base::sync_with_stdio(false); cin.tie(0); int N, K; cin >> N >> K; for (int i = 1; i <= N; i++) { int val; cin >> val; Task[val]++; Idle[i] = val...
#include <bits/stdc++.h> using namespace std; int n, m, x, y, u, v, a[1010], b[1010][1010]; vector<int> vv; int main() { scanf( %d%d , &n, &m); for (int i = 0; i < n; ++i) { scanf( %d%d , &x, &y); a[y]++; b[x][y]++; } for (int i = 0; i < m; ++i) { scanf( %d%d , &x, &y); ...
#include <bits/stdc++.h> using namespace std; const double pi = 3.14159265358979323846; void rw() {} int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); string s, r; long long n, c = 0; cin >> n >> s; for (int i = 0; i < n - 1; i++) { if (s[i] == s[i + 1]) ...
#include <bits/stdc++.h> #pragma comment(linker, /stack:200000000 ) #pragma GCC optimize(2) #pragma G++ optimize(2) using namespace std; constexpr long long N = 2e5 + 9; constexpr long long M = 1e9 + 7; constexpr long long INF = 0x3f3f3f3f3f3f3f3f; constexpr long long INF2 = 0xcfcfcfcfcfcfcfcf; long ...
#include <bits/stdc++.h> using namespace std; const int maxn = 3e5 + 5; const int INF = 0x7fffffff; vector<int> G[maxn]; long long weight[maxn]; long long dp[maxn]; int ans; long long maxsum = -INF; void dfs(int now, int fa) { dp[now] = weight[now]; for (int v : G[now]) { if (v != fa) { ...
#include <bits/stdc++.h> using namespace std; int main() { string s; int i, j, k, n, l, n1, n2, m, m1, m2; cin >> s; l = s.size(); for (i = l - 1; i >= 0; i--) { n = s[i] - 48; m = n; if (m == 0) { cout << YES << endl << 0 << endl; exit(0); } if (n...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int a[105]; int cnt = 0; for (int i = 1; i <= n; i++) cin >> a[i]; for (int i = 2; i <= n - 1; i++) { if (a[i] == 0 && a[i - 1] == a[i + 1] && a[i + 1] == 1) { a[i + 1] = 0; cnt++; } }...
#include <bits/stdc++.h> int product(long long a) { int maxi = 0, mini = 9, x, ans; long long temp = a; while (temp) { x = temp % 10; if (x < mini) mini = x; if (x > maxi) maxi = x; temp /= 10; } if (mini == 0) return 0; ans = mini * maxi; return ans; } using na...
#include <bits/stdc++.h> using namespace std; string rem(string second) { if (second[second.size() - 1] == r ) second.erase(second.size() - 1); return second; } vector<string> split(string second, char delim) { replace(second.begin(), second.end(), delim, ); stringstream ss(second); str...
#include <bits/stdc++.h> using namespace std; int main() { int a, b, r; cin >> a >> b >> r; if (2 * r > min(a, b)) { cout << Second ; } else { cout << First ; } return 0; }
#include <bits/stdc++.h> using namespace std; long long n, j, k, a, b; pair<int, int> c[300005]; map<pair<long long, long long>, long long> m; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n; for (int i = 0; i < n; i++) { cin >> a >> b; c[i] = make_...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n; cin >> n; int ar[n]; int cnt = 0, cnt2 = 0; for (int i = 0; i < n; i++) { cin >> ar[i]; if (ar[i] > 0) cnt += ar[i]; else cnt2 += ar[i]; ...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); int n, u, v, c, a, b, t; cin >> n; long long w[n], A, B, Su[n], SMax = 0; int g[n], S[n], Pa[n]; vector<pair<int, long long>> D[n]; vector<int> T, P; for (int i = 0; i < n; i++) { cin >> w[i...