func_code_string
stringlengths
59
71.4k
#include <bits/stdc++.h> #pragma GCC optimize( O3 ) using namespace std; using ll = long long; const char E = n ; const int N = 1005; const ll mod = 1e9 + 7; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, k, x, dp[2][1024] = {0}; cin >> n >> k >> x; fo...
#include <bits/stdc++.h> using namespace std; const int INF = 0x7f7f7f7f; void setup() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cout.precision(15); } struct seg_tree { struct node { int val; node(int _val = 0x7f7f7f7f) { val = _val; } node operator+(co...
#include <bits/stdc++.h> using namespace std; int N, M; double K; map<string, int> skill; int main() { cin >> N >> M >> K; for (int i = 0; i < N; i++) { string name; int exp; cin >> name >> exp; if (exp * K + 0.000001 >= 100) skill[name] = exp * K + 0.000001; } for (int...
#include <bits/stdc++.h> using namespace std; template <typename T> T extGcd(T a, T b, T &x, T &y); template <typename T> T modInv(T a, T m); const int mod = (119 << 23) + 1, root = 62; template <int maxn> struct NTT { constexpr static int lg2(int n) { return 32 - __builtin_clz(n - 1); } const s...
#include <bits/stdc++.h> using namespace std; int n, m, ans[200055], odd, even, cost, ne, no; pair<int, int> a[200055]; bool need[200055]; map<int, int> M; int next_even() { while (M[ne] && ne > 0) ne -= 2; if (ne == 0) return -1; else return ne; } int next_odd() { while (M[n...
#include <bits/stdc++.h> using namespace std; const int N = 605; int dp[N][N]; int l[N], r[N]; string res; void fill(int i, int j, int a, int b) { int k = j - i; if (i > j || a > b) return; if (l[i] <= 2 * k + 1 && 2 * k + 1 <= r[i] && (i == j || dp[i + 1][j])) { res[a] = ( , res[b] = ) ...
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 18; int n, cnt[3 * N]; unsigned long long res[3 * N], sum[3 * N]; vector<int> a; int main() { ios::sync_with_stdio(0); cin.tie(0); cin >> n; long long fuk = 1LL * n * (n - 1); for (int i = 1; i <= n; i++) { int x; ...
#include <bits/stdc++.h> using namespace std; long long gcd(long long a, long long b) { if (b == 0) { return a; } return gcd(b, a % b); } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n; cin >> n; long long g = 0; for (int i = 0; i < n;...
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e5 + 5; int aa[MAXN]; int nxt[MAXN]; int nnxt[MAXN]; int step[MAXN]; int group[MAXN]; int ll[MAXN]; int rr[MAXN]; int main() { ios::sync_with_stdio(false); cin.tie(0); int n, m; memset(ll, 0x3f, sizeof ll); cin >> n ...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); string a, b; cin >> a >> b; if (a.size() == b.size()) { int ca = 0, cb = 0; for (int i = 0; i < a.size(); i++) { ca += a[i] == 1 ; cb += b[i] == 1 ; } if (!ca && cb || ca && ...
#include <bits/stdc++.h> using namespace std; template <typename T> T id(T b) { return b; }; template <class It> bool all(It f, It l) { return std::all_of(f, l, id<bool>); } template <class It> bool any(It f, It l) { return std::any_of(f, l, id<bool>); } template <typename T> void ch...
#include <bits/stdc++.h> using namespace std; signed main() { ios_base::sync_with_stdio(0); cin.tie(0); long long t; cin >> t; while (t--) { long long n; cin >> n; set<long long> s; for (long long i = 0; i < n; i++) { long long x; cin >> x; s.inser...
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; inline bool EQ(double a, double b) { return fabs(a - b) < 1e-9; } const int InF = 1 << 29; inline int two(int n) { return 1 << n; } inline int test(int n, int b) { return (n >> b) & 1; } inline void set_bit(int& n, int b) { n |= two...
#include <bits/stdc++.h> using namespace std; const int MAXN = 100 * 1000 + 1000; int arr[MAXN]; vector<int> pt[MAXN]; int mrk[MAXN]; int32_t main() { int n; cin >> n; for (int i = 0; i < n; i++) cin >> arr[i]; for (int i = 0; i < n; i++) pt[arr[i]].push_back(i); int cnt = n; int cnt...
#include <bits/stdc++.h> using namespace std; const int maxn = 2e6 + 3; long long int x[maxn], y[maxn]; long long int w[maxn]; int ct[maxn]; vector<int> v[maxn]; int ans[maxn]; int done_per[maxn]; int main() { int n, m; cin >> n >> m; for (int i = 0; i < n; ++i) { cin >> w[i]; } ...
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 7; int n, m, c[N], d[N], w[N]; bool val[N]; long long ans; struct node { int val, id; bool operator<(const node A) const { return val > A.val; } }; priority_queue<node> Q; inline int IN() { char c; int flag = 1, k = 0; ...
#include<cstdio> #include<algorithm> #include<iostream> #include<cstring> #define ll long long #define mod (ll)(1e9+7) using namespace std; ll t,n,m,a[2000005]; ll ti,yi; double xi; int main() { //freopen( 1.in , r ,stdin); cin>>n>>m; for (int i=1; i<=n; i++) { cin>>ti>>xi>...
#include <bits/stdc++.h> using namespace std; int v[300100], dp[300100], deq[300100], n, m, l, ql, qr, i; inline bool check(int v) { l = 1, ql = 0, qr = 0; dp[0] = 1; for (i = 1; i <= n; ++i) { dp[i] = 0; if (i - m >= 0 && dp[i - m]) deq[qr++] = i - m; while (::v[i] - ::v[l] > v) l++...
#include <bits/stdc++.h> using namespace std; const int N = 100005, D = 50; const int V = N * D; vector<int> g[N]; int S[V], ssz; int low[V], num[V], cnt, vis[V]; int scc[V], scc_cnt; int all[V], sz; int n, m, d; long long val[N]; void push(int i, int j) { if (val[i] >> j & 1) { all[sz++...
#include <bits/stdc++.h> using namespace std; int n, k; int cheak(int x) { int sum = x; while (x) { sum += x / k; x /= k; } if (sum >= n) return 1; return 0; } int main() { scanf( %d%d , &n, &k); int head = 1, tail = n; while (head <= tail) { int mid = (head +...
#include <bits/stdc++.h> using namespace std; const int N = 1010; int n, m; int dx[4] = {1, -1, 0, 0}; int dy[4] = {0, 0, -1, 1}; int need[4] = {2, 0, 3, 1}; int reallyNeed[4] = {0, 2, 1, 3}; int sx, sy, ex, ey; struct state { int x, y, dir; long long cost; state(int _x, int _y, int _dir, ...
#include <bits/stdc++.h> using namespace std; const long long int mod = 1e9 + 7; const long long int inf = 1e18; long long int b, d; string a, c; vector<pair<long long int, long long int>> arr(101); int main(void) { cin >> b >> d; cin >> a; cin >> c; for (int i = 0; i < c.size(); i++) { ...
#include <bits/stdc++.h> using namespace std; const double PI = acos(-1.0); template <class T> void out(const vector<T> &a) { cout << array: ; for (int i = 0; i < (int)a.size(); i++) cout << a[i] << ; cout << endl; cout.flush(); } template <class T> T gcd(T a, T b) { return (b == ...
#include <bits/stdc++.h> using namespace std; int main() { int n, a = 0, b = 0, count = 0; char ch, c; cin >> n >> c; if (c == U ) b++; else a++; n--; while (n--) { cin >> ch; if (a == b && ch != c) { count++; c = ch; } if (ch == U ) ...
#include <bits/stdc++.h> using namespace std; long long ksm(long long a, long long b) { if (!b) return 1; long long ns = ksm(a, b >> 1); ns = ns * ns % 998244353; if (b & 1) ns = ns * a % 998244353; return ns; } int chk(int x1, int y1, int x2, int y2) { cout << ? << x1 << << y1 <<...
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5; int T, n, m; int edge, ver; bool mark[N]; int ans[N]; vector<int> G[N], seen, path; void dfs(int v) { ver++; edge += G[v].size(); mark[v] = true; seen.push_back(v); for (int u : G[v]) if (!mark[u]) dfs(u); }...
#include <bits/stdc++.h> using namespace std; int n, m, in[200005], same[200005 * 4]; long long s0[200005 * 4], s1[200005 * 4], fib[200005]; long long f(long long f0, long long f1, int x) { if (x == 0) return f0; x -= 1; long long mat[2][2] = {{f1, f0}, {f0, 0}}; long long mat2[2][2] = {{1, 1}, ...
#include <bits/stdc++.h> using namespace std; long long int x[100005]; int main() { int n; long long mn, mx, md, re, ans; scanf( %d , &n); for (int i = 0; i < n; i++) scanf( %I64d , &x[i]); sort(x, x + n); mn = x[n - 1]; mx = x[0] + x[n - 1]; while (mn <= mx) { re = 0; ...
#include <bits/stdc++.h> using namespace std; int main() { int n, m, k; scanf( %d%d%d , &n, &m, &k); vector<vector<int>> sum_points(n + m), diff_points(n + m); vector<int> x(k), y(k); for (int i = 0; i < k; ++i) { scanf( %d%d , &x[i], &y[i]); sum_points[x[i] + y[i]].push_back(i); ...
#include <bits/stdc++.h> using namespace std; int n, m, i, j, a, b; inline bool valid(int x, int y, int &mx) { if (!(x % a) && !(y % b)) { int a1 = x / a; int b1 = y / b; if (!((a1 + b1) % 2)) { if (!a1 && b1 && n <= a || !b1 && a1 && m <= b) return false; int r = a1 > b1 ? a...
#include <bits/stdc++.h> using namespace std; template <typename T1, typename T2> inline ostream &operator<<(ostream &os, const pair<T1, T2> &p) { return os << ( << p.first << , << p.second << ) ; } template <typename T, size_t N> inline ostream &operator<<(ostream &os, const array<T, N> &a) { ...
#include <bits/stdc++.h> using namespace std; int n; long long ans, sum[300030], cnt[300030], tot[3]; int main() { scanf( %d , &n); tot[0] = 1; for (int i = 1; i <= n; i++) { long long x; scanf( %lld , &x); while (x) { cnt[i] += x % 2; x >>= 1; } sum[i] ...
#include <bits/stdc++.h> using namespace std; const long long int N = 1e5 + 5; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long int n, m; cin >> n >> m; vector<long long int> G[N]; for (long long int i = 0; i < m; ++i) { long long int a, b; ...
#include <bits/stdc++.h> int main() { int t, n; scanf( %d , &t); while (t--) { scanf( %d , &n); for (int i = 1; i <= n; ++i) printf( %d%c , n - i + 1, n [i == n]); } }
#include <bits/stdc++.h> using namespace std; int o = 4; int main() { char arr[o][o]; int a = 0; for (int i = 0; i < 4; i++) { for (int j = 0; j < 4; j++) cin >> arr[i][j]; } for (int i = 0; i < 4; i++) { for (int j = 0; j < 4; j++) { if (arr[i][j] == x ) { if ((...
#include <bits/stdc++.h> using namespace std; int main() { long long t, i, j, k, l, r; cin >> t; while (t--) { cin >> l >> r; if (l == r) { if (l % 2 == 0) cout << l << endl; else cout << - << l << endl; } else if (l % 2 == 1 && r % 2 == 1) { ...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); unsigned long long int n, m, i, j = 0, b; cin >> n >> m; unsigned long long int a[n]; for (i = 0; i < n; i++) cin >> a[i]; for (i = 1; i < n; i++) a[i] = a[i - 1] + a[i]; for (...
#include <bits/stdc++.h> using namespace std; vector<pair<pair<long long, long long>, int> > island; set<pair<long long, long long> > bridge; int ans[200100]; int main() { int n, m; long long l, r, prevl, prevr, a; cin >> n >> m; cin >> prevl >> prevr; for (int i = 1; i < n; i++) { c...
#include <bits/stdc++.h> using namespace std; const int N = 3e5 + 5, inf = 1e9; int n, kk, s, x, k[N][2]; char ch[N]; int fa[N << 1], val[N << 1]; int find(int u) { return fa[u] ? fa[u] = find(fa[u]) : u; } void uni(int a, int b) { if (find(a) == find(b)) return; val[find(b)] += val[find(a)]; ...
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 10, mod = 998244353; long long jc[N] = {1}, ny[N]; void Add(long long &x, long long y) { x = (x + y + mod) % mod; } long long q_pow(long long x, long long y) { long long ans = 1; for (; y; y >>= 1) { if (y & 1) ans = ans * x % mod...
#include <bits/stdc++.h> using namespace std; template <class T> int getbit(T s, int i) { return (s >> i) & 1; } template <class T> T onbit(T s, int i) { return s | (T(1) << i); } template <class T> T offbit(T s, int i) { return s & (~(T(1) << i)); } template <class T> int cntbit(T s...
#include <bits/stdc++.h> using namespace std; void sf(int &x) { scanf( %d , &x); } void sf(long long &x) { scanf( %lld , &x); } void sf(float &x) { scanf( %f , &x); } void sf(double &x) { scanf( %lf , &x); } void sf(int &x, int &y) { scanf( %d%d , &x, &y); } void sf(long long &x, long long &y) { scanf( %l...
#include <bits/stdc++.h> using namespace std; const int INF = 2147483647; const long long LLINF = 9223372036854775807LL; const int ST = 100010; const int ST1 = 1000010; const long long MOD = 1000000007; long long ABS(long long a) { if (a < 0) return a * (-1); else return a; } int m...
#include <bits/stdc++.h> using namespace std; int n, i, j, k, p = 1000000007; int A[10], B[10]; int main() { cin >> n; A[0] = 1; for (i = 1; i <= n; i++) { for (j = 0; j <= 3; j++) for (k = 0; k <= 3; k++) { if (j == k) continue; B[j] = (B[j] + A[k]) % p; } ...
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 5; const long long mod = 998244353; const double pi = acos(-1); long long fastpow(long long b, long long e) { if (!e) return 1; long long ret = fastpow(b, e / 2); ret = (ret * ret) % mod; if (e % 2) ret = (ret * b) % mod; re...
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 10; int q, num; vector<int> v[maxn]; bool vis[maxn]; void dfs(int x) { for (int i = 0; i < v[x].size(); i++) { if (!vis[v[x][i]]) { num++; vis[v[x][i]] = 1; dfs(v[x][i]); } } } int main() { ...
#include <bits/stdc++.h> using namespace std; void fastInOut() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); } const int size = 300000 + 5; void solve() { long long n; cin >> n; long long ans = 0; long long x = 1; long long ctr = 0; long long till_now =...
#include <bits/stdc++.h> using namespace std; const int N = 100100; int n; vector<pair<int, int>> a; int main() { scanf( %d , &n); for (int i = 0; i < n; ++i) { int x, y; scanf( %d%d , &x, &y); a.emplace_back(x, 1); a.emplace_back(y + 1, -1); } sort(a.begin(), a.end());...
#include <bits/stdc++.h> using namespace std; int n, t; int a[10010]; map<int, int> calc; int wow; int LIS() { int len = 0; int d[10010]; d[len] = -0x7fffffff; for (int i = 1; i <= wow; i++) { if (d[len] <= a[i]) d[++len] = a[i]; else { int mid = upper_bound(d + 1...
#include <bits/stdc++.h> using namespace std; const int MAXN = 2010; int N, M; char A[MAXN][MAXN]; int cnt[MAXN]; int main() { scanf( %d %d , &N, &M); for (int i = 0; i < N; i++) { scanf( %s , A[i]); for (int j = 0; j < M; j++) { if (A[i][j] == 1 ) { cnt[j]++; ...
#include <bits/stdc++.h> using namespace std; int main() { double a, d; int n; cin >> a >> d >> n; for (int i = 0; i < n; i++) { double temp = fmod((i + 1) * d, 4 * a); if (temp < a) printf( %.9f %.9f n , temp, 0.0); else if (temp < a * 2) printf( %.9f %.9f n , a, t...
#include <bits/stdc++.h> using namespace std; int a[1000002], b[4000000], intialsum[1000003]; int q(int ind) { int sum = 0; while (ind > 0) { sum += b[ind]; ind -= ind & (-ind); } return sum; } void u(int ind, int n, int val) { while (ind <= n) { b[ind] += val; ind ...
#include <bits/stdc++.h> using namespace std; const int MAX = 1000005; long long res[MAX], a[MAX], b[MAX]; void add(int l, int r, int x, int y) { a[l] += x; a[r] -= x + y * (r - l); b[l] += y; b[r] -= y; } int main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n;...
#include <bits/stdc++.h> const double eps = 1e-9; const int MOD = int(1e9) + 7; const int MaxN = int(2e5) + 256; using namespace std; int n, a, b; int main() { cin >> n >> a >> b; if (n > a * b) { cout << -1; return 0; } int cnt = 1; bool ok = true, r = true; for (int i =...
#include <bits/stdc++.h> using namespace std; long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); } long long qpow(long long a, long long b, long long m) { long long r = 1; a %= m; for (; b; b >>= 1) { if (b & 1) r = r * a % m; a = a * a % m; } return r; ...
#include <bits/stdc++.h> using namespace std; const int sz = 1e5 + 5; vector<tuple<int, int, int> > q; vector<int> FWT[sz]; int mt[sz]; vector<int> mapt[sz]; void update(int idx, int v, int pn) { vector<int>& x = FWT[v]; while (idx < x.size()) { x[idx] += pn; idx = idx + (idx & -idx); ...
#include <bits/stdc++.h> using namespace std; const int N = 20; int t; int n, s; string str; char n1[N]; char n2[N]; int a[N], b[N], c[N]; int main() { cin >> t; while (t--) { cin >> str >> s; int sum = 0, k = -1, pos = -1, flag = 1; for (int i = 0; i < str.size(); i++) { ...
#include <bits/stdc++.h> using namespace std; map<int, int> w, ww; set<int> second[222222]; int h, m, n, x, u, uu, e, A[311111], B[311111], g, vv[222222], os[222222], oo[222222], fl[222222]; vector<int> v[211111], s[211111]; char o; long long ans; int main() { scanf( %d%d%d n , &h, &m, &n); ...
#include <bits/stdc++.h> using namespace std; const int MAXN = 101; int n, m; string s[MAXN]; int cnt[27]; bool toDel[MAXN][MAXN]; string solve() { for (int i = 0; i < n; i++) { memset(cnt, 0, sizeof(cnt)); for (int j = 0; j < m; j++) cnt[s[i][j] - a ]++; for (int j = 0; j < m; j++)...
#include <bits/stdc++.h> using namespace std; int a[755]; long long dp[755][755]; int n, m; int main() { cin >> n >> m; for (int i = 1; i <= n; i++) cin >> a[i]; dp[n + 1][0] = 0; for (int i = n; i >= 1; i--) { for (int j = 0; j <= n; j++) { dp[i][j] = min(dp[i + 1][j] + a[i], (l...
#include <bits/stdc++.h> using namespace std; namespace fft { const int mod = 7340033; const int root = 5; const int root_1 = 4404020; const int root_pw = 1 << 20; template <class T> T eea(T a, T b, T& x, T& y) { if (!b) { x = 1; y = 0; return a; } T x1, y1; T g = eea(b...
#include <bits/stdc++.h> using namespace std; const int max_n = 111, inf = 1111111111; int n, m, q, ans[max_n][max_n]; pair<int, int> a[max_n][max_n]; int main() { scanf( %d%d%d , &n, &m, &q); for (int i = 0; i < n; ++i) { for (int j = 0; j < m; ++j) { a[i][j] = make_pair(i, j); } ...
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; char s[100005]; int main() { int i, n, cnt1, cnt2, ans1, ans2; cnt1 = cnt2 = ans1 = ans2 = 0; scanf( %d%s , &n, s); for (i = 0; i < n; i++) { if (i & 1) { if (s[i] == r ) cnt1++; } else { if (s...
#include <bits/stdc++.h> using namespace std; inline int read() { int sum = 0, t = 1; char ch = getchar(); while (ch < 0 || ch > 9 ) { if (ch == - ) t = -1; ch = getchar(); } while (ch >= 0 && ch <= 9 ) { sum = sum * 10 + ch - 0 ; ch = getchar(); } return ...
#include <bits/stdc++.h> using namespace std; int n, m, data[510]; double ans; int main() { scanf( %d%d , &n, &m); if (m == 0) { printf( %.9lf n , 0); return 0; } for (int i = 1; i <= n; i++) scanf( %d , &data[i]); for (int i = 1, x, y, z; i <= m; i++) { scanf( %d%d%d , &x,...
#include <bits/stdc++.h> using namespace std; int a[1000006], BLOCK; long long ans[200005], answer = 0; int asdf[1000006]; struct Node { int L, R, ind; } q[200005]; bool cmp(Node x, Node y) { if (x.L / BLOCK != y.L / BLOCK) return x.L / BLOCK < y.L / BLOCK; else return x.R < y.R; ...
#include <bits/stdc++.h> using namespace std; long long isPalindrome(string str) { long long l = 0; long long h = str.length() - 1; while (h > l) { if (str[l++] != str[h--]) { return -1; } } return 1; } int32_t main() { string s; cin >> s; long long n = s.size...
#include <bits/stdc++.h> using namespace std; pair<int, int> arr[100001]; int main() { int n, d, a, b; cin >> n >> d >> a >> b; for (int i = 0; i < n; i++) { int c, d; cin >> c >> d; arr[i].first = c * a + d * b; arr[i].second = i + 1; } sort(arr, arr + n); long lon...
#include <bits/stdc++.h> using namespace std; void print1d(vector<long long> &A) { for (auto i : A) cout << i << ; cout << endl; } void print2d(vector<vector<long long>> &A) { for (auto i : A) { for (auto j : i) cout << j << ; cout << endl; } } void printadj(unordered_map<l...
#include <bits/stdc++.h> using namespace std; const int N = 1510; const int MOD = 1000000007; const int SZ = 100010; inline int add(int u, int v) { return (u += v) >= MOD ? u - MOD : u; } inline int sub(int u, int v) { return (u -= v) < 0 ? u + MOD : u; } inline int mul(int u, int v) { return (long long)u...
#include <bits/stdc++.h> using namespace std; int a[101], k, i, n, check[101][101], j = 0, kil1, kil2, ans; int main() { cin >> n >> k; for (i = 1; i <= n; i++) { cin >> a[i]; } for (i = 1; i <= k; i++) { kil1 = 0; kil2 = 0; for (j = i; j <= n; j += k) { if (a[j] ==...
#include <bits/stdc++.h> using namespace std; int main() { int n, c = 0; cin >> n; int a[n], b[n]; map<int, int> mp; for (int i = 1; i <= 1001; i++) { mp[i] = 0; } for (int i = 0; i < n; i++) { cin >> a[i]; } for (int i = n - 1; i >= 0; i--) { if (mp[a[i]] == 0)...
#include <bits/stdc++.h> using namespace std; const double pi = acos(-1.0); int main() { ios_base::sync_with_stdio(false); cin.tie(0); int n; cin >> n; char x; int min, max; cin >> x >> min >> max; if (min > max) { swap(min, max); } for (int i = 0; i < n - 1; i += 1) ...
#include <bits/stdc++.h> using ll = long long; using namespace std; void solve() { ll n, k; cin >> n >> k; int mn = 2e9; for (int i = 1; i < sqrt(n) + 1; i++) { if (n % i == 0) { int y = i * k; int x = n / i * k; for (int j = 0; y / k == i; j++) { if ((y % k...
#include <bits/stdc++.h> using namespace std; const long double eps = 1e-9; const long double pi = acos(-1.0); const long double inf = 1e+9; long long gcd(long long a, long long b) { return (b == 0) ? a : gcd(b, a % b); } int xabs(int a) { return a >= 0 ? a : -a; } int sign(int a) { return (a < 0) ? -1 : ...
#include <bits/stdc++.h> using namespace std; int main() { int t; int nMin; int ans = 0; int n; int inter[150001]; cin >> t; while (t--) { ans = 0; cin >> n; for (int i = 0; i < n; i++) { cin >> inter[i]; } for (int i = n - 1; i >= 0; i--) { ...
#include <bits/stdc++.h> #pragma comment(linker, /STACK:1024000000,1024000000 ) using namespace std; const int N = 1e5 + 10, INF = 0x3f3f3f3f, MOD = 1e9 + 7; int n, a[55][55], ans[55]; int main() { ios_base::sync_with_stdio(0); while (scanf( %d , &n) == 1) { for (int i = 1; i <= n; ++i) ...
#include <bits/stdc++.h> using namespace std; int n; long long val[2001000]; int f[2001000], pre[2001000]; void getans(long long F) { for (int i = 1; i <= n + n; i++) f[i] = 0, pre[i] = i; int pl = 1; int ans = 0x7fffffff; for (int i = n + 1; i <= n + n; i++) { while (pl < i && val[i] - ...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long n; cin >> n; if (n < 3) { cout << -1; } else { long long a[n][n]; long long offset = n * n - 9; a[0][0] = 9 + offset; a[0][1] = 5 + offset; ...
#include <bits/stdc++.h> using namespace std; int main() { long long count, x, f, total = 0; std::cin >> count; long long a[count]; for (long long i = 0; i < count; i++) { std::cin >> a[i]; } std::cin >> x >> f; for (long long i = 0; i < count; i++) { total += a[i] / (f + x);...
#include <bits/stdc++.h> using namespace std; int n; int main() { scanf( %d , &n); long long ans = 0; int cur = 0; for (int i = 0; i < n; ++i) { int a; scanf( %d , &a); int p = min(cur, a / 2); a -= p * 2, cur -= p, ans += p; ans += a / 3, a %= 3; cur += a; ...
#include <bits/stdc++.h> using namespace std; pair<long double, int> v[100005]; int n; long double minn = 2 * 3.14159265358979323846264338327950288419716939937510 + 1; int minPos; int main() { cin >> n; for (int i = 1; i <= n; i++) { int x, y; cin >> x >> y; long double angle = ata...
#include <bits/stdc++.h> using namespace std; int main() { long long n, t; cin >> n >> t; int d = 1; while (t > 1) { if (t % 2) { cout << 0 << endl; return 0; } t /= 2; d++; } long long dp[60][60] = {}; dp[1][1] = 1; long long cur = 1; long...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long int n; cin >> n; long long int a[n]; for (int i = 0; i < n; i++) cin >> a[i]; sort(a, a + n); int t = a[n - 1]; a[n - 1] = a[n - 2]; a[n - 2] = t; if (a[0...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int ar[n]; int f[n + 1], cnt[n + 1]; for (int i = 0; i < n; i++) cin >> ar[i]; memset(f, 0, n + 1); memset(cnt, 0, n + 1); f[1] = 1; cnt[1] = 1; for (int i = 2; i <= n; i++) { if (ar[i - 1] > ar...
#include <bits/stdc++.h> using namespace std; const int MAXN = 5e5 + 10; vector<int> tu[MAXN]; struct node { int val, flag; } tree[MAXN * 4]; int in[MAXN], out[MAXN], fa[MAXN]; int flag, n, q, cnt; void dfs(int son, int father) { int i, k; in[son] = ++cnt; for (i = 0; i < tu[son].size();...
#include <bits/stdc++.h> const int MAX_N = 1e5 + 1; const long long int MOD = 1e9 + 7; const long long int INF = 1e9; using namespace std; void solve() { int n, max = 0, idx; cin >> n; vector<int> v(n); for (int i = 0; i < n; i++) { cin >> v[i]; if (v[i] > max) { max = v[i]...
#include<bits/stdc++.h> using namespace std; #define ll long long int #include<vector> bool fun(pair<ll,ll>a,pair<ll,ll>b) { if((a.second>b.second)) return 1; return 0; } bool chec(ll n) { ll x,c=n; while(c) { x=c%10; if(x!=0&&n%x!=0) ...
#include <bits/stdc++.h> using namespace std; const int sz = 5005; const int mod = 998244353; long long int n, a[sz], b[sz], dp[15][1005][1005], c[sz], d[sz], m, c0, d0; long long int dipi(int i, int cnt, int rem) { if (rem > n) return -100000; if (i > m) return 0; if (~dp[i][cnt][rem]) return dp[...
#include <bits/stdc++.h> using namespace std; int32_t main() { long long n, m; cin >> n >> m; for (long long i = 0; i < n; i++) cout << 1 ; cout << n ; for (long long i = 0; i < n - 1; i++) cout << 8 ; cout << 9 n ; return 0; }
#include <bits/stdc++.h> using namespace std; struct node { int to; int l, r; node() {} node(int to, int l, int r) : to(to), l(l), r(r) {} }; struct node1 { int l, r; node1() {} node1(int l, int r) : l(l), r(r) {} }; vector<node> G[1010]; vector<node1> Q[1010]; int n, m, ans ...
#include <bits/stdc++.h> using namespace std; const int N = 200010; const int LOGN = 20; const long long LLMAX = 9223372036854775807ll; vector<long long> adj[N], indexx[N]; vector<long long> costs[N]; long long baseArray[N], ptr; long long chainNo, chainInd[N], chainHead[N], posInBase[N]; long long de...
#include <bits/stdc++.h> using namespace std; int t, n, bad, w[5000 * 1000], g[5000 * 1000], p[5000 * 1000], ans[5000 * 1000], d[5000 * 1000], cnt; pair<int, int> buf[5000 * 1000]; vector<pair<int, int> > v, e; map<int, vector<pair<int, int> > > m; void go(int x) { if (w[x]) return; w[x] = 1; ...
#include <bits/stdc++.h> using namespace std; long double w, h, a; long double an; long double y; long double x, c, s; long double k; int main() { cin >> w >> h >> a; k = min(w, h); w /= k; h /= k; long double res = 0.; if (a == 0 || a == 180) { res = w * h; } else if (a ...
#include <bits/stdc++.h> using namespace std; const int N = 8e5 + 100; struct Bit { int bit[N], n; int sum(int i) { int s = 0; while (i > 0) { s += bit[i]; i -= i & -i; } return s; } void add(int i, int x) { while (i <= n) { bit[i] += x; ...
#include <bits/stdc++.h> using namespace std; long long int n, m, cev, b, a[100005], k; string s; vector<int> v; int main() { scanf( %lld %lld %lld , &n, &m, &k); if (n <= 0 && m <= 0 && n < k && m < k && k > n + m) { printf( -1 n ); return 0; } if (n < m) swap(n, m); while (n ...
#include <bits/stdc++.h> const long long MOD = 1000000007, HMOD = 1234321237, HBAS = 23333, HIBAS = 1116618209; int N, K; char a[2002], b[2002], c[2002]; long long POW[2002], IPOW[2002], HA[2002], HB[2002], HC[2002], HIA[2002], HIB[2002]; long long aemp[2002][2002], bemp[2002][2002], a...
#include <bits/stdc++.h> using namespace std; unsigned long long min(unsigned long long x, unsigned long long y) { if (x < y) return x; return y; } unsigned long long max(unsigned long long x, unsigned long long y) { if (x < y) return y; return x; } long long min(long long x, long long y) { ...
#include <bits/stdc++.h> using namespace std; int main() { long long int n, k, countt = 0, counts = 0, maxi = 0; cin >> n >> k; long long int a[n]; for (long long int i = 1; i <= n; i++) { cin >> a[i]; if (a[i] == -1) counts++; else countt++; } for (long lon...
#include <bits/stdc++.h> using namespace std; int H, M, S, X, Y; bool A, B; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> H >> M >> S >> X >> Y; A = 1; B = 1; H = H % 12; if (X > Y) { swap(X, Y); } if (S > 5 * X && S < 5 * Y) { B =...