func_code_string
stringlengths
59
71.4k
#include <bits/stdc++.h> using namespace std; unordered_map<int, int> parent[100005]; unordered_map<int, int> depth[100005]; unordered_map<int, int> memo[100005]; int Find(int node, int color) { if (parent[node][color] == node) return node; parent[node][color] = Find(parent[node][color], color); r...
#include <bits/stdc++.h> using namespace std; int main() { int n, k, z, i, y, x = 1; string line; cin >> n >> k >> line; for (i = 0; i < line.length(); i++) { if (line[i] == G ) { z = i; } if (line[i] == T ) { y = i; } } if (y < z) { k = -k; ...
#include <bits/stdc++.h> using namespace std; int main() { int n, d, t[110], tot = 0; cin >> n >> d; for (int i = 0; i < n; i++) cin >> t[i], tot += t[i]; if (tot + (n - 1) * 10 > d) cout << -1 << endl; else { cout << (n - 1) * 2 + (d - tot - (n - 1) * 10) / 5 << endl; } retu...
#include <bits/stdc++.h> using namespace std; long long x, y, m, aux, rs = 0; void neg() { rs = (-y) / x; rs++; y = y + rs * x; } void rec() { aux = x + y; rs++; if (aux < m) { y = x; x = aux; rec(); } } int main() { cin >> x >> y >> m; aux = max(x, y)...
#include <bits/stdc++.h> using namespace std; const int maxn = 300007; const double eps = 1e-9; int n, m; double C; inline int Read() { register int ch, a, flag; while (ch = getchar(), (ch < 0 || ch > 9 ) && (ch != - )) ; flag = (ch == - ); a = flag ? 0 : ch - 0 ; while (ch =...
#include <bits/stdc++.h> using namespace std; int n; int l; int a[1000007]; int minn[1000007], maxn[1000007], cnt; int cmp(int x, int y) { return x > y; } int main() { scanf( %d , &n); long long ans = 0; for (int i = 1; i <= n; i++) { scanf( %d , &l); int flag = 0; for (int j...
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const long long INFF = 0x3f3f3f3f3f3f3f3fll; const long long M = 1e9 + 7; const long long maxn = 1e5 + 7; const double eps = 0.00000001; long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; } template <typename ...
#include <bits/stdc++.h> using namespace std; const int MN = 200000, INF = 1100000000; int main() { int n; scanf( %d , &n); static int x1[MN], y1[MN], x2[MN], y2[MN]; for (int i = 0; i < n; i++) { scanf( %d%d%d%d , x1 + i, y1 + i, x2 + i, y2 + i); } static int x1l[MN], y1l[MN], x2l[M...
#include <bits/stdc++.h> using namespace std; int d[4][2] = {{0, -1}, {1, 0}, {0, 1}, {-1, 0}}; int ans, k = 0; int egg[1000000]; int n, m, vis[1050][1050]{0}, ma[1050][1050]; void dfs(int x, int y) { for (int i = 0; i < 4; i++) { int xx = x + d[i][0]; int yy = y + d[i][1]; if ((ma[x][...
#include <bits/stdc++.h> using namespace std; map<int, int> f, num; int Q; int find(int x) { if (!f.count(x)) return x; int fa = find(f[x]); num[x] ^= num[f[x]]; return f[x] = fa; } int main() { scanf( %d , &Q); int last = 0; while (Q--) { int opt, l, r, x; scanf( %d ...
#include <bits/stdc++.h> using namespace std; int main() { int j, i, t, e, n; cin >> t; while (t--) { cin >> n; string s; cin >> s; string a, b; a = s; b = s; bool f = 0; a[0] = 1 ; b[0] = 1 ; i = 1; while (s[i] != 1 && i < n) { ...
#include <bits/stdc++.h> using namespace std; long long mod = 1e9 + 7; void solve() { int n; cin >> n; int ar[n], lock[n]; for (int i = 0; i < n; i++) cin >> ar[i]; vector<int> temp, res; bool flag = false; for (int i = 0; i < n - 1; i++) { if (ar[i] > ar[i + 1]) { flag =...
#include <bits/stdc++.h> using namespace std; using i64 = long long int; using ii = pair<int, int>; using ii64 = pair<i64, i64>; int main() { int n; scanf( %d , &n); string s; cin >> s; int maxPhone = n / 11; int eight = 0; for (auto& c : s) if (c == 8 ) eight++; printf(...
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 2; int num[N], n, res[N], a[N]; void ReadData() { cin >> n; for (int i = 0; i < n; ++i) cin >> num[i]; } void Update(int x, int y) { if (x > y) return; ++a[x]; --a[y + 1]; } void Solve() { for (int i = 0; i < n; ++...
#include <bits/stdc++.h> using namespace std; int n, m, a[5][5], sum, add, ex; char c[5][5]; int main() { for (int i = 1; i <= 4; i++) for (int j = 1; j <= 4; j++) { cin >> c[i][j]; if (c[i][j] == x ) { a[i][j] = 4; sum++; } else if (c[i][j] == o ) { ...
#include <bits/stdc++.h> using namespace std; int dp(int a, int b) { if ((a == 1 && b == 1) || b == 0) return 0; return dp(max(b + 1, a - 2), min(b + 1, a - 2)) + 1; } int main() { int n, m; cin >> n >> m; printf( %d , dp(max(n, m), min(n, m))); }
#include <bits/stdc++.h> using namespace std; int main() { int T, d; scanf( %d , &T); while (T--) { scanf( %d , &d); double a = 0, b = 0; double x = d * d - 4 * d; if (x < 0) { printf( N n ); continue; } else { a = (d - sqrt(x)) / 2.0; b = d ...
#include <bits/stdc++.h> using namespace std; int main() { int n, i = 0; string str; scanf( %d , &n); cin >> str; if (n % 2 == 0) { i = 2; printf( %c%c , str[0], str[1]); } else { i = 3; printf( %c%c%c , str[0], str[1], str[2]); } for (; i < n; i += 2) { ...
#include <bits/stdc++.h> using namespace std; vector<pair<int, int> > grafo[212345]; int marc[212345], dp[212345], ans[212345], ansmin = 1e9; void dfs(int x) { marc[x] = 1; for (int i = 0; i < grafo[x].size(); i++) { int viz = grafo[x][i].first; int type = grafo[x][i].second; if (marc[...
#include <bits/stdc++.h> using namespace std; const int N = 100010; int n, m, i, j, k, a[N], u, v, q, x; vector<int> b[N]; long long ans; long long f(int x) { return 1LL * b[x].size() * (a[x] - b[x].size()); } int main() { scanf( %d%d , &n, &m); for (i = 1; i <= m; i++) { scanf( %d%d , &u, &...
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 9; int n; int fs[maxn]; int pj[maxn]; long long ansji, ansou; void solve() { int i; for (i = 1; i <= n; ++i) fs[i] += fs[i - 1]; for (i = 1; i <= n; ++i) { pj[i] = pj[i - 1] + (fs[i] & 1); } for (i = 1; i <= n; ...
#include <bits/stdc++.h> using namespace std; int main() { long int i, m, n; double add, ans, t1, t2; scanf( %ld%ld , &m, &n); for (i = 1; i <= m; i++) { t1 = (double)i / m; t2 = (double)(i - 1) / m; add = i * (pow(t1, n) - pow(t2, n)); ans += add; } printf( %.7lf , a...
#include <bits/stdc++.h> using namespace std; int a[110], n = 0, res[1010], ch = 0, k = 0; string s; int main() { cin >> s; memset(a, 0, sizeof a); memset(res, 0, sizeof res); for (int i = 0; i < (int)s.length(); ++i) if (s[i] != , ) { a[n] *= 10; a[n] += (int)(s[i] - 0 )...
#include <bits/stdc++.h> using namespace std; const long long sz = 10000001; bool vis[sz]; int cs[sz], a[sz], n, m; void run() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); } int main() { run(); cin >> n; int x; for (int i = 0; i < n; i++) { cin >> x;...
#include <bits/stdc++.h> using namespace std; const int maxn = 100; char ch[maxn][maxn]; int main() { int n; scanf( %d , &n); for (int i = 0; i <= n + 1; i++) { for (int j = 0; j <= n + 1; j++) { ch[i][j] = # ; } } for (int i = 1; i <= n; i++) { getchar(); fo...
#include <bits/stdc++.h> using namespace std; long long int ma = -1, mi = 1000000000000000; inline long long int gcd(long long int a, long long int b) { return b ? gcd(b, a % b) : a; } inline long long int lcm(long long int a, long long int b, long long int MOD) { return a / gcd(a, b) * b % MOD; } ...
#include <bits/stdc++.h> using namespace std; int main() { long int var; scanf( %ld , &var); if (var >= 0) cout << var; else { int a, b; a = var % 10; var /= 10; b = var % 10; var /= 10; if (a > b) var = var * 10 + a; else var = var * 1...
#include <bits/stdc++.h> using namespace std; vector<pair<int, int> > v; int n, r, m; bool cmp(const pair<int, int>& a, const pair<int, int>& b) { return a.first * a.first + a.second * a.second > b.first * b.first + b.second * b.second; } inline int get_dis(const int& first, const int& second...
#include <bits/stdc++.h> using namespace std; long long gcd(long long a, long long b) { if (a > b) swap(a, b); if (a == 0) return b; return gcd(b % a, a); } long long powerMod(long long x, long long y) { long long res = 1; x %= 1000000007; while (y > 0) { if (y & 1) res = (res * x)...
#include <bits/stdc++.h> using namespace std; int main() { int c = 0; int n; cin >> n; string s; for (int i = 0; i < n; i++) { cin >> s; if (s == Cube ) c += 6; else if (s == Tetrahedron ) c += 4; else if (s == Octahedron ) c += 8; else if...
#include <bits/stdc++.h> using namespace std; int n, tot, m, l, r, len; char c; int po[400005], ha[400005], ys[400005], fi[400005], la[400005]; int s[400005], id[400005], t[400005], sum[400005], it[400005]; struct pi { int num, hai; }; pi find(int li, int ri) { int f1 = 0, f2 = 0, lp = li, rp = ...
#include <bits/stdc++.h> int n, m, a[210], f[210][210][1010], ans; inline void up(int &x, int y) { if ((x += y) >= 1000000007) x -= 1000000007; } int main() { scanf( %d%d , &n, &m); for (int i = 1; i <= n; i++) scanf( %d , &a[i]); std::sort(a + 1, a + n + 1); f[1][1][0] = f[1][0][0] = 1; ...
#include <bits/stdc++.h> using namespace std; int n, a, b, k, h[200010]; int main() { scanf( %d%d%d%d , &n, &a, &b, &k); int ans = 0, x; for (int i = 1; i <= n; i++) { scanf( %d , &x); if (x % (a + b) == 0) x -= (x / (a + b) - 1) * (a + b); else x -= (x / (a + b)) * (...
#include <bits/stdc++.h> 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) { cerr << *it << = << a << , ; err(++it, args...); } namespace fastIO { bool IOerror = 0; ...
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; long long qpow(long long x, long long y) { long long re = 1, base = x % mod; while (y) { if (y & 1) re = (re * base) % mod; base = (base * base) % mod; y >>= 1; } return re; } struct node { int to, w; ...
#include <bits/stdc++.h> using namespace std; map<int, int> p; int a[100005]; int a1[100005], a2[100005]; int n, flag, pl = 1; int main() { scanf( %d , &n); for (int i = 1; i <= n; i++) { scanf( %d , &a[i]); if (p[a[i]] == 0) p[a[i]] = pl++; } for (int i = 1; i <= n; i++) { ...
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const double PI = 3.14159265358979323846; const int MAXN = 1000005; int n, x[MAXN], y[MAXN], r[MAXN]; int d[MAXN]; vector<int> G[MAXN]; inline double dis(double x1, double y1, double x2, double y2) { double d = (x1 - x2) * (x1...
#include <bits/stdc++.h> using namespace std; using ll = long long; constexpr ll mod = 1e9 + 7; template <typename A, typename B> string to_string(pair<A, B> p); template <typename A, typename B, typename C> string to_string(tuple<A, B, C> p); template <typename A, typename B, typename C, typename D> ...
#include <bits/stdc++.h> using namespace std; template <class T> typename T::value_type arr_sum(const T& v, int n) { typename T::value_type sum = 0; for (int i = 0; i < n; ++i) sum += v[i]; return sum; } struct Sync_stdio { Sync_stdio() { cin.tie(NULL); ios_base::sync_with_stdio(fa...
#include <bits/stdc++.h> using namespace std; const int inf = 0x3f3f3f3f; const long long infll = 0x3f3f3f3f3f3f3f3fLL; inline long long read() { long long x = 0, f = 1; char ch = getchar(); while (ch < 0 || ch > 9 ) { if (ch == - ) f = -1; ch = getchar(); } while (ch >= 0 ...
#include <bits/stdc++.h> using namespace std; ifstream fin( input.txt ); ofstream fout( output.txt ); const long long mod = 1000000000 + 7; const int maxn = 500 + 10; const int inf = 1000000000; int n, m, par[maxn][maxn][2], dist[maxn][maxn][2]; vector<int> v[maxn], e[2]; queue<pair<pair<int, int>, in...
#include <bits/stdc++.h> using namespace std; const long long MAXN = 1e7 + 1; char used[MAXN] = {0}; int lowest_divisor[MAXN]; int numbers[2][MAXN], numbers2[2][MAXN]; void sieve() { for (int i = 2; i < MAXN; i += 2) { used[i] = 1; lowest_divisor[i] = 2; } for (long long i = 3; i < M...
#include <bits/stdc++.h> using namespace std; using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long n, otv = 0, otv1 = 0; cin >> n; vector<long long> v(n); for (long long j = 0; j < n; j++) { cin >> v[j]; } for (long long j = 1...
#include <bits/stdc++.h> using namespace std; long long int mod = 1e9 + 7; const double error = 1e-10; const double PI = acos(-1); inline long long int MOD(long long int x, long long int m = mod) { long long int y = x % m; return (y >= 0) ? y : y + m; } const int inf = INT_MAX; const long long i...
#include <bits/stdc++.h> using namespace std; int n, x1, x2; struct server { int c, ind; bool b1, b2; int r1, r2; } * *srv; void qs(server** a, int l, int r) { int i = l, j = r; int p = a[(l + r) >> 1]->c; do { while (i < r && a[i]->c < p) i++; while (j > l && a[j]->c > p) ...
#include<bits/stdc++.h> using namespace std; #define imax(a,b) (((a)>(b))?(a):(b)) #define imin(a,b) (((a)<(b))?(a):(b)) #define mp make_pair typedef long long ll; const int N = 3e5 + 10; typedef pair<int, int> intp; int T, n, dfstime, L[N], R[N], ans, num; vector<int> sd[2][N]; set<intp...
#include <bits/stdc++.h> bool vis[1001][1001], ret[1001][1001]; const int dx[] = {1, 1, 0, -1, -1, -1, 0, 1}; const int dy[] = {0, 1, 1, 1, 0, -1, -1, -1}; int main() { int n, m; scanf( %d %d , &n, &m); for (int i = 1; i <= n; ++i) { scanf( n ); for (int j = 1; j <= m; ++j) { ch...
#include <bits/stdc++.h> using namespace std; const int N = 255; double f[N][N * N]; int x, k, p; int main() { scanf( %d%d%d , &x, &k, &p); for (int i = 0; i <= k; i++) { int xx = x + i, cnt = 0; while (xx % 2 == 0) { xx /= 2; cnt++; } f[0][i] = cnt; } f...
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; using ull = unsigned long long; template <typename T1, typename T2> inline void chkmin(T1 &x, const T2 &y) { if (x > y) x = y; } template <typename T1, typename T2> inline void chkmax(T1 &x, const T2 &y) { ...
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const int maxn = 5000; int n, fir[maxn + 10], tmpN; int nedge, to[2 * maxn + 10], nex[2 * maxn + 10], dis[2 * maxn + 10]; bool no[2 * maxn + 10]; long long ans, dp[maxn + 10], num[maxn + 10], allDis[maxn + 10]; int p[2]; inline ...
#include <bits/stdc++.h> using namespace std; int main() { int n, sum = 0, cnt = 0; cin >> n; int a[n + 1][n + 1]; vector<int> v; vector<int> v1; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { cin >> a[i][j]; } } int no = 0; for (int i = 0; i < n;...
#include <bits/stdc++.h> using namespace std; int n, K, b[40004], a[40004]; int Wl, Wl2, w[40004], lg[40004], inv[40004] = {1, 1}; int Pow(int b, int k) { int r = 1; for (; k; k >>= 1, b = 1ll * b * b % 998244353) if (k & 1) r = 1ll * r * b % 998244353; return r; } void init(int n) { f...
#include <bits/stdc++.h> using namespace std; double d(long long int x, long long int y, long long int x1, long long int y1) { return sqrt((x - x1) * (x - x1) + (y - y1) * (y - y1)); } int main() { ios_base::sync_with_stdio(0); cin.tie(0); pair<long long int, long long int> adil; pair<long l...
#include <bits/stdc++.h> using namespace std; int main() { int n, m, k; cin >> n >> m >> k; int arr[n]; for (int i = 0; i < n; i++) { cin >> arr[i]; } int suma = 0, ans = 0, count = 0; for (int i = n - 1; i >= 0; i--) { if (suma + arr[i] <= k) suma = suma + arr[i]; ...
#include <bits/stdc++.h> using namespace std; template <class T> inline void rd(T &x) { x = 0; char c = getchar(); int f = 1; while (!isdigit(c)) { if (c == - ) f = -1; c = getchar(); } while (isdigit(c)) x = x * 10 - 0 + c, c = getchar(); x *= f; } template <class T...
#include <bits/stdc++.h> using namespace std; const int BUF = 200005; const long long INF = 1LL << 61; int n; long long toAdd; long long arrive[BUF]; int maxOrder[BUF]; void read() { cin >> n >> toAdd; for (int i = 0; i < n; ++i) { cin >> arrive[i]; } for (int i = 0; i < n; ++i) { ...
#include <bits/stdc++.h> const long long int M = 1e9 + 7; using namespace std; bool visit[100000]; vector<int> G[100000]; void dfs1(int v, stack<int> &s) { visit[v] = true; for (int i = 0; i < G[v].size(); i++) { int c = G[v][i]; if (!visit[c]) dfs1(c, s); } s.push(v); } void d...
#include <bits/stdc++.h> struct coor { int x[3]; }; int x[6][3] = {0, 1, 2, 0, 2, 1, 1, 0, 2, 1, 2, 0, 2, 0, 1, 2, 1, 0}; bool judge(coor a, coor b) { bool flag = 0; b.x[2] += 18; if (b.x[2] < a.x[2]) { flag = 1; } else if (b.x[2] > a.x[2]) { } else if (a.x[2] == b.x[2]) { if...
#include <bits/stdc++.h> const long long mn = 1000000009; long long x, n, m; long long minu(long long val) { if (val == 0) return mn - 1; return val - 1; } long long getmod(long long val) { long long ret = 1; for (long long i = 0; i < val; i++) { ret *= 2; ret %= mn; } retu...
#include <bits/stdc++.h> using namespace std; struct Grass { int sizee; char dir; } a[100005]; int n; bool flag[100005]; int main() { cin >> n; for (int i = 1; i <= n; i++) { cin >> a[i].dir; } for (int i = 1; i <= n; i++) { cin >> a[i].sizee; } int nowx = 1; ...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(NULL); cin.tie(NULL); string s; cin >> s; long long int n, i, j, cnt; n = s.length(); cnt = j = 0; for (i = 0; i < n; i++) { if (s[i] == 1 ) { cnt++; j = i; } } i...
#include <bits/stdc++.h> using namespace std; inline int leer() { 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;...
#include <bits/stdc++.h> int n; int main() { while (EOF != scanf( %d , &n)) { if (n == 5) printf( 1 n ); else printf( %d n , n % 3 + 1); } return 0; }
#include <bits/stdc++.h> #pragma comment(linker, /STACK:64000000 ) using namespace std; const int maxn = 3000000; const long long MANY = 1000000; int main() { long long n; cin >> n; while (n % 3 == 0) n /= 3; long long ans = (n % 3 ? 1 : 0) + n / 3; cout << ans << endl; return 0; } ...
#include <bits/stdc++.h> using namespace std; int toBinary(int num) { vector<int> vec; while (num > 0) { vec.push_back(num % 2); num = num / 2; } while (vec.size() < 8) { vec.push_back(0); } int temp = 0; for (int i = 0; i < vec.size(); i++) { temp += vec[7 - i] *...
#include <bits/stdc++.h> int k, x, y; using namespace std; int main() { scanf( %d , &k); x = 1000000 - k % 2000; y = (k + x - 2000 * x) / 2000; printf( 2000 n ); for (int i = 1; i <= 1998; i++) printf( 0 ); printf( %d %d n , y, x); }
#include <bits/stdc++.h> using namespace std; const int N = 100005; const long double INF = 1e18; const long double PI = acos(-1.0); int n; pair<long long, long long> o, origin, p[N]; long long r_1 = 0; long double r_2 = INF; long long sqDist(pair<long long, long long> a, pair<long long, long long> b)...
#include <bits/stdc++.h> using namespace std; void read() {} int main() { read(); ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int t = 1; while (t--) { int n, m; cin >> n >> m; string s; int a[n][m]; for (int i = 0; i < n; i++) { cin >> s...
#include <bits/stdc++.h> using namespace std; const long double Pi = 3.14159265359; const long long MOD = (long long)1e9 + 7; const long long MAXN = (long long)1e6 + 10; const long long INF = (long long)9223372036854775; const long double EPS = (long double)1e-8; long long dp[MAXN]; long long dpx[MAXN];...
#include <bits/stdc++.h> using namespace std; int a[300010]; int main() { int n; cin >> n; for (int i = 1; i <= n; ++i) { scanf( %d , &a[i]); } long long ans = 0; vector<int> v; for (int i = 1; i <= n; ++i) { ans += a[i] / 2; if (a[i] % 2 != 0) { v.push_back(i...
#include <bits/stdc++.h> using namespace std; const double pi = acos(-1.0); const double eps = 1e-11; void fastIO() { std::ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); } int dig[10]; int main() { fastIO(); long long ans = 0; long long k; string s; cin >> k >> s; ...
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 5, B = 350, Mod = 998244353; int n, lim, siz, block_cnt, cnt[maxn], a[maxn], b[maxn], sum_b[1005], sum_f[1005][1005], f[maxn]; vector<int> pos[maxn]; void cal(int w) { memset(sum_f[w], 0, sizeof sum_f[w]); int tmp = 0; for ...
#include <bits/stdc++.h> using namespace std; long long x, y, z, f[5010][5010], lsg, n, xx, yy, zz; signed main() { cin >> x >> y >> z; n = max(x, max(y, z)); lsg = 998244353; for (long long i = 0; i <= n; i++) f[0][i] = f[i][0] = 1; for (long long i = 1; i <= n; i++) for (long long j = ...
#include <bits/stdc++.h> using namespace std; const int MAXN = 1010, MAXM = 14, MAXS = MAXM * MAXM, MOD = 1e9 + 9; void setmax(int &x, int y) { if (x < y) { x = y; } } void add(int &x, int y) { x = (x + y) % MOD; } int N, M; string str[MAXM]; map<string, int> mp; int ind; int dp[MAXN][...
#include <bits/stdc++.h> using namespace std; struct query { int en, ll, rr, ind; }; int tr[3][3000000], mx, h, w, n, m, ok[400000]; vector<int> vrx[300000], vry[300000]; vector<query> qrx[300000], qry[300000]; void build(int x, int l, int r, int tp) { if (l == r) { tr[tp][x] = 300000; ...
#include <bits/stdc++.h> using namespace std; queue<char> qq[2][310][310]; vector<vector<int> > res1; vector<vector<int> > res2; void move(int x, int y, int p, int q, int k) { qq[k][p][q].push(qq[k][x][y].front()); qq[k][x][y].pop(); if (k) res2.push_back(vector<int>({p, q, x, y})); else...
#include <bits/stdc++.h> using namespace std; inline long long cal(int a, int b, int c, int l) { int x = min(l, a - b - c); if (x < 0) return 0; return (long long)(x + 2) * (x + 1) / 2; } int main() { int a, b, c, l; cin >> a >> b >> c >> l; long long ans = (long long)(l + 1) * (l + 2) *...
#include <bits/stdc++.h> using namespace std; const int K = 110; const int MOD = 998244353; const int PHI = MOD - 1; int _w; void add_phi(int &a, int b) { a += b; a -= a >= PHI ? PHI : 0; } int pow_mod(int a, int b, int p) { if (!b) return 1; long long rtn = pow_mod(a, b >> 1, p); rt...
// Problem: A. Meximization // Contest: Codeforces - Codeforces Round #708 (Div. 2) // URL: https://codeforces.com/contest/1497/problem/A // Memory Limit: 256 MB // Time Limit: 1000 ms // // Powered by CP Editor (https://cpeditor.org) #include <bits/stdc++.h> using INT=int; //#define int long long...
#include <bits/stdc++.h> #pragma GCC optimize(2) using namespace std; inline int read() { int x = 0, w = 1; char c = getchar(); while (c < 0 || c > 9 ) { if (c == - ) w = -1; c = getchar(); } while (c <= 9 && c >= 0 ) { x = (x << 1) + (x << 3) + c - 0 ; c = getc...
#include <bits/stdc++.h> using namespace std; int a[105]; int b[105]; bool cmp(int a, int b) { return a > b; } int main() { int n, x = 0, y = 0, m; int cnt = 0; scanf( %d , &n); for (int i = 1; i <= n; i++) { scanf( %d , &m); for (int j = 1; j <= m; j++) { scanf( %d , &a[j]...
#include <bits/stdc++.h> using namespace std; const int N = 3e5 + 10; int n, x1, x2; pair<int, int> c[N], f[2]; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n >> x1 >> x2; for (int i = 0; i < n; i++) cin >> c[i].first, c[i].second = i; sort(c, c + n); ...
#include <bits/stdc++.h> using namespace std; map<string, int> H; string s; int l, rs; void Read_Input() { cin >> s; l = s.length(); rs = 0; int i, j, k; for (i = 0; i < l; i++) for (j = i + 1; j < l; j++) { for (k = 0; j + k < l && s[i + k] == s[j + k]; k++) ; ...
#include <bits/stdc++.h> using namespace std; int main() { int q, n, sum; cin >> q; while (q--) { cin >> n; int m = n; sum = 0; while (n--) { int x; cin >> x; sum += x; } double y = (double)sum / m; int rs = y; if (y == rs) { ...
#include <bits/stdc++.h> using namespace std; const int maxn = 205; int n, k; int main() { scanf( %d , &k); if (k == 1) { printf( YES n2 1 n1 2 n ); return 0; } if (k % 2 == 0) { printf( NO n ); return 0; } printf( YES n ); printf( %d %d n , 2 * (k + 2), k * (...
#include <bits/stdc++.h> using namespace std; long long Min(long long a, long long b) { return a < b ? a : b; } bool cmp(long long a, long long b) { return a > b; } long long a[3]; int main() { while (~scanf( %lld%lld%lld , &a[0], &a[1], &a[2])) { long long ans = 0; sort(a, a + 3, cmp); ...
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 10; const int LG = 20; int n, a[N], u, v; long long dp[LG][N][2]; long long sdp[LG][N][2]; long long ans, ans2; vector<int> G[N]; bool mark[N]; int h[N]; void input(); void find_ans(); void dfs(int, int); int main() { inpu...
#include <bits/stdc++.h> using namespace std; int main() { long long t; cin >> t; while (t--) { long long n, p, k, i; cin >> n >> p >> k; long long a[n]; for (i = 0; i < n; i++) cin >> a[i]; long long dp[n + 1]; dp[0] = 0; sort(a, a + n); for (i = 1; i <= ...
#include <bits/stdc++.h> const int maxn = 1e6 + 9, mod = 998244353, inf = 0x3f3f3f3f; int Read() { int x(0), f(1); char c = getchar(); while (c < 0 || c > 9 ) { if (c == - ) f = -1; c = getchar(); } while (c >= 0 && c <= 9 ) { x = (x << 3ll) + (x << 1ll) + c - 0 ; ...
#include <bits/stdc++.h> using namespace std; const int maxn = 1e4 + 10; const int INF = 1e9; int n; char s[maxn]; int P, M; struct node { int l, r; int left, right; } Tree[maxn]; int cur; vector<int> stk; void addNode(int x, bool flag) { ++cur; Tree[cur].l = x; if (!stk.empty(...
#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}; long long bigmod(long long a, long long b, long long c) { if (b == 0) return 1 % c; long long x = bigmod(a, b / 2, c); ...
#include <bits/stdc++.h> using namespace std; long long min(long long a, long long b) { if (a > b) return b; return a; } long long max(long long a, long long b) { if (a > b) return a; return b; } long long fact[32600]; int main() { int n, len, l; cin >> n; len = (int)(sqrt(n));...
#include <iostream> using namespace std; int t, n, f[100005]; long long k; void Solve() { if (n < 63 && (1ll<<(n-1)) < k) { cout << -1 n ; return; } int p = max(1, n - 62); long long power = (1ll<<(n-p)); for(int i=1; i<p; ++i) f[i] = i; for(int i=p; i<=n; ++i) { powe...
#include <bits/stdc++.h> using namespace std; int main() { int l, n; cin >> n >> l; int a; int sum[100]; for (int i = 0; i < 100; ++i) sum[i] = 0; memset(sum, 0, 100); for (int i = 0; i < n; ++i) { cin >> a; for (int j = l; j <= 100; ++j) { sum[j - 1] = sum[j - 1] + (...
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 10; vector<int> a[maxn]; string s; int i, ma = -1, ans = 0, f = 1; int main() { cin >> s; for (i = 0; i < s.size(); i++) { if (s[i] == 0 ) a[++ans].push_back(i); else { if (ans == 0) { f = 0; ...
#include <bits/stdc++.h> #pragma GCC optimize( O3 ) #pragma GCC optimize( unroll-loops ) #pragma GCC optimize( no-stack-protector ) #pragma GCC target( sse,sse2,ssse3,sse3,sse4,popcnt,avx,mmx,abm,tune=native ) using namespace std; namespace output { void __(short x) { cout << x; } void __(unsigned x) { ...
#include <bits/stdc++.h> using namespace std; template <class T> inline T bigmod(T p, T e, T M) { long long int 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...
#include <bits/stdc++.h> using namespace std; int main() { long long int t; cin >> t; while (t--) { long long int n; cin >> n; long long int a[n]; set<long long int> s; for (long long int i = 0; i < n; i++) { cin >> a[i]; s.insert(a[i]); } cout <...
#include <bits/stdc++.h> using namespace std; inline void read(long long &x) { x = 0; long long f = 1; char ch = getchar(); while (ch != 45 && (ch > 9 || ch < 0 )) ch = getchar(); if (ch == 45) { f = -1, ch = getchar(); } while (ch <= 9 && ch >= 0 ) { x = x * 10 + ch - ...
#include <bits/stdc++.h> using namespace std; int a, b, c, x, y, z, st; int proc(int l, int r) { if (l > r) return (l - r) / 2; return l - r; } int main() { scanf( %d%d%d , &a, &b, &c); scanf( %d%d%d , &x, &y, &z); st = 0; st += proc(a, x); st += proc(b, y); st += proc(c, z); ...