func_code_string
stringlengths
59
71.4k
#include <bits/stdc++.h> using namespace std; int n; vector<int> a; vector<stack<int>> ids; vector<int> b; string answer; int segtree_size; template <typename T> struct segtree { int segtree_size; vector<T> segtree; T identity; T (*UpdateFn)(T, T); void InitSegtree(int main_size, T...
#include <bits/stdc++.h> int main() { int n, k, i; scanf( %d%d , &n, &k); while (n > k) { for (i = 1; i <= k; i++) { if (n % 10 > 0) n--; else n = n / 10; } printf( %d , n); n = 0; } }
#include <bits/stdc++.h> using namespace std; int n, l[200000 + 5], r[200000 + 5]; int p[200000 + 5], q[200000 + 5], sum; long long add(long long a, long long b) { return (a + b) % 1000000007; } long long mul(long long a, long long b) { return 1LL * a * b % 1000000007; } long long dec(long long a, long long...
#include <bits/stdc++.h> #pragma comment(linker, /STACK:100000000 ) using namespace std; int matrix[22][22]; int mas[22]; int matrix1[22][22]; int matrix2[22][22]; int best = 0; int minv[22]; bool used[22]; int u[22]; int v[22]; int p[22]; int way[22]; int getresult(int n) { int res = 0...
#include <bits/stdc++.h> using namespace std; int solve(string s, int x, int y) { int t = 0; for (auto i : s) { if (i - 0 == x) { t++; swap(x, y); } } if (x != y && t % 2 == 1) --t; return t; } int main() { cin.tie(0); cout.tie(0); ios_base::sync_wit...
#include <bits/stdc++.h> using namespace std; char a[2010], b[2010], c[2010]; int aa[256], bb[256]; int n; void _reverse(char *a, int l) { for (int i = 0; i < l; i++) c[i] = a[i]; for (int i = 0; i < l; i++) a[i] = c[l - 1 - i]; } void _rotate(char *a, int p) { for (int i = 0; i < p; i++) c[n ...
#include <bits/stdc++.h> void reduce(unsigned& nom, unsigned& denom) { bool reduced = true; while (reduced) { reduced = false; for (unsigned i = 2; !reduced && i < 1000; ++i) { if (nom % i == 0 && denom % i == 0) { nom /= i; denom /= i; reduced = true; ...
#include <bits/stdc++.h> using namespace std; const int max_n = 1500; const int max_m = 1500; const int inv = numeric_limits<int>::max(); int n, m; char G[max_n][max_m]; int si, sj; int di[max_n][max_m][4]; int dj[max_n][max_m][4]; int asz[max_n][max_m] = {0}; int vsti[max_n][max_m]; int vstj[ma...
#include <bits/stdc++.h> using namespace std; void add_self(int &a, int b) { a += b; if (a >= (int)1e9 + 7) a -= (int)1e9 + 7; } int n, l; void f(vector<int> &a) { int x = a[0]; for (int i = 0; i < n - 1; i++) { a[i] = a[i + 1] - a[i]; } a[n - 1] = l - a[n - 1] + x; } void f1...
#include <bits/stdc++.h> using namespace std; long long int minimum(long long int a[], long long int m, long long int n) { long long int ar[m]; for (long long int i = 0; i < m; i++) ar[i] = a[i]; long long int j = 0; long long int ans = 0; while (n > 0) { if (ar[j] > 0) { ans += ar...
#include <bits/stdc++.h> using namespace std; const int N = (1 << 20) + 10; vector<pair<int, int>> g[N]; int tamp = 0; bool faz; namespace hpath_space { vector<int> path; vector<int> idit, used_edge; void dfs(int no) { while (1) { int &id = idit[no]; while (id < (int)(g[no].size()) and...
#include <bits/stdc++.h> using namespace std; unsigned long long int w, v, qt = 0, n; inline unsigned long long int f(unsigned long long int x) { return w * (1 - x) * (1 - x) + v; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> n >> v >> w; char c; while (cin >> c) qt +...
#include <bits/stdc++.h> using namespace std; int main() { int number_of_players; cin >> number_of_players; int old_bid, counter; for (counter = 0; counter < number_of_players; counter++) { int bid; cin >> bid; while (bid % 2 == 0) bid /= 2; while (bid % 3 == 0) bid /= 3; ...
#include <bits/stdc++.h> using namespace std; const long long mod = (long long)1e9 + 7; long long n, m, k; const long long moll = 998244353; long long fact(long long n) { if (n == 0) return 1; return (n * fact(n - 1)) % moll; } long long binpow(long long a, long long b) { if (b == 0) return 1;...
#include <bits/stdc++.h> using namespace std; long long n, m, i, j, a[105], b[105]; int main() { cin >> n >> m; for (i = 0; i < n; i++) cin >> a[i]; for (i = 0; i < m; i++) cin >> b[i]; for (i = 0; i < n; i++) { for (j = 0; j < m; j++) { if (a[i] == b[j]) { cout << a[i] << ...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n; cin >> n; vector<int> tree[n + 1]; for (int i = 2; i <= n; i++) { int p; cin >> p; tree[p].push_back(i); } bool is_spruce = true; for (int i = 1; i...
#include <bits/stdc++.h> using namespace std; int main() { int n; long long int s, sum = 0; cin >> n >> s; long long int* v = new long long int[n]; for (int i = 0; i < n; i++) { cin >> v[i]; sum += v[i]; } if (s > sum) cout << -1 << endl; else { sort(v, v + n)...
#include <bits/stdc++.h> using namespace std; int N, M; signed long long L[100020], R[100020], T[100020]; signed long long Q[100020]; vector<pair<signed long long, signed long long> > QP; signed long long PP[200200]; signed long long AS[200200], BS[200200], ret[200200]; vector<signed long long> S[200200...
#include <bits/stdc++.h> int main() { int q; std::cin >> q; while (q--) { int n; std::cin >> n; std::vector<int> a(n); for (int i = 0; i < n; ++i) { std::cin >> a[i]; } for (int i = 0; i < n; i += 2) { std::cout << -a[i + 1] << << a[i] << ; ...
#include <bits/stdc++.h> using namespace std; const int maxn = 200; int mn[maxn << 2], lazy[maxn << 2], gs[maxn << 2]; void push(int rt) { if (lazy[rt] == 1000000000) return; lazy[rt << 1] = lazy[rt << 1 | 1] = lazy[rt]; mn[rt << 1] = mn[rt << 1 | 1] = lazy[rt]; gs[rt << 1] = gs[rt << 1 | 1] = l...
#include <bits/stdc++.h> const double PI = 3.1415926535897932384626433; const int KL = 1e5 + 10; const long long MOD = 1e9 + 7; using namespace std; struct point { long double x, y; void go(long long x1, long long y1) { x = x1; y = y1; } void read() { cin >> x >> y; } point ope...
#include <bits/stdc++.h> using namespace std; const long long int MOD = 998244353; long long int power(long long int x, unsigned long long int y) { long long res = 1, m = y + 2; x %= m; while (y > 0) { if (y & 1) res = res * x % m; x = x * x % m; y >>= 1; } return res; } ...
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; vector<int> prime(n + 1, 0); vector<int> div(n + 1, 0); prime[1] = 1; for (long long i = 2; i <= n; i++) { if (!prime[i]) { for (long long j = i; j <= n; j += i) { prime[j] = i; ...
#include <bits/stdc++.h> using namespace std; int query(const vector<int> &S, int v, const vector<int> &T) { if (S.empty() || T.empty()) return 0; cout << S.size() << n ; for (int i = 0; i < (int)S.size(); i++) cout << S[i] + 1 << (i < (int)S.size() - 1 ? : n ); cout << T.size() << n...
#include <bits/stdc++.h> using namespace std; int main() { if (false) { freopen( input.txt , r , stdin); freopen( output.txt , w , stdout); } int n; cin >> n; vector<int> v(n + 1, -1); int xx = 1048576; long long sum = 0; for (int i = n; i > 0; i--) { if (v[i] >= ...
#include <bits/stdc++.h> using namespace std; const int N = 150007; const double eps = 1e-8; int n; double l, r, mid, sm[N], mxp[N], mnp[N]; struct note { double p, t, c; int id; } a[N], b[N]; int cmp(note x, note y) { return x.c > y.c; } int cmp0(note x, note y) { return x.p < y.p; } int ch...
#include <bits/stdc++.h> using namespace std; string tostr(int n) { stringstream rr; rr << n; return rr.str(); } long long qpow(long long n, long long k) { long long ans = 1; while (k) { if (k & 1) ans = ans * n; n = n * n; k >>= 1; } return ans; } const int mod...
#include <bits/stdc++.h> using namespace std; const int N = 5e3 + 1; int dp[N][N]; bool palid[N][N]; int main() { ios_base::sync_with_stdio(false); cin.tie(0); string s; cin >> s; int n = s.size(); for (int d = 0; d < n; d++) for (int i = 0; i < n; i++) { int j = i + d; ...
#include <bits/stdc++.h> using namespace std; int n, m, flag; int ar[101][101], ars[101][101], c[101][101], q[101][101]; int fu() { int y = 1; for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) if (ars[i][j] != c[i][j]) y = 0; return y; } void f() { flag = max(flag, fu());...
#include <bits/stdc++.h> int main() { int a, b, c, count = 0, i, j; scanf( %d%d%d , &a, &b, &c); if ((a == c) || (b == c)) { count++; } else { for (i = 0; i <= c; i += a) { for (j = 0; j <= c; j += b) { if ((i + j) == c) { count++; break; ...
#include <bits/stdc++.h> using namespace std; template <const int mod, const int modPhi> struct Mint { int v; Mint() { v = 0; } Mint(int x) { v = x % mod; if (v < 0) v += mod; } Mint(long long x) { v = x % mod; if (v < 0) v += mod; } friend bool operator==(const...
#include <bits/stdc++.h> using namespace std; int main() { int n, m, i, j, a, b, k; vector<vector<bool> > M; cin >> n; m = 5; M.resize(m); for (i = 0; i < m; i++) M[i].resize(m); for (i = 0; i < n; i++) { cin >> a >> b; a--; b--; M[a][b] = M[b][a] = true; } ...
#include <bits/stdc++.h> using namespace std; int main() { int flag = 0; char s[6][6]; for (int i = 0; i < 4; i++) for (int j = 0; j < 4; j++) cin >> s[i][j]; for (int i = 0; i < 4; i++) { if (flag) break; for (int j = 0; j < 4; j++) { if (s[i][j] == x && s[i][j + 1] == ...
#include <bits/stdc++.h> int main(void) { int n, i; scanf( %d , &n); for (i = 1; i <= n; i++) { if ((i % 2) != 0) { printf( I hate ); if (i == n) { printf( it ); break; } } else { printf( I love ); if (i == n) { printf( it...
#include <bits/stdc++.h> using namespace std; bool IO_FILE = 0; ifstream ifs( input.txt ); ofstream ofs( output.txt ); int main() { if (IO_FILE) { cin.rdbuf(ifs.rdbuf()); cout.rdbuf(ofs.rdbuf()); } int n, m; cin >> n >> m; char *s = new char[m]; bool res = 1; char prev ...
#include <bits/stdc++.h> using namespace std; vector<int> d[2], f; vector<vector<bool> > nab; int n, len = -1; const int INF = 1 << 29; int calc(vector<bool> &a, vector<bool> &b) { vector<bool> c(a.size() + b.size() + 1); for (int i = 0; i < b.size(); ++i) c[i] = b[i]; for (int i = b.size(); i <...
#include <bits/stdc++.h> using namespace std; inline void read(int &x) { x = 0; int 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(); } x ...
#include <bits/stdc++.h> using namespace std; void solve(){ int n; cin >> n; vector<int64_t> X; vector<int64_t> Y; int x,y; for (int i = 0; i < n; i++){ cin >> x >> y; X.push_back(x); Y.push_back(y); } sort(X.begin(),X.end()); ...
#include <bits/stdc++.h> using namespace std; int main() { int n, x0; cin >> n >> x0; int x = x0; int a[n][2]; for (int i = 0; i < n; i++) cin >> a[i][0] >> a[i][1]; int c = 0, d = 0; for (int i = 0; i < n; i++) { if (min(a[i][0], a[i][1]) > x) { x = min(a[i][0], a[i][1]); ...
#include <bits/stdc++.h> using namespace std; void input() { freopen( in.txt , r , stdin); freopen( out.txt , w , stdout); } const int N = 1e6 + 10; vector<int> G[N]; int in[N], n, cnt[3], vis[N]; void dfs(int x, int flag) { cnt[flag]++; vis[x] = 1; for (int i = 0; i < G[x].size(); i...
#include <bits/stdc++.h> #pragma warning(disable : 4996) int main() { int n, k; scanf( %d %d , &n, &k); int cnt = 0, a[100]; for (int i = 0; i < n; i++) { scanf( %d , &a[i]); } for (int i = 0; i < n; i++) { if (a[i] >= a[k - 1] && a[i] > 0) cnt++; } printf( %d , cnt); ...
#include <bits/stdc++.h> using namespace std; int n = 0; vector<int> v; int flag[2010]; int countt = 0; int k = 0; int maxt = 0; int main() { cin >> n; cin >> k; for (int i = 0; i < n; i++) { int kari = 0; cin >> kari; v.push_back(kari); if (i == 0) { maxt = k...
#include <bits/stdc++.h> using namespace std; int64_t k = 0; inline bool equals(string& s1, int64_t i1, int64_t j1, string& s2, int64_t i2, int64_t j2) { if (j1 != j2) { return false; } auto x = j1; for (int64_t i = 0; i < x; i++) { if (s1[i1 + i] != s2[i2 + i]) { ...
#include <bits/stdc++.h> using namespace std; struct QUERY { int query, time, number; }; void update(vector<map<int, int> > &tree, int v, int tl, int tr, int &pos, int query, int value) { if (pos < tl || pos > tr) return; if (query == 1) tree[v][value]++; else if (query == 2)...
#include <bits/stdc++.h> using namespace std; const int N = 100000 + 10; int n; int a[N]; long long query(int l, int r) { vector<pair<long long, long long> > stack; long long ret = 0; long long cur = 0; for (int i = l + 1; i <= r; ++i) { long long diff = abs(a[i] - a[i - 1]); long ...
#include <bits/stdc++.h> using namespace std; long long s, k; long long a[5000]; long long ans[5000]; int t; int dfs(int n, int m) { if (n == 0) { if (t == 1) { cout << 2 << endl; cout << 0 << << ans[0] << endl; } else { cout << t << endl; for (int i = t -...
#include <bits/stdc++.h> int cmp(const void *a, const void *b) { return (*(int *)a - *(int *)b); } long long int mod; void f(long long int p) { long long ans = 1, n = 3; while (p) { if (p & 1) ans = (ans * n) % mod; n = (n * n) % mod; p = p >> 1; } ans--; while (ans < 0) ans ...
#include <bits/stdc++.h> #pragma comment(linker, /STACK:128777216 ) const int null = 0; using namespace std; template <class T> int size(const T &a) { return int(a.size()); } template <class T> T abs(const T &a) { return (a < 0 ? -a : a); } template <class T> T sqr(const T &a) { retur...
#include <bits/stdc++.h> using namespace std; int T, x; char str[100005], ans[100005]; char usd[100005]; int main() { scanf( %d , &T); while (T--) { scanf( %s , str + 1); scanf( %d , &x); int n = strlen(str + 1); for (int i = 1; i <= n; ++i) { if (str[i] == 0 ) { ...
#include <bits/stdc++.h> using namespace std; const long long MOD = 998244353; signed main() { cin.tie(0)->sync_with_stdio(0); long long n, m; cin >> n >> m; vector<long long> pw(n + 1); pw[0] = 1; for (long long i = 1; i <= n; i++) pw[i] = 2 * pw[i - 1] % MOD; long long _ = n; vec...
#include <bits/stdc++.h> using namespace std; int main() { int t; scanf( %d , &t); while (t--) { int N; scanf( %d , &N); vector<int> a(N + 1); vector<int> b(N + 1); int sum = 0; for (int i = 1; i <= N; ++i) { scanf( %d , &a[i]); sum += a[i]; b[...
#include <bits/stdc++.h> using namespace std; int a[200000]; int b[200000]; int c[200001]; int t[200001]; vector<int> x; vector<int> ans; int add(int r, int cr, int d) { if (c[r] == t[r]) cr--; t[r] += d; if (c[r] == t[r]) cr++; return cr; } int main() { int n, m, p, i, j; sc...
#include <bits/stdc++.h> class Counter { public: Counter(std::vector<size_t> perm1, std::vector<size_t> perm2) : size_(perm1.size()) { std::vector<size_t> inv2(size_, 0); for (size_t i = 0; i < size_; ++i) { inv2[perm2[i]] = i; } auto& points = perm1; for (size_t x...
#include <bits/stdc++.h> const long long N = 3000006; using namespace std; const long long MOD = 1000000007LL; template <typename T> T gcd(T a, T b) { if (a == 0) return b; return gcd(b % a, a); } template <typename T> T power(T x, T y, long long m = MOD) { T ans = 1; while (y > 0) { ...
#include <bits/stdc++.h> using namespace std; const int MAXN = 2e5 + 9; char s[MAXN]; map<char, char> mp; int main(int argc, char const *argv[]) { int n, m; scanf( %d%d , &n, &m); scanf( %s , s); int present = 0; for (int i = 0; i < n; i++) { present |= (1 << (s[i] - a )); } ...
#include <bits/stdc++.h> using namespace std; const int MX = (int)1e6 + 17; const int MOD = (int)1e9 + 7; const long long oo = (long long)1e18 + 7; const int INF = (int)999999999; const int N = (int)1e5 + 17; const int di[4] = {-1, 0, 1, 0}; const int dj[4] = {0, 1, 0, -1}; inline long long IN() { ...
#include <bits/stdc++.h> using namespace std; int main() { long long n, k, x = -1, m, j = 0; cin >> n; cin >> k; if (k == 2) { x = 1; } if (k == 1) { x = 0; } if (k == 0) { j++; } for (int i = 1; i < n; i++) { cin >> k; if (k == 0) { j++;...
#include <bits/stdc++.h> #pragma GCC optimize( Ofast ) #pragma GCC target( avx,avx2,fma,sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native ) using namespace std; long long MOD = 1e9 + 7; int main() { ios::sync_with_stdio(0), cin.tie(0), cout.tie(0), cout << fixed << setprecision(20); ...
#include <bits/stdc++.h> using namespace std; struct scroll { int pow; int dmg; int loc; bool operator<(const scroll& a) const { if (dmg > a.dmg) return true; else if (dmg == a.dmg && pow < a.pow) return true; else return false; } }; struct used_scro...
#include <bits/stdc++.h> using namespace std; const long long MAXN = 100000; const long long oops = 1LL << 60; class Ball { public: long long value, color; } arr[MAXN + 5]; long long colorBest[MAXN + 5]; long long n; void addToTopTwo(vector<pair<long long, int> >& toptwo, long long best, ...
#include <bits/stdc++.h> using namespace std; void adskiy_razgon() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); } const int mxN = 1e+9 + 7; const long long INF = 1e+18 + 7; long long nod(long long a, long long b) { if (b > a) { swap(a, b); } while (b > 0) { a ...
#include <bits/stdc++.h> using namespace std; using ll = long long; class SegmentTree { private: vector<ll> aint; vector<ll> lazy; public: SegmentTree(int n) { aint.resize(1 + 4 * n); lazy.resize(1 + 4 * n); } void cleannode(int node, int from, int to) { int mid = (f...
#include <bits/stdc++.h> using namespace std; const int N = 333; int main() { int n, a1, a2, a3, b1, b2, b3; cin >> n >> a1 >> b1 >> a2 >> b2 >> a3 >> b3; int c1 = b1, c2 = b2, c3 = b3; while (c1 + c2 + c3 > n) { if (c3 > a3) c3--; else if (c2 > a2) c2--; else if ...
#include <bits/stdc++.h> using namespace std; int main() { int n, k, i; cin >> n >> k; vector<pair<long long, long long>> v; vector<long long> inp, p; vector<long long>::iterator it; map<long long, long long> m; for (i = 0; i < n; i++) { long long x; cin >> x; v.push_ba...
#include <bits/stdc++.h> using namespace std; vector<long long> pref_sum_a; vector<long long> pref_sum_b; signed main() { long long n; cin >> n; if (n == 2) { cout << 3 << endl; cout << 2 << << 1 << << 2 << endl; } if (n == 3) { cout << 4 << endl; cout << 2 <<...
#include <bits/stdc++.h> using namespace std; int64_t exp(int64_t a, int64_t b) { if (b == 0) return 1; int64_t c = exp(a, b / 2); c = c * c; if (b % 2 == 1) c = c * a; return c; } int main() { ios::sync_with_stdio(0); cin.tie(0); int n; cin >> n; int64_t ans = 0; for...
#include <bits/stdc++.h> using namespace std; const int MAX = 100 * 1000 + 5; const int INF = 1000 * 1000 * 1000 + 7; const long long LINF = 1LL * INF * INF; const int MOD = INF; const double PI = acos(-1.); int main() { ios_base::sync_with_stdio(0); int n, p; cin >> n >> p; int ans = INF;...
#include <bits/stdc++.h> using namespace std; int get_index(int i, int j, int k) { return i * 4 + j * 2 + k; } int diff(int i, int j) { return i != j; } pair<int, string> input() { int n; cin >> n; string s; cin >> s; return make_pair(n, s); } int work2(int n, string s) { int first_d...
#include <bits/stdc++.h> using namespace std; int main() { int n, k, s; cin >> n; vector<int> x(n); for (int i = 0; i < n; i++) cin >> x[i]; sort(x.begin(), x.end()); k = n / 2; s = x[k] - x[0]; for (int i = 1; i < n - k; i++) { s = min(s, x[k + i] - x[i]); } cout << s;...
#include <bits/stdc++.h> using namespace std; signed main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long n; cin >> n; long long cnt[1001] = {}; for (long long i = 0; i < n; ++i) { long long x; cin >> x; cnt[x]++; if (cnt[x] > (n + 1) / 2) { ...
#include <bits/stdc++.h> using namespace std; const long long INF = 0x3ffffffffffff; int main() { long long T; scanf( %lld , &T); while (T--) { long long k, n, a, b; scanf( %lld%lld%lld%lld , &k, &n, &a, &b); k -= b * n; if (k <= 0) printf( -1 n ); else pr...
#include <bits/stdc++.h> using namespace std; int dij[4444][4444]; int x[4444], y[4444]; int num[4444]; int main(void) { int n, m; scanf( %d%d , &n, &m); for (int i = 0; i < m; i++) { scanf( %d%d , &x[i], &y[i]); dij[x[i]][y[i]] = dij[y[i]][x[i]] = 1; num[x[i]]++; num[y[i]]...
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; vector<int> atk, def, ciel; for (int i = 0; i < n; i++) { string s; int x; cin >> s >> x; if (s == ATK ) atk.push_back(x); else def.push_back(x); } for (int i = ...
#include <bits/stdc++.h> using namespace std; const string pocetno = 0000000000 ; const string oznake = RGBYW ; const int maxn = 105; int N, razlicite, sol = maxn * maxn; vector<pair<int, int> > V; set<string> S; void rijesi() { for (int maska = 0; maska < (1 << 10) + 1; maska++) { S.clear()...
#include <bits/stdc++.h> using namespace std; const int fx[4][2] = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}}; const int fxx[8][2] = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}, {1, 1}, {1, -1}, {-1, 1}, {-1, -1}}; template <typename T, typename TT> ostream& operator<<(ostream& s, pair<T, TT> t) { ...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> v(2 << n); int size = 2 << n; for (int i = (2); i < (int)(size); ++i) cin >> v[i]; int ans = 0; for (int i = size - 1; i >= 2; i -= 2) { v[i / 2] += max(v[i], v[i - 1]); ans += abs(v[i] - ...
#include <bits/stdc++.h> using namespace std; int n, A, B, C, T; int temp[1005]; int main() { cin >> n >> A >> B >> C >> T; long long ans = 0; for (int i = 1; i <= n; i++) cin >> temp[i]; ans = n * A; if (C > B) { for (int i = 1; i <= n; i++) ans += (C - B) * (T - temp[i]); } c...
#include <bits/stdc++.h> using namespace std; const int N = 100100; const long long MOD = 1000000007; const double EBS = 1e-7; int dX[] = {0, 0, 1, -1}; int dY[] = {1, -1, 0, 0}; long long GCD(long long num, long long ones) { return !ones ? num : GCD(ones, num % ones); } const int L = 17; vector...
#include <bits/stdc++.h> using namespace std; int N, M; long long Ans; struct rec { int w, h, s, k; rec() {} rec(int a, int b, int c, int i) { w = a; h = b; s = c; k = i; } } P[1010], Q[1010]; int vis[1010]; bool cmp_h(const rec &a, const rec &b) { return a.h > b.h;...
#include <bits/stdc++.h> using namespace std; inline int read() { int ans = 0; char ch = getchar(); while (!isdigit(ch)) { ch = getchar(); } while (isdigit(ch)) { ans = (ans << 3) + (ans << 1) + (ch ^ 48), ch = getchar(); } ans = ans + 0 + 0; return ans; } int first[1...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); int n; cin >> n; vector<int> answer; if (n == 1000000) { cout << 1 n1000000 n ; } else { while (n) { int p = n; string w; while (p) { if (p % 10 == 0) {...
#include <bits/stdc++.h> using namespace std; const int N = 505; long long d[N][N]; long long g[N][N]; int per[N]; long long ans[N]; int n; void upd(int q) { for (int j = q; j < N; j++) { g[per[q]][per[j]] = d[per[q]][per[j]]; g[per[j]][per[q]] = d[per[j]][per[q]]; } for (int j =...
#include <bits/stdc++.h> using namespace std; inline void splay(int &v) { v = 0; char c = 0; int p = 1; while (c < 0 || c > 9 ) { if (c == - ) p = -1; c = getchar(); } while (c >= 0 && c <= 9 ) { v = (v << 3) + (v << 1) + c - 0 ; c = getchar(); } v *= ...
#include <bits/stdc++.h> using namespace std; const int N = 100010; int dp[N][310], c[N][310], lst[N], a[N], b[N]; vector<int> v[N]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, m, s, e; cin >> n >> m >> s >> e; for (int i = 0; i < n; i++) { cin >> a...
#include <bits/stdc++.h> using namespace std; map<string, int> M; map<int, string> MM; vector<int> adj[20]; int n, m; bool val(vector<int> &v) { for (int i = 0; i < v.size(); i++) { for (int j = 0; j < v.size(); j++) { if (i == j) continue; for (int k = 0; k < adj[v[i]].size(); k++...
#include <bits/stdc++.h> using namespace std; const int N = 3e4, INF = int(1e9) + 1, mod = 1e9 + 7; const long long BIG = 1e16; int n, d, a[N + 5], dp[N + 5][250 * 2 + 5]; bool w[N + 5][250 * 2 + 5]; int rec(int v, int l) { if (v > N) { return 0; } int l1 = l - (d - 250); if (w[v][l1])...
#include <bits/stdc++.h> using namespace std; const int INF = (1 << 29); const int INFF = 0x7fffffff; const long long LINF = (1ll << 60); const long long LINFF = 0x7fffffffffffffff; const long double PI = 3.14159265359; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); long long rnd(l...
#include <bits/stdc++.h> using namespace std; unordered_set<string> has_handle; unordered_set<string> is_new; unordered_map<string, string> handle; vector<string> handles_new; vector<string> handles_old; void solve(string old) { if (is_new.count(old)) return; handles_old.push_back(old); string...
#include <bits/stdc++.h> using namespace std; struct node { int x, y, e, t, d; }; vector<node> v[555][555][2]; long long sub[555][2], sum[555][555]; long long dp[2][555][555][2]; int n, m; const long long inf = 1e18; void init(int type) { for (int i = 0; i < m; i++) for (int j = 0; j < m...
#include <bits/stdc++.h> using namespace std; int main() { long long int i, j, n; set<long long int> s; cin >> n; for (i = 0; i < n; i++) { cin >> j; if (j != 0) { s.insert(j); } } cout << s.size() << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int a[200000 + 1]; struct info { int sum, prop; } t[3 * 200000 + 3]; void build(int node, int b, int e) { if (b >= e) { if (b == e) t[node].sum = a[b]; return; } int left = node << 1; int right = left | 1; int mid = (b + e) >> 1...
#include <bits/stdc++.h> using namespace std; struct RTC {}; const int maxn = 123456 + 5; int n; int root; bool humans[maxn]; vector<int> g_tmp[maxn], g[maxn]; ; bool cut(int u, int p = -1) { bool ret = humans[u]; for (int v : g_tmp[u]) { if (v == p) continue; if (cut(v, u)) { ...
#include <bits/stdc++.h> using namespace std; long long n, k; long long get(long long x, long long y) { if (x <= y * 2) return 0; long long s1 = 1, s2 = 0, p1 = x, p2 = x - 1, ans = 0; while (p2 >= y * 2) { if (p2 == y * 2) return s1 + ans; ans += s1 + s2; if (p1 & 1) s1 = s1...
#include <bits/stdc++.h> using namespace std; const int maxN = 2e5 + 5; long long int a[maxN], b[maxN]; int n; void solve() { cin >> n; set<pair<long long int, int>> s; int count = n; for (int i = 0; i < n; i++) { b[i] = 1; cin >> a[i]; s.insert({a[i], i}); } while (!...
#include <bits/stdc++.h> using namespace std; int main() { int t; scanf( %d , &t); while (t--) { int n; scanf( %d , &n); vector<int> a(n); for (int i = 0; (i) < (int)(n); (i)++) { scanf( %d , &a[i]); } queue<int> que; vector<int> ans; for (int i = ...
#include <bits/stdc++.h> using namespace std; int n, m; int a[307][307]; inline bool check(const int& i, const int& j) { return i >= 0 && i < n && j >= 0 && j < m; } int cnt_neighbors(const int& i, const int& j) { int res = 0; if (check(i - 1, j)) res++; if (check(i, j + 1)) res++; if (c...
#include <bits/stdc++.h> using namespace std; const int N = 1000 + 2; double x[4], y[4], r[4]; double dx, dy; double Fun(double dx, double dy) { double ap[4]; for (int i = 0; i < 3; i++) { ap[i] = sqrt(((x[i] - dx) * (x[i] - dx)) + ((y[i] - dy) * (y[i] - dy))) / r[i]; } double ...
#include<bits/stdc++.h> using namespace std; typedef pair<int,int> pii; typedef pair<string,int> psi; typedef pair<int,string> pis; typedef array<int,2> aii; typedef array<int,3> aiii; typedef array<int,4> aiiii; typedef unsigned long long ull; typedef long long int ll; typedef array<ll,2> all; ...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; if (n & 1) { cout << (n / 2); } else { cout << (n / 2) - 1; } }
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; for (int i = 0; i < n; i++) { int n, m; cin >> n >> m; if (n % m == 0) cout << YES << endl; else cout << NO << endl; } return 0; }