func_code_string
stringlengths
59
71.4k
#include<bits/stdc++.h> using namespace std; #define int long long int32_t main() { int t; cin >> t; while(t--) { string s; int n; cin >> n; cin >> s; sort(s.begin(),s.end()); cout << s << endl; } return 0; }...
#include <bits/stdc++.h> constexpr int mod = 1e9 + 7; int main() { using namespace std; ios_base::sync_with_stdio(false), cin.tie(nullptr); int tt; cin >> tt; while (tt--) { int n, k; cin >> n >> k; vector<uint16_t> a(n); for (uint16_t &x : a) cin >> x; sort(a.begin(), a.end(), greater<u...
#include <bits/stdc++.h> const int maxn = 300010; int n, m, cnt, go_far; int not_read[maxn], clr[maxn]; int a[maxn]; int main() { int i, op, x, t, zz; scanf( %d%d , &n, &m); cnt = 0; a[0] = 0; go_far = 0; for (zz = 1; zz <= m; zz++) { scanf( %d%d , &op, &x); if (op == 1) { ...
#include <bits/stdc++.h> using namespace std; const int N = 55; int v[N][N], x[N << 1], y[N << 1], n, m, q; int main() { scanf( %d , &n); v[1][1] = 1; v[1][2] = v[n][n] = 0; m = n * 2 - 4; for (int i = 3; i <= n; i += 2) { printf( ? %d %d %d %d n , i - 2, 1, i, 1); fflush(stdout)...
#include <bits/stdc++.h> using namespace std; int a[200005]; int f[200005]; int main() { ios::sync_with_stdio(false); int t, n; cin >> t; for (int i = 0; i < t; i++) { cin >> n; int maxx = 0; int minx = 999999999; for (int j = 0; j < n; j++) { cin >> a[j]; ...
#include <bits/stdc++.h> using namespace std; int p[1001000]; int main() { int a, b, k; cin >> a >> b >> k; for (int i = 2; i <= b + 20; i++) p[i] = 1; for (int i = 2; i <= b + 20; i++) if (p[i]) for (int j = i + i; j <= b + 10; j = j + i) p[j] = 0; for (int i = 1; i < b + 10; i+...
#include <bits/stdc++.h> #pragma GCC optimize(2) #pragma GCC optimize(3) #pragma GCC optimize(4) using namespace std; const int N = 9; const int C = 840; int n; long long dp[C * N]; long long cnt[N], M; int main() { scanf( %lld , &M); for (int i = 1; i < N; ++i) scanf( %lld , &cnt[i]); m...
#include <bits/stdc++.h> using namespace std; int main() { long long t; cin >> t; while (t--) { long long n, f = 0; cin >> n; vector<char> v1, v2; for (int i = 0; i < n; i++) { char a; cin >> a; v1.push_back(a); } for (int i = 0; i < n; i++) { ...
#include <bits/stdc++.h> using namespace std; long long x, y, m; long long ans; int main() { cin >> x >> y >> m; if (x >= m || y >= m) { cout << 0; return 0; } if (x <= 0 && y <= 0) { cout << -1; return 0; } if (y < 0) swap(x, y); if (x < 0) { ans += cei...
#include <bits/stdc++.h> using namespace std; int memo[5001][501]; int k; int h[11]; long long distribute(int cards, int players) { if (cards <= 0 or players <= 0) return 0; if (cards >= k * players) return players * h[k]; if (memo[cards][players] != -1) { return memo[cards][players]; } ...
#include <bits/stdc++.h> using namespace std; const int M = 1e5 + 10; int n, S; long long tot; struct Node { long long val; long long num; long long sum; bool operator<(const Node &rhs) const { return num < rhs.num; } }; vector<Node> a, b; long long work(long long ls, vector<Node> &a) { ...
#include <bits/stdc++.h> using namespace std; int dd[4][2] = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}}; vector<vector<int>> mat(1000, vector<int>(1000)); int n, m, si, sj; void bfs() { mat[si][sj] = 1; queue<pair<int, int>> q; q.push({si, sj}); while (!q.empty()) { auto p = q.front(); q.p...
#include <bits/stdc++.h> using namespace std; #pragma GCC optimize( Ofast ) #pragma GCC optimize( fast-math ) #pragma GCC optimize( unroll-loops ) #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,tune=native ) mt19937 rnd(51); const int N = 1010; vector<int> g[N]; vector<bool> used(N); ve...
#include <bits/stdc++.h> using namespace std; int mod = 1e9 + 7; long long binpow(long long a, long long b) { long long res = 1; while (b > 0) { if (b & 1) res = (res % mod) * (a % mod), res %= mod; a = (a % mod) * (a % mod); a %= mod; b >>= 1; } return res; } long long...
#include <bits/stdc++.h> using namespace std; void FastInputOutput() { ios_base ::sync_with_stdio(0); cin.tie(0); cout.tie(0); } int main() { int n, temp; map<int, int> idx; scanf( %d , &n); for (int i = 1; i <= n; ++i) { scanf( %d , &temp); idx[temp] = i; } int q...
#include <bits/stdc++.h> using namespace std; long long n, m, q, t, c; string s; long long inv[200007]; long long p[200007]; long long f[200007]; long long nq[200007]; long long mq[200007]; long long res[200007]; long long dp[200007]; vector<long long> que[200007]; long long fpow(long long a, lo...
#include <bits/stdc++.h> using namespace std; const long long LINF = 0x3f3f3f3f3f3f3f3f; const long long NLINF = 0xf7f7f7f7f7f7f7f7; const int INF = 0x3f3f3f3f, NINF = 0xf7f7f7f7; const int MOD1 = 1e9 + 7, MOD2 = 1e9 + 9; const int N = 1e5 + 10; vector<int> sz; int t, n, lst; int main() { for (sca...
#include <bits/stdc++.h> using namespace std; int main() { int s, n, a[10000] = {0}, m = -1, y, i; cin >> s >> n; int c = n; while (n--) { cin >> i >> y; a[i] += y; m = max(m, i); } for (int i = 0; i < 10000; i++) { if (s > i) { s += a[i]; } } s ...
#include <bits/stdc++.h> using namespace std; int main() { long n, m, k, x, y, z; cin >> n >> m >> k; vector<long long> v(n + 1); vector<long long> s(n + 2, 0); vector<long long> m1(m + 1); vector<long long> m2(m + 1); vector<long long> m3(m + 1); vector<long long> k1(m + 2); for...
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 5; const int inf = 0x3f3f3f3f; long long dp[maxn]; int n, m; struct node { int lb, lu; long long w; }; vector<node> ve[maxn]; int lb, lu; long long w, cost[maxn]; struct seg { long long ma, lazy; } tr[maxn << 2]; ...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; unsigned long long ans = 1, ans2 = 1; for (int i = 0; i < n; i++) { ans = (ans * 27); ans2 = (ans2 * 7); if (ans2 > 1000000007 || ans % 1000000007 > ans2) { ans %= 1000000007; ans2 %= 100000...
#include <bits/stdc++.h> using namespace std; int read_number(int i) { cout << ? << i << n ; fflush(stdout); int number; cin >> number; return number; } bool intersects(int l1, int l2, int r1, int r2) { if (l1 >= l2) swap(l1, l2); if (r1 >= r2) swap(r2, r1); return max(l1, r...
#include <bits/stdc++.h> using namespace std; int n, t, k; vector<int> g[200010]; int par[200010]; int nodeId; int leaf; vector<int> deep[200010]; int a[200010]; void createGraph(int x, int level) { if (level > t) return; for (int i = 1; i <= a[level]; i++) { g[x].push_back(++nodeId); ...
#include <bits/stdc++.h> using namespace std; int main() { int n; long long m, k; cin >> n >> m >> k; vector<long long> arr(n); long long max1 = -1; long long max2 = -2; long long temp; for (int i = 0; i < n; i++) { cin >> arr[i]; if (arr[i] > max2) { max2 = arr[i...
#include <bits/stdc++.h> template <class T> inline T lowbit(T x) { return x & (-x); } template <class T> inline T sqr(T x) { return x * x; } template <class T> inline bool scan(T &ret) { char c; int sgn; if (c = getchar(), c == EOF) return 0; while (c != - && (c < 0 || c > 9...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int t; cin>>t; while(t--) { int n; cin>>n; vector<long long int>a(n); for(int i=0;i<n;i++) cin>>a[i]; sort(a.begin(),a.end()...
#include <bits/stdc++.h> using namespace std; const int N = 55; int n, num, h[N], siz[N], e[N << 1], pre[N << 1]; double g[N], C[N][N], f[N][N]; inline void add(int x, int y) { e[++num] = y, pre[num] = h[x], h[x] = num; } void dfs(int u, int fa = 0) { memset(f[u], 0, sizeof f[u]), f[u][0] = siz[u] = 1; ...
#include <bits/stdc++.h> using namespace std; const int N = (1e6) + 5; const int M = (60) + 5; int memo[M][M]; int n, a[N]; int grundy(int n, int last) { if (n == 0) { return 0; } int &ret = memo[n][last]; if (ret != -1) return ret; set<int> S; for (int i = last + 1; i <= n; i ...
#include <bits/stdc++.h> #pragma GCC optimize( Ofast ) #pragma GCC target( sse4 ) using namespace std; const int MOD = 1e9 + 7; const int MX = 2e5 + 5; const long long INF = 1e18; const long double PI = acos((long double)-1); const long double EPS = 1e-6; const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1...
#include<bits/stdc++.h> using namespace std; int main(){ int t; cin>>t; while(t--){ string s; cin>>s; int n = s.length(); int i=0,j = n-1,k = n-1; char z = a ; while(k>=0){ if(s[i] == z+k) i++; else if(s...
#include <bits/stdc++.h> using namespace std; const long N = 1000L + 10; const long long modulo = 1000000007L; vector<pair<long, long> > interv; bool memo[N][N]; bool visited[N]; void divideByZero(const char *error) { printf(error); fclose(stdout); int a = 234; a = a / (a - a); } bool ...
#include <bits/stdc++.h> constexpr int Maxn = 2e5 + 7; constexpr int Maxm = 1e6 + 7; constexpr int Mod = 1e9 + 7; int n, k, sum, root; void add(int bit[], int p, int v) { for (; p < Maxn; p += p & -p) bit[p] = (bit[p] + v) % Mod; } int query(int bit[], int p) { int res = 0; for (; p; p -= p & ...
#include <bits/stdc++.h> using namespace std; void rwFile() { freopen( INP.inp , r , stdin); freopen( OUT.out , w , stdout); } void solveC_VanyaAndScales() { long long w, m; cin >> w >> m; if (w == 2) { cout << YES ; return; } int able = 1; while (m) { long l...
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; vector<int> a(n); vector<int> update(n); for (int i = 0; i < n; i++) { cin >> a[i]; update[i] = 0; } int accumalated = 0; for (int i = 0; i < m; i++) { int t; cin >> t; i...
#include <bits/stdc++.h> using namespace std; const int N = 5010; inline int read() { int s = 0, w = 1; register char ch = getchar(); while (ch < 0 || ch > 9 ) { if (ch == - ) w = -1; ch = getchar(); } while (ch >= 0 && ch <= 9 ) s = (s << 3) + (s << 1) + (ch ^ 48), ch...
#include <bits/stdc++.h> using namespace std; const int inf = ~0U >> 1; const long long linf = (long long)1e18; const double eps = 1e-6; template <class T> string tostr(T a) { ostringstream out; out << a; return out.str(); } struct debugger { template <typename T> debugger &operator,...
#include <bits/stdc++.h> using namespace std; const int MAX = 2e5 + 5; const int MOD = 998244353; long long p[MAX]; long long mpow[MAX]; int main(int argc, char* argv[]) { if (argc == 2 or argc == 3) freopen(argv[1], r , stdin); if (argc == 3) freopen(argv[2], w , stdout); int n, m; string...
#include <bits/stdc++.h> using namespace std; bool reverse(long long a, long long b) { return a > b; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); long long n, i; cin >> n; if (n % 2 != 0) cout << -1 << n ; else { for (long long i ...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int TESTS = 1; while (TESTS--) { long long int n; cin >> n; long long int a[n + 1], b[n + 1]; for (long long int i = 1; i <= n; i++) cin >> a[i]; fo...
#include <bits/stdc++.h> using namespace std; long long head[200010], cnt; class littlestar { public: long long to, nxt; void add(long long u, long long v) { to = v; nxt = head[u]; head[u] = cnt; } } star[400010]; long long n, f[200010], g[200010], h[200010]; void dfs(long l...
#include <bits/stdc++.h> using namespace std; const long long N = 110; long long dp[N][2], n, val[N], ans; char s[N]; signed main() { scanf( %s , s + 1); n = strlen(s + 1); for (long long i = 1; i <= n; ++i) val[i] = (s[i] == A ); dp[1][val[1]] = 1; dp[0][0] = 1; for (long long i = 2;...
#include <bits/stdc++.h> using namespace std; bool comparator(string a, string b) { if (a.size() == b.size()) { return a > b; } return a.size() > b.size(); } int main() { int n, m; cin >> n >> m; string mat[n]; for (int i = 0; i < n; i++) { cin >> mat[i]; } vector...
#include <bits/stdc++.h> using ld = long double; const ld EPS = 1e-12; const ld PI = acos((ld)-1); inline bool equ(const ld& a, const ld& b) { return std::abs(a - b) < EPS; } struct vec { public: ld x, y; bool operator==(const vec& o) const { return equ(x, o.x) && equ(y, o.y); } vec& operator+=...
#include <bits/stdc++.h> #pragma GCC optimize( O3 ) using namespace std; const int MAX_N = 3e5 + 10, MAX_LOG_N = 20; const long long MOD1 = 1e9 + 7, BASE1 = 29, MOD2 = 1e9 + 9, BASE2 = 37; long long sq(long long a, long long p) { return a * a % p; } long long qpow(long long a, long long b, long long p) { ...
#include <bits/stdc++.h> using namespace std; long long a, b; long long nexta, nextb; long long d, m; int main() { cin >> a >> b; nexta = a; nextb = b; long long cur = 0; while (nexta != nextb) if (nexta < nextb) { d += nexta - cur; cur = nexta; nexta += a; ...
#include <bits/stdc++.h> using namespace std; template <typename T> void _R(T &x) { cin >> x; } void _R(int &x) { scanf( %d , &x); } void _R(long long &x) { scanf( % PRId64, &x); } void _R(double &x) { scanf( %lf , &x); } void _R(char &x) { scanf( %c , &x); } void _R(char *x) { scanf( %s , x); }...
#include <bits/stdc++.h> using namespace std; int kk[7]; int main() { string s; cin >> s; int n = s.length(); sort(s.begin(), s.end()); for (int i = 0, j; i < n; i = j) { j = i + 1; while (j < n && s[j] == s[i]) j++; kk[j - i]++; } int ans; if (kk[6] == 1 || kk[5]...
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { long long int a, b, x, y, n; cin >> a >> b >> x >> y >> n; cout << min(max(x, a - n) * max(y, b - n + min(n, a - x)), max(y, b - n) * max(x, a - n + min(n, b - y))) <<...
#include <bits/stdc++.h> using namespace std; int main() { long long n; cin >> n; string s; cin >> s; if (n % 4 != 0) { cout << === ; return 0; } vector<long long> v(5, 0); for (long long i = 0; i < n; i++) { if (s[i] == A ) { v[0]++; } if (s[i...
#include <bits/stdc++.h> using namespace std; int64_t v[200005] = {0}; int64_t fnc(int64_t h, int n) { int64_t mn = v[0]; for (int i = 1; i < n; i++) { v[i] += v[i - 1]; mn = min(mn, v[i]); } if (v[n - 1] >= 0 && h + mn > 0) return -1; int64_t ans = 0; if (h + mn <= 0) { ...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ; long long n, k, ans = 1e11; string s; cin >> n; if (n == 1 || n == 2) { cout << No << endl; return 0; } cout << Yes << endl; set<l...
#include <bits/stdc++.h> using namespace std; const int N = 1e3 + 5; int n; double p[N][N], E[N], g[N], f[N]; bool vis[N]; int main() { scanf( %d , &n); for (int i = 1; i <= n; i++) for (int j = 1; j <= n; j++) scanf( %lf , &p[i][j]), p[i][j] /= 100.0; for (int i = 1; i <= n; i++) g[i] = 1...
#include <bits/stdc++.h> using namespace std; vector<int64_t> v[3001]; int64_t calc(int64_t taken, int64_t n, int64_t m) { int64_t req = taken - v[0].size(); int64_t t = v[0].size(); int64_t ans = 0; vector<int64_t> rem; for (int64_t i = 1; i < m; i++) { if (v[i].size() == 0) continue; ...
#include <bits/stdc++.h> using namespace std; const int INF = 1e9; long long n, m, b, ans; long long a[1005]; int l, r, mid; long long dp[1005][1005]; struct Node { long long w, id; } f[1005]; bool cmp(Node a, Node b) { if (a.w != b.w) return a.w < b.w; return a.id > b.id; } int main()...
#include <bits/stdc++.h> int main() { double y1, y2, yw, xb, yb, r, A, B, C; scanf( %lf%lf%lf%lf%lf%lf , &y1, &y2, &yw, &xb, &yb, &r); yw -= r; y1 += r; yb = 2 * yw - yb; A = y1 - yb; B = xb; C = -B * y1 + B * y2; if ((C / sqrt(A * A + B * B)) <= r) { printf( -1 ); retu...
#include <bits/stdc++.h> using namespace std; int n, m, a[200010], t[200010], pos[200010], ans[200010]; struct point { int pos, v, f; point(int pos, int v, int f) : pos(pos), v(v), f(f) {} }; vector<point> v[200010]; inline void insert(int x) { for (register int i = x; i <= n; i += i & -i) t[i]+...
#include <bits/stdc++.h> using namespace std; int n, k; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> k; vector<pair<int, int> > v(n), ans; for (int i = 0; i < n; ++i) cin >> v[i].first, v[i].second = i; while (k--) { sort(v.begin(), v.end()); i...
#include <bits/stdc++.h> #pragma GCC optimize( O3 ) #pragma GCC target( sse4 ) using namespace std; template <class c> struct rge { c b, e; }; template <class c> rge<c> range(c i, c j) { return rge<c>{i, j}; } template <class c> auto dud(c* x) -> decltype(cerr << *x, 0); template <class ...
#include <bits/stdc++.h> using namespace std; const int M = 2e5 + 10; int n, k, m, kk, x, b[M]; int main() { int T; cin >> T; while (T--) { cin >> n >> k; kk = 1; m = 0; for (int i = 1; i <= n; i++) { cin >> x; if (x % 2) { m++; if (kk < k)...
#include <bits/stdc++.h> using namespace std; long long dx[] = {1, 0, -1, 0}; long long dy[] = {0, 1, 0, -1}; bool myComparison1(const pair<long long, long long> &a, const pair<long long, long long> &b) { return a.second < b.second; } bool myComparison2(const pair<long long, long lo...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL); srand(time(NULL)); ; int T = 1; while (T--) { int a[3]; for (int i = 0; i < int(3); i++) cin >> a[i]; sort(a, a + 3); cout << a[2] - a[0]; } ...
#include <bits/stdc++.h> using namespace std; int n, a[5]; int c[100]; int main() { ios_base::sync_with_stdio(false); cin >> n >> a[0] >> a[1]; for (int i = 1; i <= n; i++) cin >> c[i]; int m = min(a[0], a[1]); int ans = 0; for (int i = 1; i <= n / 2 + n % 2; i++) { if (c[i] == 2 &...
#include <bits/stdc++.h> using namespace std; const int maxn = 510; bitset<510> can[maxn][2][64]; int N, M; long long ans, best[maxn][2]; inline long long dfs(int now, int last) { if (best[now][last ^ 1] != -1) return best[now][last ^ 1]; else best[now][last ^ 1] = 0; for (int i = 59...
#include <bits/stdc++.h> using namespace std; const int maxn = 1005; int vis[maxn], p[maxn]; int plen; void prime() { memset(vis, 0, sizeof(vis)); plen = 0; for (int i = 2, k = 4; i < maxn; ++i, k += i + i - 1) { if (!vis[i]) { p[plen++] = i; if (k < maxn) { for (in...
#include <bits/stdc++.h> using namespace std; int readInt() { bool minus = false; int result = 0; char ch; ch = getchar(); while (true) { if (ch == - ) break; if (ch >= 0 && ch <= 9 ) break; ch = getchar(); } if (ch == - ) minus = true; else result ...
#include <bits/stdc++.h> using namespace std; int main() { { long long int i, j, k, y, n, x, m, a, b, ans = 0, sum = 0, cnt = 0; long long int c, mx = 0; string s, z, taj = YES ; cin >> s; map<char, long long int> mp; n = s.size(); for (i = 0; i < n; i++) mp[s[i]]++; ...
#include <bits/stdc++.h> using namespace std; int v[11][100010]; int vmap[11][100010]; int pointer[11]; int main() { int n, m; scanf( %d %d , &n, &m); long long ans = 0; for (int j = 0; j < m; j++) { for (int i = 0; i < n; i++) { scanf( %d , &v[j][i]); v[j][i]--; ...
#include <bits/stdc++.h> using namespace std; const int N = 200010; int n, s; int a[N]; int vis[N]; int main() { ios::sync_with_stdio(false); cin.tie(NULL); cin >> n >> s; for (int i = 0; i < n; ++i) cin >> a[i]; int cnt = 0; if (a[s - 1]) { cnt++; a[s - 1] = 0; } ...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int arr[n], i; for (i = 0; i < n; i++) cin >> arr[i]; int ind = 0, price; int max = arr[0]; for (i = 1; i < n; i++) { if (arr[i] > max) { max = arr[i]; ind = i; } } sort(arr, a...
#include <bits/stdc++.h> using namespace std; template <typename T, typename U> static inline void amin(T &x, U y) { if (y < x) x = y; } template <typename T, typename U> static inline void amax(T &x, U y) { if (x < y) x = y; } template <typename T> static inline void sd(vector<T> &x) { so...
#include <bits/stdc++.h> using namespace std; const long long inf = 0x3f3f3f3f3f3f3f3f; template <typename T> inline void read(T& X) { X = 0; int w = 0; char ch = 0; while (!isdigit(ch)) { w |= ch == - ; ch = getchar(); } while (isdigit(ch)) X = (X << 3) + (X << 1) + (ch ^ 4...
#include <bits/stdc++.h> using namespace std; const int N = 5010; long long n, a[N], dp[2][N], mini[2][N]; vector<long long> v; int main() { cin >> n; for (int i = 0; i < n; i++) { long long x; cin >> x; v.push_back(x); a[i] = x; } sort(v.begin(), v.end()); v.resize...
#include <bits/stdc++.h> using namespace std; int main() { int p; cin >> p; while (p--) { int y = 0, n, z = 0, x = 0; cin >> n; int a[n]; for (int i = 0; i < n; i++) { cin >> a[i]; if (a[i] == 0) z++; } for (int i = 0; i < n; i++) { if (a[i] ==...
#include <bits/stdc++.h> using namespace std; int a[210000]; long long dp[210000][2]; const long long INF = 1LL << 60; int N; void init() { for (int i = 0; i < 210000; i++) for (int j = 0; j < 2; j++) dp[i][j] = INF; } long long solve(int x, bool t) { if (x <= 0 || x > N) return 0; if ...
#include <bits/stdc++.h> using namespace std; int main() { int a, b, c, x, y, z; scanf( %d%d%d%d%d%d , &a, &b, &c, &x, &y, &z); bool can = true; int more = 0; int less = 0; if (a > x) more += (a - x) / 2; else less += x - a; if (b > y) more += (b - y) / 2; else ...
#include <bits/stdc++.h> using namespace std; int main() { long long N, T; cin >> N; list<long long> L; for (int i = 0; i < N; i++) { cin >> T; L.push_back(T); } long long K, possible = 1, curr = -1, orig = 0; cin >> K; vector<pair<long long, long long> > operations; ...
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 4; vector<int> e[N]; int n, siz[N]; long long ans; int sn = 0, sx = 0; int en[N], ex[N]; void dfs(int u, int fa) { siz[u] = 1; for (auto v : e[u]) { if (v == fa) continue; dfs(v, u); siz[u] += siz[v]; en[u]...
#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; typedef long long ll; ll n,m,pos,qwq,delta,a[1009],b[1009],p[1009][1009]; inline ll read(){ ll s = 0,w = 1; char ch = getchar(); while (ch > 9 || ch < 0 ){ if (ch == - ) w = -1; ch = getchar();} while (ch <= 9 && ch >= 0 ) s = (s << 1) + (s << 3) +...
#include <bits/stdc++.h> using namespace std; void read(long long &x) { char ch = getchar(); x = 0; while (!isdigit(ch)) ch = getchar(); while (isdigit(ch)) x = x * 10 + ch - 48, ch = getchar(); } const long long N = 2e5 + 10; long long n, mx, rt, tmp, sum, f[N], fr[N], tot, st[N], fl[N], p[N]...
#include <bits/stdc++.h> using namespace std; struct E { int x, y; }; E map1[1010], map2[1010], map3[1010]; int vis[1010]; int n, flag; void dfs(int k) { if (k == n + 1) { cout << map3[n].x << << map3[n].y; flag = 1; return; } else { for (int i = 1; i <= n; i++) { ...
#include <bits/stdc++.h> using namespace std; char arr[205]; int main() { ios::sync_with_stdio(0); int n; cin >> n; for (int i = (0); i < (n); i++) cin >> arr[i]; long long res = 0; pair<int, int> udlr; for (int i = (0); i < (n); i++) { udlr.first = 0; udlr.second = 0; ...
#include <bits/stdc++.h> #pragma GCC optimize( O3 ) using namespace std; const long double pi = acos(-1.0); const long double log23 = 1.58496250072115618145373894394781; const long double eps = 1e-8; const long long INF = 1e18 + 239; const long long prost = 239; const int two = 2; const int th = 3; ...
#include <bits/stdc++.h> using namespace std; template <typename T> ostream& operator<<(ostream& os, const vector<T>& v) { os << [ ; for (auto u : v) { os << u; os << , ; } os << ] << n ; return os; } template <typename T> ostream& operator<<(ostream& os, const s...
#include <bits/stdc++.h> using namespace std; template <typename T> inline string tostring(const T &x) { ostringstream os; os << x; return os.str(); } inline int toint(const string &s) { istringstream is(s); int x; is >> x; return x; } inline int todecimal(string s) { int a...
#include <bits/stdc++.h> using namespace std; int n, m, k, a[2005][2005], ans, p; int main() { cin >> n >> m >> k; for (int i = 1; i <= n; i++) for (int j = 1; j <= m; j++) { char c; c = getchar(); while (c != . && c != * ) c = getchar(); a[i][j] = c; if (c...
#include <bits/stdc++.h> using namespace std; int arr[300], book[300], n, a, b, flag = 0, tun = 0; int main() { cin >> n >> a >> b; arr[a] = arr[b] = 2; while (!flag) { tun++; memset(book, 0, sizeof(book)); for (int i = 1; i <= n; i++) { if (!book[i] && (arr[i] == 0 || arr[i]...
#include <bits/stdc++.h> using namespace std; long long n, t[1000 * 1000], a[1000 * 1000], b[1000 * 1000], v, ans; map<long long, long long> w; long long get(int v, int tl, int tr, int l, int r) { if (r < tl || tr < l) return 0; if (l <= tl && tr <= r) return t[v]; int m = (tl + tr) >> 1; return...
#include <bits/stdc++.h> using namespace std; constexpr int inf = 1e9; int main() { int n, q; cin >> n >> q; vector<int> t(q), l(q), r(q), v(q); vector<int> added(n), ub(n, inf); for (int j = 0; j < q; ++j) { cin >> t[j] >> l[j] >> r[j] >> v[j]; l[j]--; if (t[j] == 1) { ...
#include <bits/stdc++.h> using namespace std; const long long N = 5e5 + 5; vector<long long> g[N]; map<long long, long long> cnt; long long n, c, a[N], pref[N]; int32_t main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n >> c; for (long long i = 1; i <= n; i++) {...
#include <bits/stdc++.h> using namespace std; int n, m, q; char s2[10000006]; char s[205][205]; int vis[205][205]; int dp[205 * 205][20]; int dx[10]; int dy[10]; vector<int> Q; int id(int x, int y) { return x * m + y; } void dfs(int x, int y) { vis[x][y] = 1; int t = (s[x][y] - 0 ), p = i...
#include <bits/stdc++.h> #pragma comment(linker, /STACK:66777216 ) using namespace std; int RAND() { return (rand() << 16) + rand(); } const long long MOD = 1000000007; const int N = 2000007; int n; long long f[N]; long long power(long long a, long long b) { if (b == 0) return 1; if (b & 1) ret...
#include <bits/stdc++.h> using namespace std; long long calc(int *a, int n) { long long ret = 0, suml = 0; stack<pair<int, int> > st; for (int i = 2; i <= n; i++) { int l = 1; while (!st.empty() && abs(a[i] - a[i - 1]) > st.top().first) { suml -= st.top().first * (long long)st.top()....
#include <bits/stdc++.h> int n, m; long long ans; int main() { int i, j, k; scanf( %d%d , &n, &m); for (i = m + 1; (i << 1) <= n; ++i) { k = n - m; for (j = m + 1; j <= n - m; ++j) { while (k > m && 0 <= (i << 1) * ((i << 1) - j - ((n << 1) - k + 2)) + ...
#include <bits/stdc++.h> using namespace std; int main() { int n, rooms = 0; char a, b; scanf( %d n , &n); int arr[30]; for (int i = 0; i < 26; i++) arr[i] = 0; for (int i = 0; i < 2 * (n - 1); i += 2) { scanf( %c%c , &a, &b); arr[(int)(a - a )]++; if (arr[(int)(tolower(b)...
#include <bits/stdc++.h> using namespace std; using namespace std; int main() { string s; int t[128]; t[ > ] = 8; t[ < ] = 9; t[ + ] = 10; t[ - ] = 11; t[ . ] = 12; t[ , ] = 13; t[ [ ] = 14; t[ ] ] = 15; cin >> s; int ans = 0; for (int i = 0; i < (int)(s).size()...
#include <bits/stdc++.h> using namespace std; void solve() { long long n, x, i, m = 1, second = 0; cin >> n >> x; long long a[n]; for (i = 0; i < n; i++) cin >> a[i]; sort(a, a + n); for (i = n - 1; i >= 0; i--) { second += a[i]; if (((second * 1.0) / m) < (x * 1.0)) break; ...
#include <bits/stdc++.h> using namespace std; int n; vector<char> veq; void getVeq() { string s; cin >> s; veq.clear(); n = s.length(); veq.push_back( x ); veq.push_back( x ); for (int i = 0; i < s.length(); i++) veq.push_back(s[i]); veq.push_back( x ); veq.push_back( x ); ...
#include <bits/stdc++.h> using namespace std; int n, m, k, p, x, y, f, kek, all, a[100005]; int main() { cin >> n >> k >> p >> x >> y; for (int i = 1; i <= k; i++) cin >> a[i]; int kol = (n + 1) / 2; for (int i = 1; i <= k; i++) if (a[i] >= y) kol--; if (n - k < kol) { cout << -1; ...
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; const long long INF = 9e18; const int inf = 2147483647; long long phi(long long n) { long long ans = n; for (long long i = 2; i * i <= n; i++) { if (n % i == 0) { ans = ans / i * (i - 1); while (n % i ==...