func_code_string
stringlengths
59
71.4k
#include <bits/stdc++.h> using namespace std; struct M { int x, y, z; }; int dis(int x, int y) { return abs(x - y); } signed main() { ios::sync_with_stdio(0); cin.tie(0); ; int n; cin >> n; M note[5000]; vector<bool> vs(5000, 0); for (int i = 1; i <= n; i++) { cin >> ...
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 50; struct node { int v, c, l, r, id; void read() { scanf( %d%d%d%d , &v, &c, &l, &r); } } car[N]; map<int, int> mp, MP; inline int clr(int x) { return car[x].c + car[x].l + car[x].r; } bool cmp(node a, node b) { int ta = a.c + ...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int a[n]; for (int i = 0; i < n; ++i) cin >> a[i]; int m; cin >> m; int b[m]; for (int i = 0; i < m; ++i) cin >> b[i]; sort(a + 0, a + n); sort(b + 0, b + m); int ans = 0; for (int i = 0, j = ...
#include <bits/stdc++.h> using namespace std; template <class T> inline T bigmod(T p, T e, T M) { long long int ret = 1; for (; e > 0; e >>= 1) { if (e & 1) ret = (ret * p) % M; p = (p * p) % M; } return (T)ret; } template <class T> inline T gcd(T a, T b) { if (b == 0) return...
#include <bits/stdc++.h> using namespace std; const double eps = 1e-10; const int maxn = (1 << 11) + 100; int dp[maxn][maxn]; vector<int> g[15]; int n, m, k, u, v, mx, cc[maxn]; void init() { for (int i = 0; i < maxn; ++i) cc[i] = __builtin_popcount(i); } int main() { init(); cin >> n >> m...
#include <bits/stdc++.h> using namespace std; const int MAX_N = 100001; const int MOD = 1e9 + 7; mt19937 rnd(100); int main(int argc, char* argv[]) { ios_base::sync_with_stdio(false); cin.tie(0); int n, m, x; vector<vector<int> > a; cin >> n >> m; a.assign(n, vector<int>(m)); for (...
#include <bits/stdc++.h> using namespace std; typedef long long s64; const int MaxN = 100000 + 5; int a[MaxN]; void work() { int n; scanf( %d , &n); for (int i = 1; i <= n; ++i) { scanf( %d , a + i); } sort(a + 1, a + n + 1); s64 ans = a[n]; for (int i = ...
#include <bits/stdc++.h> using namespace std; int edge[300005][5]; int num[300005], res[300005]; void dfs(int x) { int tmp = 0; for (int i = 0; i < num[x]; i++) if (res[x] == res[edge[x][i]]) tmp++; if (tmp > 1) { res[x] ^= 1; for (int i = 0; i < num[x]; i++) if (res[x] == ...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> a(n), b(n), pa(n), pb(n); for (int i = 0; i < n; ++i) { cin >> a[i]; --a[i]; pa[a[i]] = i; } for (int i = 0; i < n; ++i) { cin >> b[i]; --b[i]; pb[b[i]] = i; } ...
#include <bits/stdc++.h> using namespace std; char st[100005]; int vis[100005]; int main() { long l, cnt = 0; scanf( %ld , &l); scanf( %s , st); if (l > 26) { cout << -1; return 0; } for (long i = 0; i < l + 10; i++) vis[i] = 0; for (long i = 0; i < l; i++) { if (vi...
#include <bits/stdc++.h> using namespace std; map<pair<int, int>, int> cntmp; int n; struct Point { int x, y; } pt[200005]; bool cpx(const Point &a, const Point &b) { if (a.x != b.x) { return a.x < b.x; } return a.y < b.y; } bool cpy(const Point &a, const Point &b) { if (a.y !=...
#include <bits/stdc++.h> const int N = 1e6 + 10; const int M = 9699690; const int mod = 1e9 + 7, Gi = 332748118; const int inf = 0x3f3f3f3f; const long long INF = 0x3f3f3f3f3f3f3f3fll; const int SIZE = 1 << 21; char ibuf[SIZE], *iS, *iT; using std::pair; template <class T> void read(T &x) { x = ...
#include <bits/stdc++.h> using namespace std; int main() { int n, m, s, e, t, r; cin >> n >> m; vector<pair<int, int> > sections(n + 1); for (int i = 1; i <= n; i++) sections[i].first = 0x3f3f3f3f; while (m--) { cin >> s >> e >> t >> r; for (int i = s; i <= e; i++) { if (t < ...
#include <bits/stdc++.h> using namespace std; struct item { long long val; int ind; bool operator<(const item& o) const { return val < o.val; } }; long long n, m, k, s; vector<long long> dollar, pound, dday, pday; vector<item> ditems, pitems; void readIt() { cin >> n >> m >> k >> s; lo...
#include <bits/stdc++.h> using namespace std; const int N = 255; int parent[N]; int ra[N]; void make_set(int v) { parent[v] = v; ra[v] = 0; } int find_set(int v) { if (v == parent[v]) return v; return parent[v] = find_set(parent[v]); } void union_sets(int a, int b) { a = find_set(a...
#include <bits/stdc++.h> using namespace std; const int inf = (int)1e9; const int mod = inf + 7; const double eps = 1e-9; const double pi = acos(-1.0); int n, a[300300]; int dp[33][300300]; int calc(int bon, int ind) { if (ind == n) return 0; int &res = dp[bon][ind]; if (res != -1) return re...
#include <bits/stdc++.h> int n, sum; int a[16]; int b[4][4]; int cmp(const void *a, const void *b) { return *((int *)a) - *((int *)b); } int dfs(int x, int y, int z) { int p, q, i, j; if (x == n && y == 0) return 1; p = x; q = y + 1; if (q == n) { p = x + 1; q = 0; } fo...
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const long long INFF = 1e18; const double pi = acos(-1.0); const double inf = 1e18; const double eps = 1e-9; const long long mod = 1e9 + 7; const int maxmat = 10; const unsigned long long BASE = 133333331; inline void RI(int &...
# include<bits/stdc++.h> using namespace std; int main() { int a,b,c=0;set<int>s; cin>>a>>b; while(a) { c++; s.insert(a%b); a/=b; } if(c==s.size()) cout<< YES <<endl; else cout<< NO <<endl; return 0; }
#include <bits/stdc++.h> using namespace std; const long double E = 2.71828182845904523536; const long double pi = acos(-1); const double eps = 1e-9; const long long mod = 1e9 + 7; const long long inf = 1LL << 30; const int N = 500500; vector<int> adj[N]; vector<int> v; int dep[N]; void DFS(int u,...
#include <bits/stdc++.h> using namespace std; int c[500005], n, nm[500005], g[321]; vector<int> v[55]; char s[500005], p[500005]; inline int qr() { int x = 0, w = 1; char a = 0; while (a < 0 || a > 9 ) { if (a == - ) w = -1; a = getchar(); } while (a <= 9 && a >= 0 ) { ...
#include <bits/stdc++.h> using namespace std; int n, k; const int maxn = 500; int v[maxn + 5]; long long vv[maxn + 5]; int ans[maxn + 5]; int r[maxn + 5]; int main() { scanf( %d , &n); for (int i = 0; i < n; i++) scanf( %d , &v[i]); scanf( %d , &k); for (int i = 0; i < k; i++) scanf( %I6...
#include<bits/stdc++.h> using namespace std; typedef long long int ll; void solve(void); int main(){ int t; cin>>t; while(t--){ solve(); } return 0;} void solve(){ ll n,i; cin>>n; ll a[n+1]; for(i=1;i<=n;i++) {cin>>a[i]; } cout<<3*n<<endl; for(i=1;i<n;i++) { cout<<...
#include <bits/stdc++.h> #pragma GCC optimize( O3 ) using namespace std; enum { MOD0 = 1000000000, MOD7 = 1000000007, MOD9 = 1000000009 }; int a[200000]; long long ft[200000]; int t[800000]; int n; void inc(int index, int val) { while (index < n) { ft[index] += val; index |= index + 1; ...
#include <bits/stdc++.h> using namespace std; int main() { int n, m, min, max; std::cin >> n >> m >> min >> max; int a[m]; int maxHit = 0; int minHit = 0; for (int i = 0; i < m; ++i) { std::cin >> a[i]; if (a[i] == min) { minHit = 1; } else if (a[i] == max) { ...
#include <bits/stdc++.h> #pragma comment(linker, /STACK:1024000000,1024000000 ) using namespace std; double dp[5010], f[5010]; int main() { int T, i, j, k, ca = 0, n, m; while (~scanf( %d%d , &n, &T)) { for (i = 0; i <= T; i++) dp[i] = 0; dp[0] = 1; double ans = 0; for (i = 0; i...
#include <bits/stdc++.h> using namespace std; int main() { int a, b; cin >> a >> b; int x = abs(a - b); if (x % 2 == 0) { x /= 2; cout << x * (x + 1) << endl; } else { x /= 2; cout << x * (x + 1) + x + 1 << endl; } }
#include <bits/stdc++.h> using namespace std; const int Mx = 1e5 + 5; const long long inf = 1e9 + 1; struct Point { long long x, y; } point[Mx]; int n; long long ans, hmax[Mx], emax[Mx], hmin[Mx], emin[Mx]; template <class T> bool cmp(T a, T b) { return a.x < b.x; } bool judge(long long mi...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; if (n == 1 or n > 26) { cout << Yes n ; return 0; } set<char> s; char c; for (int i = 0; i < n; i++) { cin >> c; if (s.find(c) != s.end()) { cout << Yes n ; return 0; ...
#include <bits/stdc++.h> using namespace std; int main() { int n, l, r, shag = 0; cin >> n; l = 1; r = n; while (l <= r) { if (shag % 2 == 0) cout << l++ << ; else cout << r-- << ; shag++; } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { long long n, m, x, y, k; cin >> n >> m; long long a[n], b[m]; cin >> x >> k >> y; for (long long i = 0; i < n; i++) cin >> a[i]; for (long long i = 0; i < m; i++) cin >> b[i]; vector<long long> adj[n]; long long z[n]; lon...
#include <bits/stdc++.h> using namespace std; template <typename S, typename T> ostream& operator<<(ostream& out, pair<S, T> const& p) { out << ( << p.first << , << p.second << ) ; return out; } template <typename T> ostream& operator<<(ostream& out, vector<T> const& v) { long long l = v.s...
#include <bits/stdc++.h> using namespace std; int n, k; long long c(int a, int b) { long long res = 1; for (int i = 1; i <= b; ++i) { res = res * (a + 1 - i) / i; } return res; } int main() { scanf( %d%d , &n, &k); long long ans = 1; for (int i = 1; i <= k; ++i) { if (i...
#include <bits/stdc++.h> namespace test { struct Poly { public: using value_type = unsigned int; using ptr_type = value_type *; using const_ptr_type = value_type const *; using cast_type = unsigned long long; using size_type = unsigned int; using arr_type = value_type[1 << 21]; using ...
#include <bits/stdc++.h> using namespace std; const int maxn = 505, MOD = 1e9 + 7; struct node { node *ch[20], *fail; int cnt, id; node(node* son = NULL) { for (int i = 0; i <= 19; i++) ch[i] = son; fail = son; cnt = id = 0; } } nil, *null = &nil, *root = null, *nd[maxn]; typ...
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 1; int sp[N]; int dp[N]; int main() { ios_base::sync_with_stdio(0); const int N = 1e6 + 1; int n; cin >> n; int a[n + 1]; for (int i = 0; i < n; i++) { cin >> a[i]; } a[n] = N; for (int i = 2; i < N; i+...
#include <bits/stdc++.h> using namespace std; int main() { int n, k = 0; cin >> n; int a[n]; for (int i = 0; i < n; i++) cin >> a[i]; int count = 0; for (int i = 0; i < n; i++) { if (a[i] == 1) { count++; } } cout << count << endl; for (int i = 1; i < n; i++) ...
#include <bits/stdc++.h> using namespace std; const int N = 300005; struct seg { int v[N * 4], tp; void build(int k, int l, int r, int *a) { if (l == r) return v[k] = a[l], void(0); int mid = (l + r) / 2; build(k * 2, l, mid, a); build(k * 2 + 1, mid + 1, r, a); v[k] = (tp ? ...
#include <bits/stdc++.h> using namespace std; int main() { int n, x, c = 0; cin >> n >> x; int j = 1; for (int i = 0; i < n; i++) { int r, l; cin >> r >> l; c += l - r + 1; while (j + x <= r) { j += x; } c += r - j; j = l + 1; } cout << c << ...
#include <bits/stdc++.h> using namespace std; const long long NMAX = 1000; pair<long long, long long> func[NMAX + 5]; pair<long long, long long> tmp_func[NMAX + 5]; long long initial[NMAX + 5]; pair<long long, long long> ans[NMAX + 5]; map<pair<long long, long long>, long long> memo; int cnt_queries = 0...
#include<bits/stdc++.h> using namespace std; typedef long long ll; const int maxn = 1e6+5; const int mod = 1e9+7; const int inf = 0x3f3f3f3f; #define for1(i,n) for(int i=1;i<=n;i++) #define forn(i,n) for(int i=0;i<n;i++) int a[maxn], n,m; ll add[maxn]; vector<ll> ans; void dfs(int L, int R){ ...
#include <bits/stdc++.h> using namespace std; int n; string s1, s2; int main() { cin >> n; if (n == 1) { cout << a na nb nb ; return 0; } s1 = s2 = ; int m = n; while (m > 1) { if (s1 == || s1[s1.size() - 1] == b ) s1 += aa ; else s1 += bb...
#include <bits/stdc++.h> using namespace std; int n; int s[1005]; int us[1005]; int t[1005]; int ut[1005]; int a[1005]; int main() { scanf( %d , &n); for (int i = 0; i < n; i++) { scanf( %d , &s[i]); us[s[i]]++; } for (int i = 0; i < n; i++) { scanf( %d , &t[i]); ...
#include <bits/stdc++.h> using namespace std; const double eps = 1e-10; const double PI = atan(1.0) * 4; const int inf = 2147483647 / 2; const int maxn = 207; const int maxs = 20; const int mod = 1000000007; template <class T> bool chmin(T &a, const T &b) { return b < a ? a = b, 1 : 0; } templ...
#include <bits/stdc++.h> using namespace std; const int N = 100010; const int INF = 0x3f3f3f3f; const int iinf = 1 << 30; const long long linf = 2e18; const int MOD = 1000000007; void print(int x) { cout << x << endl; exit(0); } void PRINT(string x) { cout << x << endl; exit(0); } ...
#include <bits/stdc++.h> using namespace std; int t, n, m, a[15], ans, b[10010]; char s[15][10010]; struct P { int val, id; } p[10010]; inline bool cmp(P x, P y) { return x.val < y.val; } int main() { scanf( %d , &t); while (t--) { scanf( %d%d , &n, &m); ans = 0; for (int i =...
#include <bits/stdc++.h> using namespace std; int main() { int W, H; while (cin >> W >> H) { vector<pair<int, int>> pset; for (int dy = 0; dy < (int)(2); ++dy) for (int dx = 0; dx < (int)(2); ++dx) { if (dx <= W && dy <= H) pset.push_back(pair<int, int>(dx, dy)); } ...
#include <bits/stdc++.h> using namespace std; void print(vector<int> v) { size_t sz = v.size(); for (int i : v) { cout << i << ; } } vector<int> a, b, c; int main(void) { int n, m; scanf( %d , &n); a.resize(n); int x; for (unsigned i = 0; i < n; i++) { scanf( %d ...
#include <bits/stdc++.h> int main() { int count; std::vector<int> visitors; std::cin >> count; for (int i = 0; i < 2 * count; ++i) { int value; std::cin >> value; visitors.push_back(value); } int counter = 0; for (int i = 0; i < 2 * count; i += 2) { if (visitors[i] ...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<vector<int>> v(n); int mat[4][4] = { {8, 9, 1, 13}, {3, 12, 7, 5}, {0, 2, 4, 11}, {6, 10, 15, 14}}; int ans[n][n]; for (int i = 0; i < n * n; i++) { int x = i / n; v[x].push_back(i); } ...
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 5; int A[maxn], MAX = 0; int main() { int n; cin >> n; for (int i = 0; i < n; i++) cin >> A[i]; sort(A, A + n); int ans = 0; for (int i = 0; i < n; i++) if (ans * A[i] + ans <= i) ans++; cout << ans; retur...
#include <bits/stdc++.h> using namespace std; long long n, q, i, s1, s[100010], a[100010], k[100010], t, at, dp, sum, now; bool cmp(long long a, long long b) { return a > b; } int main() { cin >> n; for (i = 0; i < n; i++) { cin >> a[i]; } cin >> q; for (i = 0; i < q; i++) { cin ...
#include <bits/stdc++.h> using namespace std; const int maxn = 1000 + 5; int arr[maxn][maxn]; int main() { int m, n, k, p, sum = 0; bool bol = false; cin >> n >> m >> k; if (n % 2 != m % 2) { cout << 0 << endl; return 0; } if (m > n) { bol = true; swap(n, m); ...
#include <bits/stdc++.h> const long long INF = 1e17, N = 2e5 + 1; using namespace std; int a[N], n, m, k, sum[N], t[N]; int getime(int idx) { return min(idx, n - idx + 1); } int getlen(int l, int r) { if (l > r) swap(l, r); int tmp = (r - l) / m; if ((r - l) % m != 0) tmp++; return tmp; } ...
#include <bits/stdc++.h> using namespace std; vector<long long> tree; void build(vector<long long> &arr, long long ind, long long l, long long r) { if (l == r) { tree[ind] = arr[l]; return; } long long mid = (l + r) / 2; build(arr, ind * 2, l, mid); build(arr, ind * 2 + 1, mid + 1,...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int arr[26] = {0}; string s; cin >> s; transform(s.begin(), s.end(), s.begin(), ::tolower); for (int i = 0; i < n; i++) arr[s[i] - a ]++; for (int i = 0; i < 26; i++) { if (arr[i] == 0) { puts(...
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; const double pi = acos(-1); int n, i, j, k, t; long double a[100004], b[100004], val[100003]; int x[100004], c[100003]; vector<int> adj[100005]; int par[100003]; bool bisa = true; void dfs(int v, int p) { val[v] = b[v] ...
#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 lcm(long long a, long long b) { return (a * (b / gcd(a, b))); } long long bigmod(long long b, long long p, long long m) { if (p == 0) return 1; if (p % 2 == 0) { ...
#include <bits/stdc++.h> using namespace std; template <class Q> Q _min(Q x, Q y) { return x < y ? x : y; } template <class Q> Q _max(Q x, Q y) { return x > y ? x : y; } set<long long int> S; long long int a[1005][1005], b[1005][1005]; long long int lights[1005000]; long long int ans = 0, ...
#include <bits/stdc++.h> using namespace std; vector<pair<int, int>> vc; vector<pair<int, int>> vc2; int main() { int n; cin >> n; for (int i = 0; i < n; i++) { int x, y; cin >> x >> y; vc.push_back(make_pair(x, y)); } vc2 = vc; sort(vc.begin(), vc.end(), [](co...
#include <bits/stdc++.h> using namespace std; const int MAXN = 100005; int N, M; int pwr[MAXN], jump[MAXN], cnt[MAXN]; int len; void recalc(int pos) { int nxt = pos + pwr[pos]; if (nxt < N && (nxt / len) == (pos / len)) { jump[pos] = jump[nxt]; cnt[pos] = cnt[nxt] + 1; } else { ...
#include <bits/stdc++.h> using namespace std; const long long INF = 1e17 + 9; double ans = 0; vector<int> adj[100009]; int vis[100009]; double dfs(int x, double prof) { vis[x] = 1; double ret = 1 / prof; for (auto e : adj[x]) { if (vis[e] == -1) ret += dfs(e, prof + 1); } return re...
#include <bits/stdc++.h> int a[2 * 1000010]; int main() { int n, l, t, i, j, nn, k, left; scanf( %d%d%d , &n, &l, &t); nn = 2 * n; for (i = 0; i < n; i++) scanf( %d , &a[i]); for (i = n; i < nn; i++) a[i] = l + a[i - n]; k = 2 * t / l; left = 2 * t - k * l; double ans = 1.0 * (n - 1)...
#include <bits/stdc++.h> using namespace std; const int d = 5; const int MAX = 1 << d; const int TOTAL = 374; inline int bit(unsigned int mask, int k) { return (mask >> k) & 1; } int __builtin_fnz(unsigned int x) { return 31 - __builtin_clz(x); } void printm(unsigned int mask, int k = d) { for (int i ...
#include <bits/stdc++.h> using namespace std; const int INF = (int)(1e9 + 1337); const long long LINF = (long long)(4e18); const double EPS = (double)(1e-11); int n; int m; int ans; vector<vector<int> > g; vector<set<int> > s; vector<set<int> > fbd; int a[1000010]; void dfs(int v, int p) { i...
#include <bits/stdc++.h> using namespace std; int main() { int n, m; int l, r, t, c; int res = 0; cin >> n >> m; n++; int a[n]; int b[n]; for (int i = 0; i < n; i++) { a[i] = 10000; b[i] = 0; } while (m--) { cin >> l >> r >> t >> c; for (int i = l; i <...
#include <bits/stdc++.h> using namespace std; const long long MOD = 1e9 + 7; const long long MAX_N = 5e3 + 5; struct edge { long long to; long long w; long long idx; }; long long cidx; long long vr1, vr2; long long vw; vector<edge> adj[MAX_N]; long long vis[MAX_N]; pair<long long, long...
#include <bits/stdc++.h> using namespace std; long long max(long long x, long long y) { return x > y ? x : y; } long long min(long long x, long long y) { return x < y ? x : y; } void _(long long& a, long long b) { a = (a % 1000000007 + b % 1000000007) % 1000000007; a = (a + 1000000007) % 1000000007; }...
#include <bits/stdc++.h> using namespace std; int main() { int n, s; scanf( %d %d , &n, &s); long long arr[n]; for (int i = 0; i < n; i++) scanf( %lld , &arr[i]); sort(arr, arr + n); long long val = arr[n / 2]; long long cnt = abs(s - val); for (int i = 0; i < (n / 2); i++) { i...
#include <bits/stdc++.h> using namespace std; const int maxn = 100; const int inf = 0x3f3f3f3f; const int mod = 1e9 + 7; void MOD(int &x) { if (x >= mod) x -= mod; } void MOD(long long &x) { if (x >= mod) x -= mod; } long long powmod(long long x, long long n) { long long ret = 1; for (...
#include <bits/stdc++.h> using namespace std; const int N = (1e6) + 1, M = (1e7) + 1; int n, k, a[N], dp[M]; bool check(int x) { fill(dp + 1, dp + M, 0); for (int i = x; i <= (1e7); i++) dp[i] = max(dp[i >> 1] + dp[i + 1 >> 1], 1); long long sum = 0; for (int i = 0; i < n; i++) sum += dp[a[i]]; ...
#include <bits/stdc++.h> using namespace std; void fun() {} signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ; fun(); long long int c, v, u, a, l, p = 0, ans = 1; cin >> c >> v >> u >> a >> l; p += v; while (p < c) { v += a; p += min(...
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 100; int sz[N]; vector<int> g[N], g2[N]; signed main() { int n; std::cin >> n; int sum = 0; vector<int> nonOnes, ones; for (int i = 0; i < n; ++i) { std::cin >> sz[i]; sum += sz[i]; if (sz[i] > 1) { ...
#include <bits/stdc++.h> using namespace std; const int INF = 1791791791; const long long INFLL = 1791791791791791791ll; template <int input_buf_size, int output_buf_size> class FastIO { char cbuf[input_buf_size + 1]; int icur = 0; inline bool go_to_next_token() { while (cbuf[icur] == ||...
#include <bits/stdc++.h> using namespace std; int main() { int a, b, c, d; cin >> a >> b >> c >> d; int arr[4]; arr[0] = a; arr[1] = b; arr[2] = c; arr[3] = d; int cmax = b; if (c > b) cmax = c; int k = 0; if (b >= a) k++; if (c >= d) k++; if (a + c >= b) k++; ...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); int n, k; cin >> n >> k; vector<int> adj[n]; int deg[n]; for (int i = 0; i < n; i++) { deg[i] = 0; } for (int i = 1; i < n; i++) { int a, b; cin >> a >> b; ...
#include <bits/stdc++.h> using namespace std; int n, a, k; int x[200030], xx[200030]; bool judge(int m) { for (int i = 1; i <= m; i++) xx[i] = x[i]; sort(xx + 1, xx + 1 + m); int ans = 0; xx[0] = 0; for (int i = 1; i <= m; i++) ans += (xx[i] - xx[i - 1]) / (a + 1); ans += (n - xx[m] + 1)...
#include <bits/stdc++.h> using namespace std; const int N = 100000; const int inf = (int)1e9 + 1; const long long big = (long long)1e18 + 1; const int P = 239; const int MOD = (int)1e9 + 7; const int MOD1 = (int)1e9 + 9; const double eps = 1e-9; const double pi = atan2(0, -1); const int ABC = 26; ...
#include <bits/stdc++.h> using namespace std; int N, M; int used[10]; int main() { cin >> N >> M; int len1 = 1, len2 = 1; for (int a = 7; a < N; a *= 7) { ++len1; } for (int b = 7; b < M; b *= 7) { ++len2; } int answer = 0; if (len1 + len2 <= 7) { for (int i = 0...
#include <bits/stdc++.h> using namespace std; int main() { int m, n; cin >> m >> n; if (m % 2 == 0) { cout << (m * n / 2); } else { cout << ((m / 2) * n + n / 2); } return 0; }
#include<bits/stdc++.h> using namespace std; #define int long long const int maxn = 2000005; int tag[maxn],summ[maxn]; int len[maxn]; int n,k; void push_up(int p){ summ[p] = summ[p<<1] + summ[p<<1|1]; } void push_down(int p,int l,int r){ if(tag[p] == 0) return; int x = tag[p]; tag[p] = ...
#include <bits/stdc++.h> using namespace std; int a[123456]; int main() { int n, ans = 0; cin >> n; for (int i = 1; i <= n; i++) cin >> a[i]; a[n + 1] = a[0] = 0; for (int i = 1; i <= n; i++) a[i] = min(a[i], min(a[i - 1] + 1, a[i + 1] + 1)); for (int i = n; i > 0; i--) { a[i] ...
#include <bits/stdc++.h> using namespace std; int main() { int n, k; while (scanf( %d %d , &n, &k) == 2) { char s[1000005]; memset(s, 0, sizeof(s)); int t = 0; if (n == 1 && k == 1) printf( a n ); else if (k == 1) printf( -1 n ); else if (n < k) pr...
#include <bits/stdc++.h> using namespace std; const long double pi = 3.14159265358979323; const double EPS = 1e-12; const int N = 1e6 + 5; const int MOD = 1e9 + 7; long long int n, m; long long int dp[2005][2005]; long long int ad(long long int a, long long int b) { return ((a % MOD + b % MOD) % MOD...
#include <bits/stdc++.h> using namespace std; int32_t main() { long long u, v; cin >> u >> v; if (v - u < 0 || (v - u) % 2) { cout << -1; return 0; } if (u == 0 && v == 0) { cout << 0; return 0; } if (v == u) { cout << 1 << n << v; return 0; } ...
#include <bits/stdc++.h> using namespace std; bool ok1, ok2, ok3, ok4, p1, p2; int n, m, maxx, minx, maxy, miny; string a[4002]; int main() { cin >> n >> m; minx = miny = 1000000; maxx = maxy = -1000000; for (int i = 0; i < n; ++i) { cin >> a[i]; for (int j = 0; j < m; ++j) { ...
#include <bits/stdc++.h> using namespace std; typedef struct Node { int xi; int yi; }; int main() { int s, n; scanf( %d%d , &s, &n); struct Node Q[n]; int i; for (i = 0; i < n; i++) { scanf( %d , &Q[i].xi); scanf( %d , &Q[i].yi); } for (i = 0; i < n; i++) { ...
#include <bits/stdc++.h> using namespace std; const int maxn = 1e6 + 7; const int inf = 1e9; const long long inff = 1e18; const long long mod = 1e9 + 7; int a[maxn]; vector<int> v[maxn]; vector<int> tmp; int32_t main() { ios::sync_with_stdio(0); cin.tie(0); int _1 = 0, _2 = 0; int n; ...
#include <bits/stdc++.h> int main() { long long t, i, x, y, a, b; scanf( %lld , &t); for (i = 1; i <= t; i++) { scanf( %lld%lld%lld%lld , &x, &y, &a, &b); if ((y - x) % (a + b) == 0) printf( %lld n , (y - x) / (a + b)); else printf( -1 n ); } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(NULL); long long i, j, n, m; cin >> n; long long a[n - 1]; for (int i = 0; i < n - 1; i++) cin >> a[i]; long long dp[n][2][2]; memset(dp, 0, sizeof(dp)); for (int j = 0; j < 2; j++) ...
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n; cin >> n; string s; cin >> s; vector<vector<int>> lcp(n, vector<int>(n)); for (int i = n - 1; i >= 0; --i) { for (int j = n - 1; j >= 0; --j) { lcp[i][j]...
#include <bits/stdc++.h> using namespace std; string dat[64]; int dp[64][64][64][64]; int main(void) { int n, m, q; scanf( %d%d%d , &n, &m, &q); for (int i = (0); i < (int)(n); ++i) cin >> dat[i]; for (int i = (0); i < (int)(n); ++i) for (int j = (0); j < (int)(m); ++j) dp[i][j][i]...
#include <bits/stdc++.h> using namespace std; const int64_t MAXN = 1000000007; struct point { int64_t x = 0; int64_t y = 0; point(const int64_t& x, const int64_t& y) : x(x), y(y) {} static point read() { int64_t x, y; cin >> x >> y; return point(x, y); } }; double distanc...
#include <bits/stdc++.h> using namespace std; template <class L, class R> ostream& operator<<(ostream& os, pair<L, R> P) { return os << ( << P.first << , << P.second << ) ; } template <class T> ostream& operator<<(ostream& os, vector<T> V) { os << [ ; for (auto v : V) os << v << ; ...
#include <bits/stdc++.h> using namespace std; const int N = (int)2e5 + 7; int n, m, q; set<int> ds[N]; set<int> us[N]; struct T { int min_d; int max_u; bool ok; }; T operator+(T a, T b) { int min_d = min(a.min_d, b.min_d); int max_u = max(a.max_u, b.max_u); bool ok = a.ok & b.ok ...
#include <bits/stdc++.h> using namespace std; int N, M, K, dp[505][505]; char g[505][505]; bool check(int r, int c) { int dx[] = {-1, 1, 0, 0}; int dy[] = {0, 0, -1, 1}; if (r < 0 || c < 0) return false; if (g[r][c] == 0 ) return false; for (int i = 0; i < 4; ++i) { int nextR = r + dx...
#include <bits/stdc++.h> using namespace std; const int INFI = 2000000000; const int goX[4] = {-1, 0, 1, 0}; const int goY[4] = {0, 1, 0, -1}; const string PROBLEM_NAME = test ; const string INPUT_FILE = PROBLEM_NAME + .in ; const string OUTPUT_FILE = PROBLEM_NAME + .out ; ofstream fout(OUTPUT_FILE.c...
#include <bits/stdc++.h> using namespace std; void input() { freopen( give_me.txt , r , stdin); freopen( see_it.txt , w , stdout); } int main() { ios::sync_with_stdio(false); cin.tie(0); long long n, k; cin >> n >> k; long long a[n], sum = 0, w = n - k + 1; for (int i = 0; i < ...
#include <bits/stdc++.h> using namespace std; const long double eps = 1e-12; const int maxn = 100000 + 1912; const int MX = 1e6; int n; pair<int, int> a[maxn]; vector<int> p[MX * 2 + 3]; long long res = 0; void ReadData() { scanf( %d , &n); for (int i = 1; i <= n; i++) { scanf( %d%d , &a...
#include <bits/stdc++.h> using namespace std; void setIO(string name) { freopen((name + .in ).c_str(), r , stdin); freopen((name + .out ).c_str(), w , stdout); } long long inv(long long base, long long mod = 998244353) { if (base == 0) return mod; long long res = (1 - mod * inv(mod % base, b...