func_code_string
stringlengths
59
71.4k
#include <bits/stdc++.h> #pragma GCC optimize( Ofast ) #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native ) #pragma GCC optimize( -ffloat-store ) using namespace std; clock_t time_p = clock(); void aryanc403() {} const long long int INF = 0xFFFFFFFFFFFFFFFL; long long int seed; ...
#include <bits/stdc++.h> using namespace std; inline char get(void) { static char buf[100000], *S = buf, *T = buf; if (S == T) { T = (S = buf) + fread(buf, 1, 100000, stdin); if (T == S) return EOF; } return *S++; } inline void read(int& x) { static char c; x = 0; for (c ...
#include <bits/stdc++.h> using namespace std; const long long INF = (long long)2e18; const int N = 1005; char s[N]; int lcp[N][N]; vector<pair<int, int>> segs; bool cmp(pair<int, int> a, pair<int, int> b) { int alen = a.second - a.first; int blen = b.second - b.first; int clen = min(alen, blen...
#include <bits/stdc++.h> using namespace std; template <typename T> using V = vector<T>; const long long int mod = 1000000007; struct sb { size_t c, ind; unsigned long long int a, b; }; bool cmp(sb a, sb b) { return a.c < b.c; } struct s { unsigned long long int sub; size_t lastsub; ...
#include <bits/stdc++.h> using namespace std; const int32_t INFint = 1e9; const long long INFll = 1e18; int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); ; long long t; cin >> t; while (t--) { long long n; cin >> n; long long arr[n]; for ...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); map<pair<string, string>, int> map_count; vector<int> cost_list; int n, a, b, k, f; string s, t, prv = ; cin >> n >> a >> b >> k >> f; for (int cost, i = 0; i < n; i++) { cin >> s >> t; ...
#include <bits/stdc++.h> using namespace std; vector<vector<int>> compos; int complement_component(vector<vector<int>> &g) { int n = g.size(), ans = 0; set<int> S; for (int i = 0; i < n; ++i) S.insert(i); while (S.size()) { ++ans; int theCompo = 0; queue<int> q; q.push(*S.b...
#include <bits/stdc++.h> using namespace std; long long int n; vector<long long int> a, b; struct segmentTree { vector<long long int> t; segmentTree() { t.resize(4 * n); } void add(long long int ind, long long int x, long long int v = 0, long long int tl = 0, long long int tr = n) { ...
#include <bits/stdc++.h> using namespace std; const long long MAX = 1e18; long long k, n, c; string s; long long p[26][26]; long long f[105][105][26]; char x, y; signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> s >> k >> n; for (long long i = 1; i <= n; i...
#include <bits/stdc++.h> using namespace std; int n, m, k, mx, a[100][100], dp[100][100], me[100], inf = -1e15; int sub(int a, int b) { return (((a - b) % k) + k); } signed main(void) { ios_base::sync_with_stdio(0); cin.tie(0); cin >> n >> m >> k; for (int i = 1; i <= n; i++) for (int j = ...
#include <bits/stdc++.h> #pragma GCC optimize(2) #pragma GCC optimize(3) #pragma GCC optimize( Ofast ) #pragma GCC optimize( inline ) #pragma GCC optimize( -fgcse ) #pragma GCC optimize( -fgcse-lm ) #pragma GCC optimize( -fipa-sra ) #pragma GCC optimize( -ftree-pre ) #pragma GCC optimize( -ftree-vrp )...
#include <bits/stdc++.h> using namespace std; int main() { long long n, m, f[10] = {0}, x, i; long long ans, z; scanf( %lld , &n); scanf( %lld , &m); for (i = 0; i < n; i++) { scanf( %lld , &x); f[x - 1]++; } ans = (n * (n - 1)) / 2; for (i = 0; i < m; i++) { z = (f...
#include <bits/stdc++.h> using namespace std; bool IsPrime(int n) { if (n == 1) return false; for (int d = 2; d * d <= n; d++) { if (n % d == 0) return false; } return true; } int main() { int n; cin >> n; int count = 0; while (n > 0) { int j = 0; int k = n; ...
#include <bits/stdc++.h> using namespace std; const int MOD = 998244353, N = 1e6 + 5; long long fact[N], d[N]; long long f(int x) { if (x == 0) return 1; if (fact[x] != 0) return fact[x]; return fact[x] = (x * f(x - 1)) % MOD; } int main() { d[1] = 1; for (int i = 2; i < N; i++) { ...
#include <bits/stdc++.h> using namespace std; template <typename T> void chkmin(T &a, T b) { a = min(a, b); } template <typename T> void chkmax(T &a, T b) { a = max(a, b); } inline int fread(void) { int ret = 0, op = 1; char ch = getchar(); for (; !isdigit(ch); ch = getchar()) ...
#include <bits/stdc++.h> using namespace std; bool cmp(const pair<long long int, long long int> &a, const pair<long long int, long long int> &b) { return a.second < b.second; } int main() { long long int n, k, ai, bi, total = 0, ans = 0; vector<long long int> a; vector<pair<long long ...
#include <bits/stdc++.h> using namespace std; int n, m, a[101][101]; int main() { cin >> n >> m; if (n == 1 && m == 1) cout << 1 ; else if (n == 2 && m == 2) cout << -1 ; else if ((n == 1 && m <= 3) || (m == 1 && n <= 3)) cout << -1 ; else { int k = n * m; for ...
#include <bits/stdc++.h> using namespace std; void solve() { int n; scanf( %d n , &n); string a, b; getline(cin, a); getline(cin, b); int q(0); map<pair<char, char>, int> SET; map<char, int> have; for (int i(0), _l((int)(n)-1); i <= _l; ++i) { if (a[i] != b[i]) { ++...
#include <bits/stdc++.h> using namespace std; int a[200005], b[200005]; int nx[500005]; int n, m; void getnext() { nx[0] = -1; int j = 0, k = -1; while (j < m) { if (k == -1 || b[j] == b[k]) nx[++j] = ++k; else k = nx[k]; } } int KMP() { int ret = 0; int...
#include <bits/stdc++.h> using namespace std; const int maxn = 1010; int N; long long c[4][maxn][maxn]; void upd(int p, int i, int j, long long x) { int jj = j; while (i <= N) { j = jj; while (j <= N) c[p][i][j] ^= x, j += j & (-j); i += i & (-i); } } long long get(int p, int...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<long long int> v(n); for (int i = 0; i < n; i++) { cin >> v[i]; } int i; for (int i = 0; i < n; i++) { while (v[i] % 2 == 0) { v[i] /= 2; } while (v[i] % 3 == 0) { v...
#include <bits/stdc++.h> using namespace std; long long max(long long a, long long b) { if (a < b) return b; return a; } long long min(long long a, long long b) { if (a < b) return a; return b; } bool okay(vector<long long> &v, long long d, long long k) { long long sum = 0; priority_...
#include <bits/stdc++.h> using namespace std; namespace GR1 { vector<int> solve(int N, int num_exact_matches, int num_common, const vector<int>& B) { vector<queue<int> > pos(N + 2); for (int i = 0, _n = (N); i < _n; ++i) { int b = B[i]; pos[b].push(i); } int missing...
#include <bits/stdc++.h> using namespace std; int N; bool v[2001]; vector<int> G[2001]; int cnt = 0; int a[2001][2001]; int Dfn[2001], Low[2001]; int Dindex = 0; int Bcnt; bool instack[2001]; int Sta[2001]; int top = -1; void add(int x, int y) { G[x].push_back(y); } void read() { scanf( ...
#include <bits/stdc++.h> using namespace std; const int N = 4e6 + 10; int n, m; int a[N]; int find(int x) { for (int i = 1; i <= n; i++) { if (a[i] == x) return i; } } vector<int> v; signed main() { int x, y, z, T; cin >> T; while (T--) { scanf( %d , &n); for (int i...
#include <bits/stdc++.h> using namespace std; int n, t, c, d[555555], res = 0, ll = -1; bool try_ans(int k) { if (d[n - 1] > k) return false; int last = 0, now = 0, res, l2 = -1; vector<pair<int, int> > aa; for (int i = 0; i < n; i++) { if (d[i] > k) { l2 = i; if (!last) aa.p...
#include <bits/stdc++.h> using namespace std; template <typename T> void read(T& x) { x = 0; int fl = 1; char ch = getchar(); while (ch < 0 || ch > 9 ) { if (ch == - ) fl = -1; ch = getchar(); } while (ch >= 0 && ch <= 9 ) { x = (x << 1) + (x << 3) + ch - 0 ; ...
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; const int MN = 200010; int exp(int x, int n) { int ret = 1; while (n) { if (n & 1) ret = 1LL * ret * x % mod; x = 1LL * x * x % mod; n >>= 1; } return ret; } int inv(int x) { return exp(x, mod - 2); } ...
#include <bits/stdc++.h> using namespace std; const int MOD = 1e9 + 7; const int MAXN = 1e5 + 10; bool bd[MAXN]; int n; int a[MAXN]; vector<pair<int, int>> sol; pair<int, int> coord(pair<int, int> p) { return {(n - 1 - p.second), p.first}; } int main(void) { scanf( %d , &n); for (int i = 0; i ...
#include <bits/stdc++.h> using namespace std; string moves[] = { MW , LW , LM }; int sequence[25]; void listify(int k, int n) { for (int i = 0; i != n; ++i) { sequence[i] = k % 3; k /= 3; } } void solve(int n, vector<vector<int> >& V) { int n1 = n / 2; int n2 = n - n1; int ...
#include <bits/stdc++.h> using namespace std; long long powmod(long long a, long long b) { long long res = 1; a %= 1000000007; for (; b; b >>= 1) { if (b & 1) res = res * a % 1000000007; a = a * a % 1000000007; } return res; } template <typename T> inline bool chkmin(T &a, cons...
#include <bits/stdc++.h> using namespace std; const int MAXS = 200005; const int MAXN = 100005; const int B = 75; template <typename T> inline void read(T &AKNOI) { T x = 0, flag = 1; char ch = getchar(); while (!isdigit(ch)) { if (ch == - ) flag = -1; ch = getchar(); } whil...
#include <bits/stdc++.h> using namespace std; int morh[100001], parent[100001], pos[100001], temp = 0, ans = 0; int calculate(int i) { int posi = i, ans = 0; while (posi != 0) { if (pos[posi] > 1) break; else { posi = parent[posi]; ans++; } } return ans; ...
#include <bits/stdc++.h> using namespace std; struct three { int f, s, w; }; map<pair<int, int>, bool> mp; int parent[200005], pat[200005]; three A[200005]; int time_in[200005], time_out[200005]; vector<vector<int> > dp(200005); vector<vector<int> > dp_mx(200005); vector<vector<pair<int, int> > ...
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; const int maxn = 2e5 + 50; const long long inf = 1e17; int t; void get() { fflush(stdout); scanf( %d , &t); for (int i = 1; i <= t; i++) scanf( %*s ); } int main() { do { puts( next 0 1 ), get(); put...
#include <bits/stdc++.h> using namespace std; const int max_n = 2e5 + 5; long long ans[max_n]; struct no { long long p, val; }; vector<no> v; bool operator<(const no &x, const no &y) { return x.p < y.p; } int main() { int n; scanf( %d , &n); for (int i = 1; i <= n; i++) { long long...
#include <bits/stdc++.h> using namespace std; template <typename T> void read(T& x) { x = 0; char ch = getchar(); long long f = 1; while (!isdigit(ch)) { if (ch == - ) f *= -1; ch = getchar(); } while (isdigit(ch)) { x = x * 10 + ch - 48; ch = getchar(); } ...
#include <bits/stdc++.h> using namespace std; long long a[100005]; long long c[100005]; int main() { int n, k; scanf( %d %d , &n, &k); for (int i = 1; i <= n; i++) { scanf( %lld , &a[i]); a[i] -= k; } long long A; scanf( %lld , &A); priority_queue<long long, vector<long l...
#include <bits/stdc++.h> using namespace std; int main() { long long int t, n, k; cin >> t; while (t--) { cin >> n >> k; 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]); } sort(a, a + n); ...
#include <bits/stdc++.h> using namespace std; int n; vector<int> ways[400], a[400], num[400]; vector<int> ans; struct edge { int a, b; }; vector<edge> gr; bool dfs(int v, int f, int pr) { if (v == f) return true; for (int i = 0; i < a[v].size(); i++) { if (a[v][i] != pr) if (df...
#include <bits/stdc++.h> using namespace std; const long long inf = (long long)4e18; int n, q; long long c[110000]; long long v[110000]; long long d[110000]; int u[110000]; int main() { ios::sync_with_stdio(0); cin >> n >> q; for (int i = 0; i < n; ++i) cin >> v[i]; for (int i = 0; i < n...
#include <bits/stdc++.h> using namespace std; const int mod = 998244353; const int inf = 0x3c3c3c3c; const long long infl = 0x3c3c3c3c3c3c3c3c; long long dp[5003][5003]; int A, B, C; int main() { ios::sync_with_stdio(0), cin.tie(0); ; cin >> A >> B >> C; vector<int> v({A, B, C}); sort(...
#include <bits/stdc++.h> using namespace std; int n; int main() { scanf( %d , &n); int block = (int)sqrt(n), total = 0; for (int t = 1;; ++t) { for (int j = 1, k = max(1, n - t * block + 1); j <= block; ++j, ++k) { printf( %d , k); if (++total == n) { return 0; ...
#include <bits/stdc++.h> using namespace std; int main() { int n, m, k, i; cin >> n >> m >> k; vector<long long int> a(n), s1(m, 0), e1(m, 0), tot1(m, 0), s2(n, 0), e2(n, 0), tot2(n, 0); long long int b[m][3]; long long int c[k][2]; for (i = 0; i < n; i++) cin >> a[i]; for (i = 0...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; if (n % 2 == 0) cout << -1 << endl; else { for (int i = 0; i < n; i++) { if (i > 0) cout << ; cout << i; } cout << endl; for (int i = 0; i < n; i++) { if (i > 0) cou...
#include <bits/stdc++.h> using namespace std; long long a, b, c, d, e, f, n, ans, cn1, cn2, cn3, t; string s, s1, s2; int main() { ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0); cin >> a; cin >> b; cin >> c; cin >> d; cin >> e; cin >> f; ans = 0; if (e >= f) { ...
#include <bits/stdc++.h> using namespace std; int main() { int n, m, a, b; cin >> n >> m; if (m == n) { vector<bool> rev(n, false); vector<vector<int> > mat(n + 1); for (int i = 0; i < m; i++) { cin >> a >> b; mat[a].push_back(b); mat[b].push_back(a); } ...
#include <bits/stdc++.h> #pragma GCC optimize( Ofast,no-stack-protector ) #pragma GCC target( avx ) int V[100000]; float x; int main() { int n, m, l, r, res, type; scanf( %d%d , &n, &m); for (int i = 1; i <= n; i++) scanf( %d , &V[i]); while (m--) { scanf( %d%d%d%f , &type, &l, &r, &x); ...
#include <bits/stdc++.h> using namespace std; #define TC 1 #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define deb(...) [ << #__VA_ARGS__ : << (__VA_ARGS__) << ] using ll = long long; template <typename T> vector<T> readArr(int n) { vector <T> v(n); for (auto &it ...
#include <bits/stdc++.h> template <class T> T gcd(T a, T b) { T r; while (b != 0) { r = a % b; a = b; b = r; } return a; } template <class T> T lcm(T a, T b) { return a / gcd(a, b) * b; } using namespace std; const long long MOD = 1e9 + 7; vector<int> p, q; long...
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5; int n; int a[N], b[N], c[N]; map<pair<int, int>, pair<int, int> > mtp; int main() { scanf( %d , &n); for (int i = 1; i <= n; i++) { scanf( %d %d %d , &a[i], &b[i], &c[i]); } double ans = 0; int idx = -1; for (...
#include <bits/stdc++.h> using namespace std; int main() { long long n, a, b, x1, y1, x2, y2, d1, d2, r1 = 10000000000000000, r2 = 10000000000000000, ans; ans = r2; r1 *= -1; r2 = r1; vector<pair<long long, pair<long long, long long> > > v1, v2; ...
#include<bits/stdc++.h> #define ll long long using namespace std; int k; int dfs(int v, int p, vector<vector<int>> &viz){ int t=-1; vector < int > pos; for(auto u: viz[v]){ if(u==p) continue; int w=dfs(u,v,viz); pos.push_back(w); if(t==-1) t=w+1; t = min(t,w+1); } sort(pos....
#include <bits/stdc++.h> using namespace std; const long double eps = 1e-9; const long double pi = acos(-1.0); const long long inf = 1e+9; #pragma comment(linker, /STACK:36777216 ) template <typename T> istream &operator>>(istream &, vector<T> &); template <typename T> ostream &operator<<(ostream &, ...
#include <bits/stdc++.h> using namespace std; long long mc[1 << 20]; list<int> th; struct f { long long x, k, m, ms[20]; } fs[100]; bool kcomp(f a, f b) { return a.k < b.k; } int main() { ios::sync_with_stdio(false); cin.tie(0); long long n, m, b; cin >> n >> m >> b; for (int i = 0...
#include <bits/stdc++.h> using namespace std; char s[10]; int v[10][10]; int dx[4] = {-2, -2, 2, 2}, dy[4] = {2, -2, 2, -2}; int sx, sy, ex, ey; int mark[10][10]; int ans; void dfs(int curx, int cury, int curnum) { for (int i = 0; i < 4; i++) { int tempx = curx + dx[i]; int tempy = cury ...
#include <bits/stdc++.h> using namespace std; int report[105], folder[105]; int main() { int n; cin >> n; int k = 1, am = 0; for (int i = 1; i <= n; i++) cin >> report[i]; for (int i = 1; i <= n; i++) { if (report[i] < 0 && am == 2) { k++; folder[k]++; am = 1; ...
#include <bits/stdc++.h> using namespace std; int n; string a; vector<pair<int, int> > v; void input() { cin >> a; n = a.size(); } void solve() { int i; for (i = 0; i < n; i++) { if (a[i] != a ) { v.push_back(make_pair((a[i] - a ), i)); } } int sz = v.size(); ...
#include <bits/stdc++.h> using namespace std; vector<int> vec[10]; vector<vector<int> > vvv(183); queue<int> qu; map<string, int> mp; map<string, int>::iterator iter; bool ch[10] = {false}; int main() { string s1, s2; cin >> s1 >> s2; for (int i = 0; i < s1.length(); i++) { if (s1[i] >...
#include <bits/stdc++.h> int freq[1005] = {0}; int find_int(int a, int b, int c, int d) { int i; if (b < c) return 0; if (a > d) return 0; if (a <= c && b >= d) { for (i = c; i <= d; i++) freq[i] = 1; return d - c + 1; } else if (a >= c && b <= d) { for (i = a; i <= b; i++) fre...
#include <bits/stdc++.h> using namespace std; int GLL(long long& x) { return scanf( %lld , &x); } int GI(int& x) { return scanf( %d , &x); } int m, n; long long add(long long x, long long y) { x += y; if (x >= m) x -= m; return x; } long long sub(long long x, long long y) { x -= y; if ...
#include <bits/stdc++.h> using namespace std; inline void Boost() { ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); } const long double eps = 1e-10; int main() { Boost(); int n; cin >> n; vector<long double> A(n), B(n); for (auto &x : A) cin >> x; for (auto &x :...
#include <bits/stdc++.h> using namespace std; int main() { int n, x; long long score, sum = 0; cin >> n; vector<int> ara(n); for (int i = 0; i < n; i++) { cin >> ara[i]; sum += ara[i]; } sort(ara.begin(), ara.end()); reverse(ara.begin(), ara.end()); score = sum; f...
#include <bits/stdc++.h> using namespace std; int main() { int x; cin >> x; x++; cout << x / 36 << << (((x % 36)) / 3); }
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); long long n = 0, m = 0, mn = 0, mx = 0, l = 1, r = 0, k = 0, j = 1, i = 0, ans = 0; cin >> n; vector<int> a(n); for (auto &x : a) cin >> x; bool got = true; while (got) { ...
#include <bits/stdc++.h> using namespace std; set<int> st; set<int> en; vector<int> out; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n; cin >> n; for (int i = 0; i < n; i++) { int t; cin >> t; if (st.find(t) == st.end()) st.insert(t); else if ...
#include <bits/stdc++.h> using namespace std; int const MAXN = 2e5 + 10; int n, m, T; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> n >> m; int t = 0; while (m) { t = 10 * t + m % 10; m /= 10; } cout << n + t; return 0; }
#include <bits/stdc++.h> using namespace std; const long long INF = 1e18; const int32_t M = 1e9 + 7; const int32_t MM = 998244353; void solve() { long long x; cin >> x; long long n = 2; long long tot = (n * (n - 1)) / 2; long long ans = 0; while (tot <= x) { ans++; n *= 2; ...
#include <bits/stdc++.h> using namespace std; const int N = 1000010, P = 2000010; int f[P]; int n, t, a[N]; int d[N], g[N], r[P]; vector<int> q[P], v[N]; void init(int c, int p) { vector<int> z; int cv = a[c]; d[c] = d[p] + 1; g[c] = -1; if (c == 1) fill(r + 1, r + P, -1); for (int...
#include <bits/stdc++.h> using namespace std; const long long MXN = 2e5 + 10; const long long MXS = MXN * 4; const long long INF = 1e18; struct Typ { long long Sum, ValL, ValR, dpL, dpR, Maxdp, sz, Mindis, Val2L, Val2R; pair<long long, long long> Valley; void init() { Mindis = INF; Val...
#include <bits/stdc++.h> using namespace std; const double pi = acos(-1.0); template <typename T, typename U> inline void amin(T &x, U y) { if (y < x) x = y; } template <typename T, typename U> inline void amax(T &x, U y) { if (x < y) x = y; } using namespace std; int main() { int n, m; ...
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; long long powmod(long long x, long long y) { long long t; for (t = 1; y; y >>= 1, x = x * x % mod) if (y & 1) t = t * x % mod; return t; } long long gcd(long long x, long long y) { return y ? gcd(y, x % y) : x; } long l...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); long long t; cin >> t; while (t--) { long long n, m; cin >> n >> m; if (m >= 2 * n) { cout << n << << 2 * n << endl; } else { cout...
#include <bits/stdc++.h> using namespace std; const double pi = 3.1415926535897; int main() { string pass; string str[10]; cin >> pass; for (int i = 0; i < 10; i++) { cin >> str[i]; } for (int i = 0; i < 80; i += 10) { string tmp = pass.substr(i, 10); for (int io = 0; io ...
#include <bits/stdc++.h> using namespace std; const int N = 300005; int n, m, q; struct Graph { struct Edge { int to, next; } edge[N << 1]; int head[N], cnt; Graph() { memset(head, 0, sizeof(head)); cnt = 1; return; } void add_edge(int u, int v) { if (u == 0...
#include <bits/stdc++.h> using namespace std; void solve() { long long n, k; cin >> n >> k; vector<long long> a(n); for (long long &i : a) cin >> i; sort(a.begin(), a.end()); a.resize(unique(a.begin(), a.end()) - a.begin()); n = a.size(); if (k == 1 and n > 1) { cout << -1 << e...
#include <bits/stdc++.h> using namespace std; int t1, n, i, j, a[202], f[202][404]; int main() { scanf( %d , &t1); while (t1--) { scanf( %d , &n); for (i = 1; i <= n; i++) scanf( %d , &a[i]); sort(a + 1, a + n + 1); memset(f, 44, sizeof(f)); for (j = 0; j <= n * 2; j++) f[0][...
#include <bits/stdc++.h> int read() { int ans = 0, c, f = 1; while (!isdigit(c = getchar())) if (c == - ) f *= -1; do ans = ans * 10 + c - 0 ; while (isdigit(c = getchar())); return ans * f; } const int N = 1000050; int n, a[N]; long long S; long long calc(long long p) { long...
#include <bits/stdc++.h> using namespace std; const int N = 1e6; vector<long long int> adj[N]; long long int depth[N]; void dfs(long long int n, long long int p) { for (auto x : adj[n]) { if (x != p) { depth[x] = depth[n] + 1; dfs(x, n); } } } void solve() { long lo...
#include <bits/stdc++.h> using namespace std; const int N = 100005; int sz = 1; int t[N << 2], clr[N << 2]; inline void pushclear(int k) { if (!clr[k]) return; t[k] = 0; if (k < sz) clr[k << 1] = clr[k << 1 | 1] = 1; clr[k] = 0; } inline void clear(int k, int l, int r, int a, int b) { ...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cout << Black << endl; }
#include <bits/stdc++.h> #pragma comment(linker, /STACK:836777216 ) using namespace std; int n, t, m; int nextId = 0; int max_online = 0; int cur_online = 0; deque<pair<int, int> > id_q; int cnt[86400]; vector<int> answer; int main(void) { memset((cnt), (0), sizeof((cnt))); scanf( %d%d%d , ...
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; for (int i = 0; i < t; i++) { int a1; cin >> a1; cout << 1 << << (a1 - 1); cout << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; const long long N = 1e5 + 10; long long n, a, cnt, ans, sum, l, r; string g; void DNM() { cin >> n; cin >> g; sort(g.begin(), g.end()); cout << g << endl; } int main() { ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL); ...
#include <bits/stdc++.h> using namespace std; long long t[2300]; int main() { int n, k; scanf( %d%d , &n, &k); for (int i = 0; i < n; i++) scanf( %lld , &t[i]); sort(t, t + n); long long sum = 0; for (int i = 0; i < k; i++) sum += t[i]; printf( %lld n , sum); }
#include <bits/stdc++.h> using namespace std; int M = 1000000007; map<string, long long int> b1; int main() { ios ::sync_with_stdio(false); cin.tie(0); long long int n, k; cin >> n >> k; long long int c = max(n - 2 * k, 0ll); long long int a = n * (n - 1) / 2 - c * (c - 1) / 2; cout ...
#include <bits/stdc++.h> int main() { int m, n, a; scanf( %d %d , &n, &m); if (m % 2 == 0 || n % 2 == 0) printf( %d , m * n / 2); else if (n >= m) printf( %d , (n - 1) * m / 2 + (m - 1) / 2); else if (n < m) printf( %d , (m - 1) * n / 2 + (n - 1) / 2); }
#include <bits/stdc++.h> using namespace std; int Sky[105][105][15]; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, q, c; cin >> n >> q >> c; c++; for (int i = 1; i <= n; i++) { int x, y, s; cin >> x >> y >> s; for (int r = 0; r < c; r++) Sky[x]...
#include <bits/stdc++.h> using namespace std; template <typename T> inline void read(T& t) { T f = 1; char ch = getchar(); t = 0; while (ch < 0 || ch > 9 ) { if (ch == - ) f = -f; ch = getchar(); } while (ch >= 0 && ch <= 9 ) t = t * 10 + ch - 0 , ch = getchar(); t ...
#include <bits/stdc++.h> using namespace std; template <class _T> inline _T sqr(const _T &first) { return first * first; } template <class _T> inline string tostr(const _T &a) { ostringstream os( ); os << a; return os.str(); } const long double PI = 3.1415926535897932384626433832795L; ...
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 10; int n, m; int cnt1[N], cnt2[N]; struct Fenwick_tree { vector<long long> t; int n; void init(int _n) { n = _n; t.assign(n + 1, 0); } void add(int r, int x) { for (; r <= n; r = (r | (r + 1))) t[r] += 1LL...
#include <bits/stdc++.h> using namespace std; const int NMAX = 200010, ALPHA = 30; int N; long long Sum[ALPHA]; double Ans; char A[NMAX], B[NMAX]; int main() { scanf( %i n , &N); gets(A + 1); gets(B + 1); long long Posib = (1LL * N * (N + 1) * (2 * N + 1)) / 6; for (int i = N; i; --i) ...
#include <bits/stdc++.h> using namespace std; struct EDGE { int to, next, w; } e[400010]; int head[200010], top; void add(int u, int v, int w) { e[top].to = v; e[top].next = head[u]; e[top].w = w; head[u] = top++; } vector<int> vv; int vis[200010], tmpp = -1; long long in_max; in...
#include <bits/stdc++.h> using namespace std; long long v[2][200005]; long long c[2][200005]; int n, k, a, b, q, e, day, ord; const int maxn = 200005; void add(int i, int value, int z) { for (; i < maxn; i += (i + 1) & -(i + 1)) v[z][i] += value; } long long get(int i, int z) { long long res = 0...
#include <bits/stdc++.h> using namespace std; const int N = 1 << 18; const int inf = 1e9; int a[N], b[N], c[N], d[N]; int dp[19][N]; bool pr[19][N]; int main() { int n; scanf( %d , &n); for (int i = 1; i <= n; i++) { scanf( %d , &a[i]); b[i] = (a[i] % N + N) % N; } dp[0][0]...
#include <bits/stdc++.h> using namespace std; int main() { int n, h, a, ans = 0; cin >> n >> h; for (int i = 0; i < n; i++) { cin >> a; int add = 1; if (a > h) add++; ans += add; } cout << ans; return 0; }
#include <bits/stdc++.h> using namespace std; string s; int main() { cin >> s; long long n = s.size(); long long b = n / 2; if (n % 2) { while (1) { if (s[b] == A ) break; if (s[b] == H ) break; if (s[b] == I ) break; if (s[b] == M ) break; if (s[b...
#include <bits/stdc++.h> using namespace std; const int maxn = 100000; long long n, ans; int main() { while (~scanf( %lld , &n)) { n--; int l = 0; for (int i = 0; i < 50; i++) if ((1ll << i) & n) l = i; ans = n / 2 + n % 2; int f = l; for (; f > 0; f--) { ...
#include <bits/stdc++.h> using namespace std; int n, ans = 0; int main() { cin >> n; for (int i = 1; i <= n; i++) for (int j = 1; j <= n; j++) { int x; cin >> x; if (i == j || (i + j) == (n + 1) || i == (n + 1) / 2 || j == (n + 1) / 2) ans += x; } cout << ...
#include <bits/stdc++.h> using namespace std; const int N = 105; int M127; string s; int S, k, n; int e[N][N]; int f[N][N][N]; int conv(char c) { return c - a + 1; } int main() { cin >> s; S = s.size(); s = + s; memset(f, -127, sizeof(f)); M127 = f[0][0][0]; k = ({ ...