func_code_string
stringlengths
59
71.4k
#include <algorithm> #include <bitset> #include <cmath> #include <complex> #include <cstdio> #include <iostream> #include <map> #include <numeric> #include <queue> #include <random> #include <set> #include <stack> #include <string> #include <sys/types.h> #include <unistd.h> #include <unord...
#include <bits/stdc++.h> using namespace std; long long poww(long long a, long long b, long long md) { return (!b ? 1 : (b & 1 ? a * poww(a * a % md, b / 2, md) % md : poww(a * a % md, b / 2, md) % md)); } const long long MAXN = 1e6 + 10; const long long INF = 8e18; ...
#include <bits/stdc++.h> using namespace std; struct comp { bool operator()(const vector<long long>& lhs, const vector<long long>& rhs) const { return lhs[0] > rhs[0] || (lhs[0] == rhs[0] && lhs[2] > rhs[2]) || (lhs[0] == rhs[0] && lhs[2] == rhs[2] && lhs[1] > rhs[1]); ...
#include <bits/stdc++.h> using namespace std; int a[1000000], g[1000000], h[1000000]; int d[1000000]; int dp[1000000]; int up[1000000]; int h1[1000000]; int h2[1000000]; int t1[1000000]; int t2[1000000]; vector<int> v[1000000]; int x, y, n, m; int maxy, one_kek, two_kek; void dfs(int x, int pr...
#include <bits/stdc++.h> using namespace std; int a[1003][1003]; int r[1003]; int c[1003]; char ch[5]; int main() { int n, m, k; scanf( %d %d %d , &n, &m, &k); for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) { scanf( %d , &a[i][j]); } } for (int i = 1; i <...
#include <bits/stdc++.h> using namespace std; const long long MOD = 1000 * 1000 * 1000 + 7; const double PI = acos(-1.0); long long gcd(long long a, long long b) { long long m; while (b) { m = a % b; a = b; b = m; } return a; } int solve() { string s; cin >> s; ...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); string s; cin >> s; int x = 0, y = 0; for (int i = 0; i < s.size(); i++) s[i] == x ? x++ : y++; if (x > y) for (int i = 0; i < x - y; i++) cout << x ; else for (int i = 0; i < y - x; i+...
#include <bits/stdc++.h> using namespace std; int main() { int n, req = 1; scanf( %d , &n); map<int, int> index; for (int i = 0; i < n; i++) { int x; scanf( %d , &x); if (x == req) { index[x] = i + 1 + 2000; req++; } } int cnt = 0; for (int i = 1; ...
#include <bits/stdc++.h> #pragma warning(disable : 4996) using namespace std; int n, m; char a[2000000], b[2000000]; int main() { int i, j, k; scanf( %s%s , a, b); n = strlen(a), m = strlen(b); int now = 0; for (i = 0; i < m; i++) { if (b[i] == a[now]) { now++; if (no...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int u[n + 1]; int a[n + 1][n + 1]; int maxx[n + 1]; int dom[n + 1]; for (int i = 1; i <= n; i++) { cin >> u[i]; for (int j = 1; j <= n; j++) { a[i][j] = 0; } maxx[i] = u[i]; ...
#include <bits/stdc++.h> #pragma GCC optimize( Ofast ) #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma ) #pragma GCC optimize( unroll-loops ) using namespace std; long long MOD = 998244353; double eps = 1e-12; void solve() { long long n; cin >> n; for (long long i = 0;...
#include <bits/stdc++.h> #pragma GCC optimize( O3 ) using namespace std; int main() { int T; cin >> T; while (T--) { long long n, m; cin >> n >> m; long long d = n / m; long long w = m % 10; long long sm = 0; for (int i = 0; i < 10; i++) { sm += (i * w) % 10...
#include <bits/stdc++.h> using namespace std; const int MAXN = 5000 + 10; int n, T; double p[MAXN]; int t[MAXN]; double dp[MAXN][MAXN]; int main() { scanf( %d%d , &n, &T); for (int i = 1; i <= n; ++i) { scanf( %lf%d , &p[i], &t[i]); p[i] *= 0.01; } double ans = 0.0; dp[0][0...
#include <bits/stdc++.h> using namespace std; int main() { long long int n, max = -1; cin >> n; long long int a[n], b[n]; for (int i = 0; i < n; i++) { cin >> a[i]; } for (int i = n - 1; i >= 0; i--) { if (max < a[i]) { max = a[i]; b[n - i] = 0; } else { ...
#include <bits/stdc++.h> using namespace std; const int MAXBUF = 10000; char buf[MAXBUF], *ps = buf, *pe = buf + 1; inline bool isdigit(const char& n) { return (n >= 0 && n <= 9 ); } inline void rnext() { if (++ps == pe) pe = (ps = buf) + fread(buf, sizeof(char), sizeof(buf) / sizeof(c...
#include <bits/stdc++.h> using namespace std; const int N = 100005; inline int in() { int x; scanf( %d , &x); return x; } inline long long lin() { long long x; scanf( %I64d , &x); return x; } vector<int> G[N + N]; pair<int, int> edg[N + N]; int n, k, start; int inp[N + N]; ...
#include <bits/stdc++.h> using namespace std; bool test(long long, long long, long long); int main(void) { long long n, m; cin >> n >> m; long long first, last; first = 0; last = sqrt(2 * n) + 1; if (m >= n) { cout << n; return 0; } while (test(first, n, m) == 0) { ...
#include <bits/stdc++.h> using namespace std; char s[50005]; map<string, int> st; int sq = 300; vector<int> p[500100]; vector<int> h; string s1[500100]; int res[1010][1010]; void pro(int x1, int y1) { int x = h[x1]; int y = h[y1]; int pri = -1, prj = -1; int mn = 1e9; int r; fo...
#include <bits/stdc++.h> using namespace std; long long n, m, a[1000500]; map<pair<int, long long>, bool> dp; bool found = false; void solve(int idx, long long sum, bool take) { if (found) return; if (take && sum % m == 0) { found = true; return; } if (idx >= n) return; bool &r...
#include <bits/stdc++.h> using namespace std; inline int read() { char c = getchar(); int x = 0, f = 1; for (; !isdigit(c); c = getchar()) if (c == - ) f = -1; for (; isdigit(c); c = getchar()) x = x * 10 + c - 0 ; return x * f; } const int MAXN = 8e3 + 5; int nxt[MAXN], p[MAXN][MA...
#include <bits/stdc++.h> using namespace std; template <typename T> void maxtt(T& t1, T t2) { t1 = max(t1, t2); } template <typename T> void mintt(T& t1, T t2) { t1 = min(t1, t2); } bool debug = 0; int n, m, k; string direc = URDL ; const long long MOD2 = (long long)1000000007 * (long lon...
#include <bits/stdc++.h> using namespace std; struct abc { int p, q, idx; }; bool compareTwoStudents(abc a, abc b) { if (a.p != b.p) return a.p < b.p; return (a.q < b.q); } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int i, j, k, m, n, t, u, v, w, p = 0, q, flag = 0...
#include <bits/stdc++.h> using namespace std; template <typename T> void out(T x) { cout << x << endl; exit(0); } const int maxn = 2000 + 7; int n; long double p; int t; long double dp[maxn][maxn]; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >>...
#include <bits/stdc++.h> #pragma GCC optimize(3, Ofast , inline ) #pragma GCC target( avx ) using namespace std; template <class t> inline t read(t &x) { char c = getchar(); bool f = 0; x = 0; while (!isdigit(c)) f |= c == - , c = getchar(); while (isdigit(c)) x = (x << 1) + (x << 3) + ...
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 100; int a[N]; int per[N]; int main() { int n; cin >> n; for (int i = 0; i < n - 1; i++) { scanf( %d , &a[i]); } int ls = a[0]; set<int> st; for (int i = 1; i <= n; i++) { st.insert(i); } for (int...
#include <bits/stdc++.h> int a, b, c; long long int MOD; long long int Comb[110][110]; long long int comb(int a, int b) { if (a == b) return 1; if (b == 0) return 1; if (Comb[a][b] != -1) return Comb[a][b]; return Comb[a][b] = (comb(a - 1, b - 1) + comb(a - 1, b)) % MOD; } int check[110][110...
#include <bits/stdc++.h> const long long INF = 2 * 1e9; const long long MOD = 1000000007; using namespace std; void solve() { long long n, k, m; cin >> n >> k >> m; vector<long long> a(n); vector<pair<long long, long long> > c; long long x; cin >> x; c.push_back({x, 1}); long lon...
#include <bits/stdc++.h> using namespace std; int main() { long long int n; cin >> n; long long int ans = 0; if (n == 1 || n == 2) { cout << n << endl; return 0; } for (long long int i = 1; i <= (sqrt(n)); i++) { if (n % i == 0) ans += 2; if (i * i == n) ans = ans - 1...
#include <bits/stdc++.h> using namespace std; template <typename _T> inline void read(_T &f) { f = 0; _T fu = 1; char c = getchar(); while (c < 0 || c > 9 ) { if (c == - ) { fu = -1; } c = getchar(); } while (c >= 0 && c <= 9 ) { f = (f << 3) + (f << ...
#include <bits/stdc++.h> using namespace std; int main() { int n; map<int, int> m; cin >> n; int a[n]; for (int i = 0; i < n; i++) { cin >> a[i]; m[a[i]]++; } int chek[32]; chek[0] = 2; for (int i = 1; i < 32; i++) { chek[i] = chek[i - 1] * 2; } int sm =...
#include <bits/stdc++.h> #define testCase int T; cin>>T; while(T--) #define int long long #define Endl endl using namespace std; /* */ const int N = 1e5+13, LMAX = 3e18 + 13, IMAX = 1e9 + 5, mod = 1e9 + 7; //998244353; int32_t main() { ios_base::sync_with_stdio(false); cin.tie(nu...
#include <bits/stdc++.h> using namespace std; int main() { long long n, k, a[300001], seti = 0, l, r, z = 0, maxi = 0, fz, lt = -1, rt = -1; cin >> n >> k; for (long long i = 0; i < n; i++) cin >> a[i]; l = 0; for (long long i = 0; i < n; i++) { if (a[i] == 0...
#include <bits/stdc++.h> using namespace std; template <typename Arg1> void __f(const char* name, Arg1&& arg1) { cout << name << : << arg1 << n ; } template <typename Arg1, typename... Args> void __f(const char* names, Arg1&& arg1, Args&&... args) { const char* comma = strchr(names + 1, , ); ...
#include <bits/stdc++.h> #pragma GCC optimize( O3 ) using namespace std; struct Point { int x; int y; }; int direction(Point a, Point b, Point c) { return (c.x - a.x) * (b.y - a.y) - (c.y - a.y) * (b.x - a.x); } bool onsegment(Point a, Point b, Point c) { return (min(a.x, b.x) <= c.x && ma...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> a; while (n) { int x = n, p = 1, m = 0; while (x) { if (x % 10) m += p; x /= 10; p *= 10; } n -= m; a.push_back(m); } cout << a.size() << endl; fo...
#include <bits/stdc++.h> int main() { long long n; scanf( %lld , &n); long long a[1000005] = {0}; for (int i = 1; i <= n; i++) { scanf( %lld , &a[i]); } long long ans = 0; for (int i = 1; i <= n; i++) { ans = ans + a[i] * i - (i - 1); } printf( %lld , ans); return 0...
#include <bits/stdc++.h> using lint = long long; using ld = long double; template <class T> using numr = std::numeric_limits<T>; struct input_t { template <class T> operator T() { T t; std::cin >> t; return t; } } input; namespace ns { using namespace std; template <int m...
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 500; const int inf = 1e9 + 5; struct node { int l, r; } b[N]; bool cmp(node a, node b) { return a.l < b.l; } bool rcmp(node a, node b) { return a.r > b.r; } int n, m, a[N], cnt, rt, ls[N * 32], rs[N * 32], sz[N * 32], vl[N * 32], Big[...
#include <bits/stdc++.h> using namespace std; typedef long long LL; typedef pair<int, int> PII; typedef pair<LL,LL> PLL; const int INF = 0x3f3f3f3f, N = 1e5 + 10; inline int lc(int u) {return u << 1;} inline int rc(int u) {return u << 1 | 1;} inline int lowbit(int x) {return x & (-x);} int y[27] = {10...
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 10; int n, k, root, ans; vector<int> g[N]; int dfs(int u, int f) { if (g[u].size() == 1) return 0; vector<int> d; for (int v : g[u]) if (v != f) d.push_back(dfs(v, u) + 1); sort(d.begin(), d.end()); int sz = d.size(); ...
#include <bits/stdc++.h> #pragma GCC optimize( Ofast,no-stack-protector,unroll-loops ) #pragma GCC optimize( no-stack-protector,fast-math ) using namespace std; const long long N = 1e6 + 100, OO = 724249387, T = (1 << 20) + 10, M = 998244353, P = 6151, SQ = 280, lg = 64; long long n, m, k, n...
#include <bits/stdc++.h> using namespace std; inline int read() { char ch = getchar(); int res = 0, flag = 1; while (ch < 0 || ch > 9 ) { if (ch == - ) flag = -1; ch = getchar(); } while (ch >= 0 && ch <= 9 ) { res = res * 10 + ch - 0 ; ch = getchar(); } r...
#include <bits/stdc++.h> using namespace std; const int MAX = int(1e9 + 5); const long long MAXL = long long(1e18 + 5); const long long MOD = long long(1e9 + 7); const long long MOD2 = long long(998244353); void fastio() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); return; ...
#include <bits/stdc++.h> using namespace std; const long long N = 1e3 + 10; long long n, m, ans, h[N][N]; char ar[N][N]; bool get(long long i, long long j) { long long x = h[i][j]; i -= x; if (i < 0) return 0; if (h[i][j] != x) return 0; i -= x; if (i < 0) return 0; return h[i][j] ...
#include <bits/stdc++.h> using namespace std; void solve(int test_case) { int a, b; cin >> a >> b; cout << b % max(b / 2 + 1, a) << n ; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int t; cin >> t; for (int test_case = 1; test_case <= t; ++test_case) { so...
#include <bits/stdc++.h> using namespace std; int a[1000001]; int mod = 1000000007; int f(int x, int y) { int res = 1; long long xx = x; while (y > 0) { if (y % 2) res = (res * xx) % mod; xx = (xx * xx) % mod; y = y / 2; } return res; } int main() { int t, p; in...
#include <bits/stdc++.h> using namespace std; int n; char grid[101][101]; bool rw[101], cl[101]; int main() { bool f, r = 0, c = 0; int cnt; scanf( %d , &n); for (int i = 0; i < n; ++i) { scanf( %s , grid[i]); f = 1; for (int j = 0; j < n; ++j) { f &= (grid[i][j] == ...
#include <bits/stdc++.h> int main() { int n, k, a[4] = {2, 3, 4, 5}, x, min = 250; scanf( %d %d , &n, &k); if (n * 5 == k || n * 3 == k || n * 4 == k) { printf( 0 ); return 0; } for (int i = n; i >= 0; i--) { x = i * 5; if (x > k) continue; for (int j = n; j >= 0; j--...
#include <bits/stdc++.h> using namespace std; bool check(vector<vector<int>> &a, int n, int x) { deque<pair<int, int>> q; map<pair<int, int>, bool> was; q.push_back({1, 1}); was[{1, 1}] = true; int dx[] = {1, 0, -1, 0}; int dy[] = {0, 1, 0, -1}; while (!q.empty()) { auto u = q.fron...
#include <bits/stdc++.h> using namespace std; long long t[5005], c[5005], ans[5005], n, i, l, b, v; int main() { cin >> n; for (i = 1; i <= n; i++) cin >> t[i]; for (l = 1; l <= n; l++) { for (i = 1; i <= n; i++) c[i] = 0; b = 0; for (i = l; i <= n; i++) { v = t[i]; c...
#include <bits/stdc++.h> int main() { int l, r, a, n; scanf( %d %d %d , &l, &r, &a); if (l > r) { if (r + a < l) { printf( %d n , 2 * (r + a)); } else { n = r + a - l; printf( %d n , 2 * (l + n / 2)); } } else { if (l + a < r) { printf( %d n , 2 ...
#include <bits/stdc++.h> using namespace std; const int N = 200010; pair<int, int> bug[N]; pair<int, pair<int, int> > stud[N]; set<pair<int, int> > smart; int ans[N]; int studs, bugs, exams; long long solve(int days) { long long sum = 0; smart.clear(); int last = 0; for (int i = 0; i < b...
#include <bits/stdc++.h> using namespace std; int main() { double a, b, mn = 1e12; cin >> a >> b; int n; cin >> n; while (n--) { double x, y, v, dis; cin >> x >> y >> v; dis = sqrt((a - x) * (a - x) + (b - y) * (b - y)); dis /= v; mn = min(mn, dis); } cout <...
#include <bits/stdc++.h> using namespace std; struct node { int to, id; }; vector<node> E[10005]; vector<int> Ans; int dep[10005], fa[10005][15], Id[10005], S1[10005], S0[10005], Stk[10005], cnt, n1, n, m; bool mk[10005], Mk[10005]; void dfs(int x, int f) { mk[x] = 1; dep[x] = dep[f] +...
#include <bits/stdc++.h> using namespace std; const double PI = acos(-1.0); const int N = 1e6 + 5; int f[N]; int a[] = {1, 2}; int na = 2; int main() { int cnt; cin >> cnt; if (cnt == 1) { cout << 1 1 n1 ; return 0; } int x = 1; for (int i = 2; i < N; i++) { if (...
#include <cstdio> #include <cmath> long long T, n; bool flag; int main() { scanf( %d , &T); for(int t = 1; t <= T; t ++) { scanf( %lld , &n); flag = false; for(long long i = 2; i <= n; i *= 2) { if(n == i) { printf( NO n ); flag = true; break; } }...
#include <bits/stdc++.h> using namespace std; const int maxn = 3020; long long a[maxn], b[maxn]; long long dp1[maxn][maxn]; int n; bool cmp(int x, int y) { return x > y; } int main() { while (cin >> n) { for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 0; i < n; i++) { a[i] -=...
#include <bits/stdc++.h> #pragma GCC optimize( O2,unroll-loops ) using namespace std; const int inf = 1000000010; const long long INF = 1000000000000001000LL; const int mod = 1000000007; const int MAXN = 100200, SQ = 320, NSQ = MAXN / SQ + 1; int n, m, w, u, v, x, y, t, a, b, maxb; int A[MAXN], B[MAXN],...
#include <bits/stdc++.h> using namespace std; using namespace std::chrono; long long mod = 1000000007; void __print(int x) { cerr << x; } void __print(long x) { cerr << x; } void __print(long long x) { cerr << x; } void __print(unsigned x) { cerr << x; } void __print(unsigned long x) { cerr << x; } vo...
#include <bits/stdc++.h> #define int long long #define f(i,a,n) for (int i = a; i < n; ++i) #define f1(i,a,n) for(int i=n-1;i>=a;i--) #define ff first #define ss second #define pb push_back #define mp make_pair #define all(x) x.begin(), x.end() #define sortall(x) sort(all(x)) #define fastio ios_base...
#include <bits/stdc++.h> using namespace std; int tt; int n, m; int main() { scanf( %d , &tt); while (tt--) { scanf( %d %d , &n, &m); long long z = (n - m), g = m + 1; long long k = z / g; long long ans = (n * 1ll * (n + 1) / 2) - (k * (k + 1) / 2) * g - (k + 1) * (z % ...
#include <bits/stdc++.h> using namespace std; int n, F[500007], wartosc[500007], Fat[500007]; bool valid_number[500007], valid_edges[300007], query_node[500007]; int Find(int a) { return (a == Fat[a] ? a : Fat[a] = Find(Fat[a])); } inline void Union(int a, int b) { a = Find(a); b = Find(b); F[a] =...
#include <bits/stdc++.h> using namespace std; int a[200005]; int main() { int t, k, i, j, n, m, x, y, q, c; cin >> n >> k; if ((n - 1) % k >= 2) { printf( %d n , 2 * ((n - 1) / k) + 2); } else if ((n - 1) % k == 1) { printf( %d n , 2 * ((n - 1) / k) + 1); } else { printf( %d ...
#include <bits/stdc++.h> using namespace std; int N, Y[50001]; set<int> pos[50001]; set<int> used; priority_queue<int> q; int next(int x) { int temp = x; while (x != 0) { if (used.count(x) == 0) return x; x /= 2; } return temp; } int main() { cin >> N; for (int i = 0;...
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 3; int a[maxn], b[maxn], c[maxn], sum; int main() { int n; cin >> n; for (int i = 1; i <= n; i++) { cin >> a[i]; sum += a[i]; } int ans = 0, cnt = 0; for (int i = 1; i <= n; i++) { ans += a[i]; c...
#include <bits/stdc++.h> using namespace std; int main() { int a, b, l, r, c, pl, pr, cl, cr; cin >> a >> b >> l >> r; c = a + b; cl = --l / c; cr = --r / c; pl = l % c; pr = r % c; if (cl == cr) { if (pl < a && pr < a) { cout << pr - pl + 1 << endl; } else if (pl...
#include <bits/stdc++.h> using namespace std; int gcd(int x, int y) { return (!y ? x : gcd(y, x % y)); } const int maxn = 2e5; vector<int> g[maxn], tree[maxn]; map<pair<int, int>, int> we; int par[maxn]; int gpar(int v) { return (par[v] == v ? v : par[v] = gpar(par[v])); } bool mrg(int u, int v) { u...
#include <bits/stdc++.h> using namespace std; long long bbuy(long long* c, long long l, int n); int main() { long long n, l; cin >> n >> l; long long c[n]; for (int i = 0; i < n; ++i) { cin >> c[i]; } long long bp = c[0]; for (int i = 0; i < n; ++i) { bp *= 2; bp = mi...
#include <bits/stdc++.h> using namespace std; namespace std { template <> struct hash<pair<int, int>> { size_t operator()(const pair<int, int> &x) const { long long P = 38923, Q = 109797901; return (size_t)((x.first * P + x.second) % Q); } }; }; // namespace std template <class T> u...
#include <bits/stdc++.h> using namespace std; template <typename T> inline T qmin(const T a, const T b) { return a < b ? a : b; } template <typename T> inline T qmax(const T a, const T b) { return a > b ? a : b; } template <typename T> inline void getmin(T &a, const T b) { if (a > b) a = b...
#include <bits/stdc++.h> #pragma comment(linker, /STACK:100000000000000 ) using namespace std; const long long int INF = 2e9; void init(vector<int> &dsu) { for (int i = 0; i < ((int)(dsu).size()); i++) { dsu[i] = i; } } int find_p(vector<int> &dsu, int id) { if (dsu[id] == id) return id; ...
#include <bits/stdc++.h> using namespace std; template <class A, class B> inline bool mina(A &first, B second) { return (first > second) ? (first = second, 1) : 0; } template <class A, class B> inline bool maxa(A &first, B second) { return (first < second) ? (first = second, 1) : 0; } const int ...
#include <bits/stdc++.h> using namespace std; const int inf = (int)1e9 + 7; const double pi = 3.14159265358979323846; template <class T> T sqr(T x) { return x * x; } double len(const pair<int, int> &p1, const pair<int, int> &p2) { return sqrt(sqr((long long)p1.first - p2.first) + s...
#include <bits/stdc++.h> using namespace std; const int MAX = 2e5 + 4; string s; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); ; cin >> s; long long n = s.size(); long long sub = 0; for (int k = 1; k <= 8; k++) { for (int i = 0; i + k <...
#include <bits/stdc++.h> using namespace std; const int N = 3E4 + 7; int x[N], y[N]; void solve() { int n; cin >> n; int a[n]; for (int i = 0; i < n; i++) cin >> a[i]; x[0] = a[0], y[0] = 0; for (int i = 1; i < n; i++) { x[i] = min(x[i - 1], a[i]), y[i] = a[i] - x[i]; if (y[i...
#include <bits/stdc++.h> using namespace std; const int maxn = 200000 + 10; struct Tree { int tl, tr; int mx; } tree[maxn << 2]; set<int> st[maxn]; int ve[maxn], n, m; void build(int id, int l, int r) { tree[id].tl = l; tree[id].tr = r; tree[id].mx = -1; if (l == r) return; int...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long int n, k; cin >> n >> k; string s[n + 1]; set<string> ar; for (int x = 0; x < n; x++) { cin >> s[x]; ar.insert(s[x]); } char a[3] ...
#include <bits/stdc++.h> using namespace std; long long gcd(long long a, long long b) { return (a ? gcd(b % a, a) : b); } long long power(long long a, long long n) { long long p = 1; while (n > 0) { if (n & 1) { p = p * a; } n >>= 1; a *= a; } return p; } long l...
#include <bits/stdc++.h> using namespace std; int x, y; int n, m, k; int main() { cin >> n >> m >> k; for (int i = 0; i < k; i++) { cin >> x >> y; if (x <= 5 || y <= 5 || n - x <= 4 || m - y <= 4) { cout << YES << endl; return 0; } } cout << NO << endl; ...
#include <bits/stdc++.h> #pragma comment(linker, /stack:100000000 ) using namespace std; const int N = 155; const int INF = 1000000000; struct Edge { int to, flow, cap, cost; Edge() {} Edge(int to, int flow, int cap, int cost) : to(to), flow(flow), cap(cap), cost(cost) {} }; vector<Ed...
#include <bits/stdc++.h> using namespace std; int main() { long long int i, t, c, sum = 0; cin >> t; long long int a[t]; for (i = 0; i < t; i++) { cin >> a[i]; } for (i = 0; i < t; i++) { sum += a[i]; } if (sum % 2 == 0) { cout << sum << endl; } else { lon...
#include <bits/stdc++.h> int main() { int n, s[10001], ss[10001]; scanf( %d , &n); for (int i = 1; i <= n; i++) scanf( %d , &s[i]); for (int i = 1; i < n; i++) { ss[i] = abs(s[i] - s[i + 1]); } ss[n] = abs(s[n] - s[1]); int t, min = 999999; for (int i = 1; i <= n; i++) { if...
#include <bits/stdc++.h> using namespace std; const int N = 132700; int n; tuple<int, int, int, int> esq[N], dir[N]; vector<tuple<int, int, int, int>> v; int main(void) { ios_base::sync_with_stdio(false); cin >> n; for (int i = 0; i < n; i++) { int a, b, c, d; cin >> a >> b >> c >> d...
#include <bits/stdc++.h> using namespace std; long long dp[2010][2010]; int a[2010]; int p[2010]; bool used[2010]; bool ok[2010]; int main() { int n; cin >> n; dp[0][0] = 1; int rem = 0; for (int i = 0; i < n; i++) { cin >> a[i]; if (a[i] != -1) { used[a[i] - 1] = t...
#include <bits/stdc++.h> using namespace std; int a, b; int main() { cin >> a >> b; if (abs(a - b) <= 1 && (a || b)) { cout << YES << endl; } else { cout << NO << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; void Q_Q() { ios::sync_with_stdio(0); ios_base::sync_with_stdio(0); cin.tie(0), cout.tie(0); } map<int, bool> mp; int main() { Q_Q(); int n, k; double t; cin >> n >> k >> t; int arr[n]; long long int sum = 0; for (int i = 0;...
#include <bits/stdc++.h> using namespace std; int main() { unsigned int n, m, l; cin >> n >> m >> l; int s = 0; while (l--) { s += 2 * (n + m - 2); n -= 4; m -= 4; } cout << s; }
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 2; long long d, k, a, b, t; int main() { cin >> d >> k >> a >> b >> t; if (d <= k) { cout << d * a; } else if (t + k * a > k * b) { cout << k * a + (d - k) * b; } else { long long cnt = d / k; long long ans...
#include <bits/stdc++.h> using namespace std; int main() { long long n, i; scanf( %I64d , &n); if (n <= 3) { printf( 1 ); return 0; } if (n == 4) { printf( 2 ); return 0; } if (n % 2 == 0) printf( 2 ); else { bool u = 1; for (i = 2; i * i <= ...
#include <bits/stdc++.h> using namespace std; long long mod = 1e9 + 7; long long inf = 4e18; const long long N = 2e5 + 5; long long ans[N]; signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long tt = 1; while (tt--) { long long n; cin >> n;...
#include <bits/stdc++.h> using namespace std; const int a[6] = {3, 3, 3, 2, 2, 1}; const int b[6] = {2, 1, 0, 1, 0, 0}; const int inf = 1000000000; const double eps = 1e-6; int Dist[6]; double X[7]; int Round(double X) { int T = (int)X; if (T + 1 - X < eps) T++; return T; } bool Check(in...
#include <bits/stdc++.h> using namespace std; const int MO = 1e9 + 7; int n, K; long long dp[105][44], tt[44]; vector<int> e[105]; void add(long long &x, long long y) { x = (x + y) % MO; } void mul(long long &x, long long y) { x = x * y % MO; } void dfs(int u, int f) { dp[u][K + 1] = 1; dp[u][0]...
#include <bits/stdc++.h> using namespace std; long long n, m, val[105], c[105][105], pref[105][105], calc[105][105], dp[105][10005]; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n >> m; for (long long i = 1; i <= n; ++i) { cin >> val[i]; for (long...
#include <bits/stdc++.h> using namespace std; int main() { int n, t[90]; bool ans = false; cin >> n; for (int i = 0; i < n; i++) { cin >> t[i]; } if (t[0] > 15) { cout << 15; ans = true; } for (int i = 0; i < n - 1 && ans == false; i++) { t[i] += 15; if ...
#include <bits/stdc++.h> using namespace std; template <typename Abel> struct BIT2D { vector<vector<Abel>> dat[4]; BIT2D(int h, int w) { for (int which = 0; which < 4; which++) dat[which].assign(h + 1, vector<Abel>(w + 1)); } inline void sub_add(int which, int a, int b, Abel x) { ...
#include <bits/stdc++.h> using namespace std; void solve() { long long n; cin >> n; long long x = n * (n * n + 1) / 2; vector<long long> a[101]; for (long long j = 0; j < n / 2; j++) for (long long i = 1; i < n + 1; i++) { long long x = n * j + i; a[i].push_back(x); ...
#include <bits/stdc++.h> using namespace std; template <class T> T power(T a, T b) { T x; if (b == 0) x = 1; else x = a; for (size_t i = 1; i < b; i++) x *= a; return x; } long long int gcd(long long int a, long long int b) { return b == 0 ? a : gcd(b, a % b); } long lo...
#include <bits/stdc++.h> using namespace std; int main() { int n, k; scanf( %i%i , &n, &k); if (k * 2 >= n) printf( -1 n ); else { printf( %i n , n * k); for (int i = 0; i < n; i++) for (int j = 0; j < k; j++) printf( %i %i n , i + 1, (i + j + 1) % n + 1); } return ...
#include <bits/stdc++.h> using namespace std; vector<long long> lucky; void backtrack(long long num) { if (num > 10000000000) return; lucky.push_back(num); backtrack(num * 10 + 4); backtrack(num * 10 + 7); } int main() { backtrack(0); sort(lucky.begin(), lucky.end()); pair<long lon...
#include <bits/stdc++.h> using namespace std; vector<int> Neighbors[2000000]; bool Visited[2000000]; bool Leaf[2000000]; char Color[500001]; queue<int> Queue; void bfs(int i) { Visited[i] = true; Queue.push(i); while (Queue.empty() == false) { int u = Queue.front(); Queue.pop(); ...