func_code_string
stringlengths
59
71.4k
#include <bits/stdc++.h> using namespace std; void getre() { int x = 0; printf( %d n , 1 / x); } void gettle() { int res = 1; while (1) res <<= 1; printf( %d n , res); } template <typename T, typename S> inline bool upmin(T &a, const S &b) { return a > b ? a = b, 1 : 0; } templ...
#include <bits/stdc++.h> using namespace std; const int N = 30; long long n, a[N], ans, limit = 1e9 + 10; int main() { cin >> n; for (int i = 0; i < n; i++) cin >> a[i]; sort(a, a + n); reverse(a, a + n); for (int i = 0; i < n; i++) { ans += min(a[i], limit); limit = min(limit - ...
#include <bits/stdc++.h> using namespace std; int Read() { int x = 0, f = 1; char ch = getchar(); while (!isdigit(ch)) { if (ch == - ) f = -1; ch = getchar(); } while (isdigit(ch)) { x = (x << 3) + (x << 1) + ch - 0 ; ch = getchar(); } return x * f; } int n,...
#include <bits/stdc++.h> using namespace std; template <class T> ostream& operator<<(ostream& os, vector<T> V) { for (auto v : V) os << v << ; return cout << ; } template <class T> ostream& operator<<(ostream& os, set<T> S) { for (auto s : S) os << s << ; return cout << ; } tem...
#include <bits/stdc++.h> long long n, m, k, a[11111], kq; long long min(long long a, long long b) { if (a < b) return a; return b; } int main() { scanf( %lld %lld %lld , &n, &m, &k); for (int i = 1; i <= n; i++) scanf( %lld , &a[i]); if (n % 2 == 0) printf( 0 ); else { kq = a...
#include <bits/stdc++.h> using namespace std; const int N = 1000000 + 7; const int M = 32; const long long base = 1e18; const int mod = 999983; const int inf = 1e9 + 7; const double pi = acos(-1); const int maxn = N * 2; const double PI = acos(-1); const double ep = 1e-9; int n, m, s, e; int a[N...
#include <bits/stdc++.h> using namespace std; int main() { int tt; cin >> tt; unordered_map<string, string> mp; unordered_set<string> s; for (int i = 0; i < tt; i++) { string s1; string s2; cin >> s1 >> s2; if (s.find(s1) == s.end()) { mp.insert({s1, s2}); ...
#include <bits/stdc++.h> using namespace std; int x[3], y[3]; bool is_between(int a, int b, int c) { return min(a, b) <= c && c <= max(a, b); } bool check(int i, int j, int k) { return (x[k] == x[i] || x[k] == x[j]) && is_between(y[i], y[j], y[k]) || (y[k] == y[i] || y[k] == y[j]) && is_bet...
#include <bits/stdc++.h> using namespace std; long long n, k; int main() { cin >> n >> k; cout << k * (6 * n - 1) << endl; for (int i = 1; i <= n; i++) { int x = (i - 1) * 6 + 1; cout << k * x << << k * (x + 1) << << k * (x + 2) << << k * (x + 4) << endl; } } ...
#include <bits/stdc++.h> using namespace std; inline long long getint() { long long ssum = 0, ff = 1; char ch; for (ch = getchar(); !isdigit(ch) && ch != - ; ch = getchar()) ; if (ch == - ) ff = -1, ch = getchar(); for (; isdigit(ch); ch = getchar()) ssum = ssum * 10 + ch - 0 ; retu...
#include <bits/stdc++.h> using namespace std; int main() { long long n, t; cin >> n; t = 2 * n; long long a[t], I; for (I = 0; I < t; I++) cin >> a[I]; sort(a, a + t); long long ans = (a[0] - a[n - 1]) * (a[n] - a[2 * n - 1]); for (I = 1; I < n; I++) ans = min(ans, (a[I] - a[I ...
#include <bits/stdc++.h> inline int read() { int n = 0, ch = getchar(); for (; !isdigit(ch); ch = getchar()) ; for (; isdigit(ch); ch = getchar()) n = (n << 3) + (n << 1) + (ch ^ 48); return n; } int main() { int T = read(); while (T--) { int ans[3] = {0, 0, 0}; int n = r...
#include <bits/stdc++.h> using namespace std; template <class t> inline void read(t& res) { char ch; while (ch = getchar(), !isdigit(ch)) ; res = ch ^ 48; while (ch = getchar(), isdigit(ch)) res = res * 10 + (ch ^ 48); } template <class t> inline void print(t x) { if (x > 9) print(...
#include <bits/stdc++.h> #include <algorithm> using namespace std; #define int long long #define ll long long #define rep(i,a,b) for (int i = a; i < b; ++i) #define mod 1000000007 #define F first #define S second #define printer(v) for(auto f: v) cout<<f<< #define pb push_back #define mp ma...
#include <bits/stdc++.h> #include <vector> #include <set> #include <string> #include <map> #include <cmath> #include <algorithm> typedef long long int ll; #define f first #define s second #define vi vector<int> #define ld long double #define pb push_back #define mp make_pair #define pii pair...
#include <bits/stdc++.h> using namespace std; int main() { long long int l, r; cin >> l >> r; if (r - l < 2) { printf( -1 ); return 0; } if (l & 1) l++; if (l + 2 > r) { printf( -1 ); return 0; } cout << l << << l + 1 << << l + 2 << endl; return 0;...
#include <bits/stdc++.h> using namespace std; const int MAX = 18; const int MOD = 1000000007; char c[MAX]; int r[MAX], b[MAX]; int dp[1 << 16][125]; int red[1 << 16], blue[1 << 16]; void precalc(int n) { for (int i = 0; i < (1 << n); i++) { for (int j = 0; j < n; j++) { if (!(i & (1 <<...
#include <bits/stdc++.h> using namespace std; template <class T> T Bitcnt(T a) { int sum = 0; while (a) { if (a & 1) sum++; a /= 2; } return sum; } template <class T> T Max3(T a, T b, T c) { return max(a, max(b, c)); } template <class T> T Lcm(T a, T b) { T tmp = __...
#include <bits/stdc++.h> using namespace std; int freq[300]; string s; const int maxN = 2000; int primes[maxN]; int equs[maxN]; char result[maxN]; set<pair<int, char> > lets; int n; void sieve() { for (int i = 2; i < maxN; i++) { primes[i] = 1; } for (long long i = 2; i * i < maxN;...
#include <bits/stdc++.h> using namespace std; template <typename Tp> inline void rd(Tp &x) { x = 0; int fh = 1; char ch = 1; while (ch != - && (ch < 0 || ch > 9 )) ch = getchar(); if (ch == - ) fh = -1, ch = getchar(); while (ch >= 0 && ch <= 9 ) x = x * 10 + ch - 0 , ch = getcha...
#include <bits/stdc++.h> using namespace std; int main() { int n, a, b, ans[100], i, sum, z = 1; scanf( %d%d%d , &n, &a, &b); sum = ans[0] = 1; for (i = 1; i <= b; i++) { ans[i] = sum + 1; if (ans[i] > 50000) z = 0; sum += ans[i]; } if (z) { if (b != 0) { for ...
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 20; inline int read() { int ans = 0; char last = , ch = getchar(); while (ch< 0 | ch> 9 ) last = ch, ch = getchar(); while (ch >= 0 && ch <= 9 ) ans = ans * 10 + ch - 0 , ch = getchar(); if (last == - ) ans = -ans; ...
#include <bits/stdc++.h> using namespace std; const int MAXN = 201001; const int MAXK = 51; const double inf = 1e100; const double eps = 1e-10; int K, N; int tab[MAXN]; long long sum[MAXN]; double res[MAXN]; double odw[MAXN]; double dp[MAXK][MAXN]; struct Pt { double x, y; }; int ccw(con...
#include <bits/stdc++.h> using namespace std; const int N = 105, INF = 1 << 30, MOD = 1e9 + 7; int n, k; vector<int> adj[N]; long long cnt[N][N]; long long ans = 0, F[N]; long long sumOfProducts(vector<int>& arr, int n, int k) { long long dp[n + 1][n + 1]; memset(dp, 0, sizeof(dp)); long long ...
#include <bits/stdc++.h> using namespace std; const int MAXn = 1e5 + 10, MAXx = 4 * MAXn; struct salar { int l, r, max1, leftchild, rightchild, id; long long sum; salar() { sum = id = l = r = max1 = leftchild = rightchild = 0; } void idit(int v) { id = v; leftchild = 2 * v; right...
#include <bits/stdc++.h> using namespace std; int n, a[100005]; long long b[100005], dpMax[100005], dpMin[100005], ans = (1ll << 63); void setup() { cin >> n; for (int i = 1; i <= n; i++) cin >> a[i]; for (int i = 1; i <= n - 1; i++) b[i] = abs(a[i] - a[i + 1]); n--; } void xuly() { for ...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); int n; cin >> n; int a[n]; for (int i = 0; i < n; i++) { cin >> a[i]; } for (int i = 0; i < n; i++) { for (int t = 0; t < n - 1; t++) { if (a[t] > a[t + 1]) { int j = t ...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); long long a, b, c, i, j, k, l, m, t, x, y, n, z; string s; map<long long, long long> mp; map<long long, long long>::iterator it; cin >> a >> s; n = s.size(); long long a1[n + 1]; a1[0] = 0; ...
#include <bits/stdc++.h> using namespace std; const long double pi = 3.1415926535897932384626433832795l; template <typename T> inline auto sqr(T x) -> decltype(x * x) { return x * x; } template <typename T1, typename T2> inline bool umx(T1& a, T2 b) { if (a < b) { a = b; return 1; ...
#include <bits/stdc++.h> using namespace std; int main() { long long n; cin >> n; long long prod = 1; int arr[10]; for (int i = 0; i < 10; i++) arr[i] = 1; int p = 0; while (prod < n) { p %= 10; prod /= arr[p]; ++arr[p]; prod *= arr[p]; p++; } string...
#include <bits/stdc++.h> using namespace std; long long n, len, lcm, g, mod; long long a[266666], b[266666], c[266666], d[266666], e[266666], f[266666]; long long pw[266666], tmp[266666], w[2][266666], rev[266666]; long long mul(long long a, long long b) { return (a * b - (long long)(((long double)a * b +...
#include <bits/stdc++.h> using namespace std; const int maxn = 100 + 10; const int maxe = maxn * 2; int fir[maxn]; struct Edge { int v, c, nxt; Edge(int v = 0, int c = 0, int nxt = 0) : v(v), c(c), nxt(nxt) {} } edge[maxe]; int cnt; bool cir[maxn]; void init() { memset(fir, -1, sizeof(fir)...
#include <bits/stdc++.h> using namespace std; const long long MOD = 1e9 + 7; const long long INF = 1e17; struct item { long long t, d, p; }; long long n, dp[105][2100][2], ans; item arr[200], arrc[200]; long long solve(long long pos, long long tim) { if (pos > n) return 0; if (dp[pos][tim][0...
#include <bits/stdc++.h> using namespace std; int n, m; vector<int> ve; const int MAX = 51; long long C[MAX][MAX]; void build() { for (int i = 0; i < MAX; ++i) for (int j = 0; j < MAX; ++j) C[i][j] = (j == 0) ? 1 : ((i == 0) ? 0 : C[i - 1][j - 1] + C[i - 1][j]); } double memo[MAX][MAX]...
#include <bits/stdc++.h> using namespace std; int s[100005]; int bas[100005]; const int INF = 0x7fffffff; bool cmp(int a, int b) { return a > b; } int main() { int n, m; while (scanf( %d , &m) != EOF) { memset(s, 0, sizeof(s)); memset(bas, 0, sizeof(bas)); int i, j; int minba...
#include <bits/stdc++.h> using namespace std; long long n, arr[55] = {}, sm = 0, dp[55][2] = {}; long long rec(int ind, bool dt) { if (ind == n - 1) { if (dt) return 0; else return arr[ind]; } if (dp[ind][dt] != -1) return dp[ind][dt]; if (dt) return dp[ind][dt] =...
#include <bits/stdc++.h> using namespace std; int arr[251][251][51]; bool check(int n, int ans, int t) { if (t == 0) { if (ans == n) return 1; return 0; } bool ret = 0; if (arr[n][ans + 3][t - 1] == -1) arr[n][ans + 3][t - 1] = check(n, ans + 3, t - 1); ret |= arr[n][ans + 3]...
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; const int maxn = 1000010; struct Point { long long x, y; Point() {} Point(long long x, long long y) : x(x), y(y) {} bool operator<(const Point &rhs) const { if (x == rhs.x) return y < rhs.y; return x < rhs.x; ...
#include <bits/stdc++.h> using namespace std; int main() { string a, b; cin >> a >> b; long long int mx = 0; for (long long int i = 0; i < a.size(); i++) { long long int g = (a[i] - 0 ); mx = max(mx, g); } for (long long int i = 0; i < b.size(); i++) { long long int g = (b...
#include <bits/stdc++.h> using namespace std; const long long int N = 1e6; const long long int inf = 1e14; const long long int mod = 1e9 + 7; const double PI = acos(-1); long long int powm(long long int a, long long int b) { a = a % mod; long long int res = 1; while (b) { if (b & 1) res = ...
#include <bits/stdc++.h> #pragma GCC optimize(2) using namespace std; const long long mod = 1e9 + 7; long long a[200010]; int main() { long long n, k; cin >> n >> k; long long i; for (i = 1; i <= n; i++) scanf( %d , &a[i]); long long sum = 0; for (i = 1; i <= n; i++) { long long ...
#include <bits/stdc++.h> using namespace std; int main() { int n; while (cin >> n) { int m = n % 4; cout << (m == 0 || m == 3 ? 0 : 1) << endl << n / 2 << ; for (int i = n; i >= 4; i -= 4) cout << i - 1 << << i - 2 << ; if (m == 2) cout << 1 << endl; else i...
#include <bits/stdc++.h> using namespace std; const int maxn = 1e3 + 5; int n, m, k; struct node { int x, y, step; }; char s[maxn][maxn]; bool vis[maxn][maxn][4]; int go[4][2] = {0, 1, 1, 0, 0, -1, -1, 0}; int bfs(int x, int y, int tx, int ty) { for (int i = 0; i < 4; ++i) vis[x][y][i] = 1; ...
#include <bits/stdc++.h> using namespace std; long long A[100005]; long long D[100005]; long long qzh[100005]; long long hzh[100005]; long long ans[100005]; long long dp[100005]; int main() { int n, k; cin >> n >> k; for (int i = 1; i <= n; i++) scanf( %lld , &A[i]); for (int i = 1; i <=...
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 50; int mod = 1e9 + 7; long long add(long long a, long long b) { return (a % mod + b % mod + mod) % mod; } long long mul(long long a, long long b) { return (a % mod * (b % mod)) % mod; } int dp[N][3]; int solve(int rem, int val) { ...
#include <bits/stdc++.h> using namespace std; int main() { long long n, a[100001]; cin >> n; for (int i = 0; i < n; i++) cin >> a[i]; cout << 1 << << n << endl; cout << 0 << ; for (int i = 1; i < n; i++) cout << (n * (n - 1 - a[i])) << ; cout << endl; cout << 1 << << 1 ...
#include<cstdio> #include<iomanip> #include<iostream> #include<cstring> #include<string> #include<cmath> #include<map> #include<algorithm> #include<vector> #include<set> #include<queue> #include<unordered_map> #define Quick ios::sync_with_stdio(false); cin.tie(0); cout.tie(0) #define ll long l...
#include<bits/stdc++.h> using namespace std; void solve() { long long int n,s=0,sum=0,k; cin>>n; long long int arr[n+1]; for(int i=1;i<=n;i++) { cin>>arr[i]; if(i%2==1) sum=sum+arr[i]; else s=s+arr[i];} if(sum>=s) { for(int i=1;i<=n;i++) { if(i%2==1) ...
#include <bits/stdc++.h> using namespace std; const double eps = 1e-9; struct point { double x, y; point() {} point(double _x, double _y) { x = _x; y = _y; } point operator+(const point &t) { return point(x + t.x, y + t.y); } point operator-(const point &t) { return point(x - t...
#include <bits/stdc++.h> using namespace std; long long min(long long a, long long b) { return (a < b) ? a : b; } int main() { long long n, m, b_max_1 = 0, b_max_2 = 0, g_min = 1e9; long long sum_b = 0, sum_g = 0; cin >> n >> m; long long b[n], g[m]; for (int i = 0; i < n; ++i) { cin >> ...
#include <bits/stdc++.h> using namespace std; int a[200010]; struct seg { int val, idx; } tree1[600010], tree2[600010]; void build(int node, int s, int e) { if (s > e) return; if (s == e) { tree1[node].val = a[s]; tree1[node].idx = s; tree2[node].val = a[s]; tree2[node].idx...
#include <bits/stdc++.h> using namespace std; const long long INF = 1e18 + 10; const int inf = 1e9 + 10; const int N = 1e6 + 10; vector<int> t[N * 4]; void build(int v, int tl, int tr, vector<int> &a) { if (tl == tr) { t[v].push_back(a[tl]); } else { int tm = (tl + tr) / 2; build(v...
#include <bits/stdc++.h> using namespace std; bool As; char c; int n, m, k; inline void read(int& a) { a = 0; do c = getchar(); while (c < 0 || c > 9 ); while (c <= 9 && c >= 0 ) a = (a << 3) + (a << 1) + c - 0 , c = getchar(); } int Min[1211]; double A[11][11]; bool Has[11][11]...
#include <bits/stdc++.h> using namespace std; int n, ans; float x, dis, t; struct ponto { float ini, fim; bool operator<(const ponto &lhs) const { return lhs.ini > ini; } } p[1010]; int main() { scanf( %d%f , &n, &t); ans = 2; for (int i = 0; i < n; i++) { scanf( %f%f , &x, &dis); ...
#include <bits/stdc++.h> using namespace std; const int MOD = 1000000007; long long int inverse(long long int i) { if (i == 1) return 1; return (MOD - ((MOD / i) * inverse(MOD % i)) % MOD + MOD) % MOD; } int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long n; ci...
#include <bits/stdc++.h> using namespace std; using lint = long long; bool has(int s, int x) { int i = s / 50 % 475; for (int ii = (0); ii < int(25); ++ii) { i = (i * 96 + 42) % 475; if (i + 26 == x) { return true; } } return false; } void solve(istream& cin, ostream&...
#include <bits/stdc++.h> using namespace std; struct vec { int to; int fro; }; int fa[200010], son[200010][26], mx[200010]; int rt, lst, tot; int n, m; char s[200010]; vec mp[200010]; int tai[200010], cnt; int P[200010]; int ans[200010]; vector<int> qs[200010]; int av[200010]; int le...
#include <bits/stdc++.h> using namespace std; bool iguales(vector<string>& x, vector<string>& y) { for (int i = (int)0; i < (int)x.size(); i++) { if (x[i] == T || y[i] == T ) continue; if (!(x[i] == y[i])) return false; } return true; } int main() { map<string, vector<vector<strin...
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 10; int n, k; int a[200]; int main() { ios::sync_with_stdio(false); cin >> n >> k; int e = 0, s = 0; for (int i = 1; i <= n; i++) { cin >> a[i]; if (a[i] == 1) e++; else s++; } int ee...
#include <bits/stdc++.h> using namespace std; int main() { int n, k, c; cin >> n >> k >> c; int p = ((n * k * c) / 100); int k1 = p / k; int k2 = p % k; for (int i = 0; i < n; i++) { if (i != 0) cout << ; if (i < k1) cout << k; else if (i == k1) cout << k...
#include <bits/stdc++.h> using namespace std; int n, t, i, j, a[100005], b[100005]; int main() { j = 2; cin >> n; for (i = 1; i <= n; i++) cin >> a[i]; for (i = 1; i <= n; i++) b[i] = b[i - 1] + a[i]; for (i = n; i >= 1; i--) if (b[i + 1] + a[i] < b[i]) { j = i; b[i] = b[...
#include <bits/stdc++.h> const int mo = 1000000007, x[9][9] = {{0, 0, 0, 0, 1, 1, 0, 0, 1}, {0, 0, 0, 0, 0, 0, 1, 1, 1}, {0, 0, 0, 0, 1, 1, 0, 0, 1}, {0, 0, 0, 0, 0, 0, 1, 1, 1}, {1, 0, 0, 0, 0, 0, 0, 0, 1}, {0, 0, 1, 1, 0, 0, 0, 0, 1}, ...
#include <bits/stdc++.h> using namespace std; int a[100005], b[100005]; bool compare(int c, int d) { return a[c - 1] < a[d - 1]; } int main() { int n; cin >> n; for (int i = 0; i < n; i++) { cin >> a[i]; b[i] = i + 1; } sort(b, b + n, compare); cout << (n + 1) / 2 << endl; ...
#include <bits/stdc++.h> using namespace std; const long long maxN = 2e5 + 10; const long long maxB = 500; const long long INF = 4557430888798830399; const int INF_I = 2139062143; const long long maxA = 1e6 + 10; const long long MOD = 1e9 + 7; const long long mINF = -4557430888798830400; const int mIN...
#include <bits/stdc++.h> using namespace std; const long long int INF = 1e9 + 7; long long int gcd(long long int a, long long int b) { if (a == 0) return b; return gcd(b % a, a); } long long int lcm(long long int a, long long int b) { return (a / gcd(a, b)) * b; } long long int sq(long long in...
#include <bits/stdc++.h> using namespace std; int x1, x2, a, b; int main() { while (cin >> x1 >> x2 >> a >> b) { bool ch = false; if (x1 > x2) { swap(x1, x2); swap(a, b); a = -a; b = -b; ch = true; } int dif = abs(x1 - x2); if (a <= 0) { ...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); int n; cin >> n; map<int, int> pmax, maxp; vector<int> g[n + 2]; for (int i = 0; i < n; i++) { int a, b; cin >> a >> b; g[a].push_back(b); if (pmax.find(a) == pmax.end(...
#include <bits/stdc++.h> int gcd(int x, int y) { int r1 = x, q, r2 = y, r; while (r2 > 0) { q = r1 / r2; r = r1 - q * r2; r1 = r2; r2 = r; } return r1; } using namespace std; int main(int argc, char const *argv[]) { int n, m, x, cnt; char c; cin >> n >> m; ...
#include <bits/stdc++.h> using namespace std; const int maxn = 1e6 + 5; int ans, cnt, tmp; int main() { int n; cin >> n; int a[] = {0, 0, 0, 0, 0}; for (int i = 0; i < n; i++) { int x; cin >> x; a[x]++; cnt += x; } if (cnt == 5 || cnt < 3) return cout << -1, 0; ...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; const int N = 26; int mas[26]; for (int i = 0; i < N; ++i) mas[i] = 0; int rez = 0; for (int i = 0; i < n * 2 - 2; ++i) { char a; cin >> a; if (isupper(a)) { if (mas[tolower(a) - a ] > ...
#include <bits/stdc++.h> using namespace std; int a[505]; pair<int, int> query(set<int> s) { cout << ? ; for (auto e : s) { cout << e << ; } cout << endl; pair<int, int> res; cin >> res.first >> res.second; a[res.first] = res.second; return res; } int main() { io...
#include <bits/stdc++.h> using namespace std; const int MOD = 1e9 + 7; int main() { string s; cin >> s; string a = ; for (int i = 0; i < s.size(); i++) { if (s[i] == a || s[i] == b ) a += s[i]; } int ans = 1, cnt = 0; for (int i = 0; i < a.size(); i++) { if (a[i] == b...
#include <bits/stdc++.h> using namespace std; unsigned long long ans = 0; int r = -1; int n, g[40][21], p[40][21]; char ch; void update(unsigned long long &a, int &b, int &c, unsigned long long d, int e) { if (b == 0 || a < d) { a = d; c = e; b = 1; } } unsigned l...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; if (n < 3) cout << -1; else for (int i = n; i > 0; --i) { cout << i << ; } return 0; }
#include <bits/stdc++.h> using namespace std; struct pony { long long s, m, r, t; } ponys[100005]; bool cmp(pony &x, pony &y) { return x.t < y.t; } struct node { long long l, r, latest; long long *sm, *sr, *t; } nodes[100005 << 4]; void build(long long ord, long long l, long long r) { node...
#include <bits/stdc++.h> using namespace std; typedef int* Pint; typedef long long* PLL; const int MAXN = 1E4; int a[110], f[110][3]{}; int n; int main() { scanf( %d , &n); for (int i = 1; i <= n; i++) scanf( %d , a + i); for (int i = 1; i <= n; i++) { f[i][0] = min(min(f[i - 1][0], f[i ...
#include <bits/stdc++.h> #pragma comment(linker, /STACK:102400000,102400000 ) using std::bitset; using namespace std; struct point { long long x, y; bool operator<(const point &I) const { return x < I.x || (x == I.x && y < I.y); } } a[101000]; long long n; long long hmi[101000], tmi[101...
#include <bits/stdc++.h> using namespace std; const double pi = 3.1415926535897932384626433832795; const int inf = 1e9; const long long inf2 = 1e18; const int mod = 1e9 + 7; void boost() { ios_base::sync_with_stdio(false); cin.tie(NULL); } inline long long exp(long long x, long long n, long long...
#include <bits/stdc++.h> using namespace std; int main() { int a1[3], a2[3], i; cin >> a1[0] >> a1[1] >> a1[2]; cin >> a2[0] >> a2[1] >> a2[2]; for (i = 0; i < 3; i++) { if (a1[i] == a2[i]) { cout << YES ; return 0; } } cout << NO ; return 0; }
#include <bits/stdc++.h> using namespace std; string s; int n, k, cal; string solve() { for (int i = 0; i < s.size(); i++) { int m4x = min(s[i] + k, (int) z ); int m1n = max(s[i] - k, (int) a ); if (s[i] - m1n >= m4x - s[i]) { k -= s[i] - m1n; s[i] = m1n; } else { ...
#include <bits/stdc++.h> using namespace std; template <class Flow = long long, class Cost = long long> struct MinCostFlow { const Flow INF_FLOW = 1000111000; const Cost INF_COST = 1000111000111000LL; long long n, t, S, T; Flow totalFlow; Cost totalCost; vector<long long> last, visited; ...
#include <bits/stdc++.h> using namespace std; long long i, j, x, y, curr, T, t, K, N, coun[51], fact[21], rev[51]; vector<int> ans, v; set<int> cand; set<int>::iterator it; void precomp() { fact[0] = 1; for (i = 1; i < 21; i++) { fact[i] = fact[i - 1] * i; } coun[0] = coun[1] = 1; ...
#include <bits/stdc++.h> using namespace std; int main() { deque<int> dq; int n; cin >> n; int f = 0, a = 0, b = 0; for (int i = 0; i < n; ++i) { int x; cin >> x; dq.push_back(x); } while (!dq.empty()) { int ans = max(dq.front(), dq.back()); if (f == 0) { ...
#include <bits/stdc++.h> using namespace std; const int MAXN = 100001; int q, n; int d[MAXN], p[MAXN]; int main() { cin >> q; int small = 1 << 30; for (int i = 0; i < q; ++i) { cin >> d[i]; small = ((small) > (d[i]) ? (d[i]) : (small)); } cin >> n; for (int i = 0; i < n; ++...
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; long long ans = 0; for (int i = (0); i < (n); ++i) { long long t, T, x, cost; cin >> t >> T >> x >> cost; if (t >= T) { ans += cost + m * x; continue; } long long aux1 = ...
#include <bits/stdc++.h> #pragma comment(linker, /stack:200000000 ) #pragma GCC optimize( Ofast ) #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native ) using namespace std; void file() {} void fast() { std::ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL); }...
#include <bits/stdc++.h> using namespace std; int n, x[1500][1500], y[1500][1500], vis[1510][1500]; char ans[1500][1500]; struct node { int x, y; }; int dx[] = {0, 0, 1, -1}; int dy[] = {1, -1, 0, 0}; vector<node> a; int main() { cin >> n; for (int i = 1; i <= n; i++) { for (int j = ...
#include <bits/stdc++.h> using namespace std; map<int, int> mp; int a[300000]; int n, k; int b[300000]; int cnt = 0; int cmp(int a, int b) { return mp[a] > mp[b]; } bool check(int mid) { int sum = 0; for (int i = 1; i <= cnt; i++) { sum += mp[b[i]] / mid; } return sum >= k; } i...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int t; cin >> t; for (int i = 0; i < t; i++) { int x, y, a, b; cin >> x >> y >> a >> b; if ((y - x) % (a + b) == 0) { cout << (y - x) / (a + b) << n ; } els...
#include <bits/stdc++.h> long long a[100000], b[100000]; using namespace std; bool isnp(long long n, long long k, long long t) { long long magic = 0; for (long long i = 0; i < t; i++) { if (a[i] * n > b[i]) magic += a[i] * n - b[i]; if (magic > k) return false; } return true; } int...
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5, K = 505, INF = K * (1e4 + 5); int n, m, k; int c[N], a[N], visit[N]; int w[K][K]; vector<pair<int, int>> edges[N]; vector<int> colors; void dfs(int s) { visit[s] = 1; colors.push_back(a[s]); for (auto x : edges[s]) { ...
#include <bits/stdc++.h> using namespace std; int n, m; char a[222][222]; struct Dinic { struct edge { int to, flow, cap; }; const static int N = 202 * 202; vector<edge> e; vector<int> g[N + 7]; int dp[N + 7]; int ptr[N + 7]; void clear() { for (int i = 0; i < N + 7; ...
#include <bits/stdc++.h> using namespace std; int main() { int n, m; std::ios::sync_with_stdio(false); cin >> n >> m; int x, y; for (int i = 0; i < m; i++) cin >> x >> y; for (int i = 0; i < n; i++) if (i % 2 == 0) cout << 0; else cout << 1; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; int a[n]; for (int i = 0; i < n; i++) { cin >> a[i]; } int ans = 0; for (int i = 0; i < k; i++) { int m = 0; for (int j = i; j < n; j += k) { if (a[j] == 1) { m++; ...
#include <bits/stdc++.h> using namespace std; struct abc { long long int y, x; }; bool compare(abc a1, abc a2) { if (a1.x == a2.x) return a1.y < a2.y; return a1.x < a2.x; } long long int countDivisors(long long int n) { long long int cnt = 0; for (long long int i = 1; i <= sqrt(n); i++) ...
#include <bits/stdc++.h> using namespace std; vector<int> v; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); ; long long n; cin >> n; int flag = 0; int m; cin >> m; long long a[m]; for (int i = 0; i < m; i++) { cin >> a[i]; } sort(a, a + m);...
#include <bits/stdc++.h> using namespace std; const long long int INF = 1e18; const int N = 3e5 + 7; const int MOD = 1e9 + 7; constexpr int mul(int a, int b) { return 1LL * a * b % MOD; } template <typename... T> constexpr int mul(int a, int b, T... t) { return mul(mul(a, b), t...); } inline int r...
#include <bits/stdc++.h> using namespace std; int main() { int n, *a, s, t, d1 = 0, d2 = 0; cin >> n; a = new int[n]; for (int i = 0; i < n; i++) cin >> a[i]; cin >> s >> t; if (s < t) { int tmp = t; t = s; s = tmp; } for (int i = t - 1; i < s - 1; i++) d1 += a[i]; ...
#include <bits/stdc++.h> using namespace std; vector<int> prefix_function(const string &s) { int n = (int)s.size(); vector<int> p(n); p[0] = 0; for (int i = 1; i < n; i++) { p[i] = p[i - 1]; while (p[i] > 0 && s[p[i]] != s[i]) p[i] = p[p[i] - 1]; if (s[p[i]] == s[i]) p[i]++; } ...
#include <bits/stdc++.h> using namespace std; const int A = 1000001; int x, p, k; bool b[A]; vector<int> v[A]; int calc(int x) { int ret = 0; int n = v[p].size(); for (int i = 1; i < (1 << n); i++) { int pro = 1; for (int j = 0; j < n; j++) { if ((1 << j) & i) pro *= v[p][j];...