func_code_string
stringlengths
59
71.4k
#include <bits/stdc++.h> using namespace std; int main() { int m, e[10][10] = {}, a, b; scanf( %d , &m); while (m--) { scanf( %d%d , &a, &b); e[a][b] = e[b][a] = 1; } for (int i = 1; i <= 5; i++) for (int j = i + 1; j <= 5; j++) for (int k = j + 1; k <= 5; k++) ...
#include <bits/stdc++.h> using namespace std; long long n; struct node { long long x, y; } po[100000]; inline long long dis(node a, node b) { return (a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y); } bool cmp(const node &a, const node &b) { return (a.y == b.y ? a.x < b.x : a.y < b.y); ...
#include <bits/stdc++.h> using namespace std; template <class T> inline void read(T &x) { x = 0; char c = getchar(); int f = 1; while (!isdigit(c)) { if (c == - ) f = -1; c = getchar(); } while (isdigit(c)) { x = x * 10 + c - 0 ; c = getchar(); } x *= f; ...
#include <bits/stdc++.h> using namespace std; char c[200010]; int main() { int n; while (scanf( %d , &n) != EOF) { memset(c, 0, sizeof c); scanf( %s , c); int ans = 0; for (int i = 0; i < n; i++) { if (c[i] == < ) ans++; else break; } ...
#include <bits/stdc++.h> using namespace std; const int N = 505; int a[N]; int z[2][N][N]; int main() { int n, bl, bugs, md; scanf( %d %d %d %d , &n, &bl, &bugs, &md); for (int i = 0; i < int(n); i++) scanf( %d , &a[i]); z[0][0][0] = 1; for (int it = 1; it <= n; it++) { int i = it & ...
#include <bits/stdc++.h> #pragma GCC optimize( Ofast ) #pragma GCC optimize( inline ) #pragma GCC optimize( omit-frame-pointer ) #pragma GCC optimize( unroll-loops ) using namespace std; template <class T> void debug(vector<T> vec) { for (int i = 0; i < vec.size(); i++) cerr << vec[i] << ; cerr...
#include <bits/stdc++.h> using namespace std; const double eps = 1E-9; int cnt; double a, b, m, vx, vy, vz, t, f; double ansx, ansz; int main() { scanf( %lf%lf%lf , &a, &b, &m); scanf( %lf%lf%lf , &vx, &vy, &vz); t = -m / vy; ansx = a / 2 + t * vx; ansz = t * vz; while (ansx < 0) ans...
#include <bits/stdc++.h> using namespace std; template <class _T> inline _T sqr(const _T& first) { return first * first; } template <class _T> inline string tostr(const _T& a) { ostringstream os( ); os << a; return os.str(); } const long double PI = 3.1415926535897932384626433832795L; ...
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const long long LINF = 0x3f3f3f3f3f3f3f3f; const double eps = 1e-12; const double PI = acos(-1.0); const int mod = 998244353; int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); } long long gcd(long long a, long long b) { r...
#include <bits/stdc++.h> using namespace std; bool isprime(long long int n) { if (n <= 1) return false; if (n <= 3) return true; if (n % 2 == 0 || n % 3 == 0) return false; for (int i = 5; i * i <= n; i = i + 6) if (n % i == 0 || n % (i + 2) == 0) return false; return true; } vector<lo...
#include <bits/stdc++.h> using namespace std; const long long N = 5255; long long n, m; long long a[N], b[N]; long long ans[N], rec[N]; inline long long gt(long long u) { long long flg = u < 0 ? -1 : 1; u = u * flg; for (long long i = 2; i * i <= u; ++i) { while (u % (i * i) == 0) u = u / ...
#include <bits/stdc++.h> using namespace std; const long long N = 200000 + 10; const long long M = 1000000 + 10; const long long INF = (long long)1e9 + 10; long long n, m; long long tl[N], tr[N]; map<long long, long long> toX; pair<long long, long long> a[N]; pair<pair<long long, long long>, pair<long...
#include <bits/stdc++.h> using namespace std; int main() { int n, d; cin >> n >> d; int m; cin >> m; for (int i = 0; i < m; i++) { int x, y; cin >> x >> y; if (x + y - d >= 0 && x - y - d <= 0 && x - y + d >= 0 && x + y - 2 * n + d <= 0) { cout << YES n ; ...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int T = 1; while (T--) { long long a, b, s; cin >> a >> b >> s; s = s - abs(a) - abs(b); if (s % 2 == 0 && s >= 0) cout << Yes ; else ...
#include <bits/stdc++.h> using namespace std; long long n, k; long long quickpow(long long x, long long y) { long long res = 1; for (; y; y >>= 1, x *= x, x %= 1000003) if (y & 1) res *= x, res %= 1000003; return res; } int main() { scanf( %I64d %I64d , &n, &k); if (n < 62 && k > (1L...
#include <bits/stdc++.h> using namespace std; long long n; int x[100005], y[100005], num_, num; int main() { cin >> n; for (int i = 0; i < n; i++) { cin >> x[i] >> y[i]; if (x[i] > 0) { num++; } else { num_++; } } if (num == 1 || num_ == 1 || num == 0 || n...
#include <bits/stdc++.h> using namespace std; long long power(long long b, long long e, long long m) { if (e == 0) return 1; if (e & 1) return b * power(b * b % m, e / 2, m) % m; return power(b * b % m, e / 2, m); } long long power(long long b, long long e) { if (e == 0) return 1; if (e & 1)...
#include <bits/stdc++.h> using namespace std; long long f(long long n) { long long t = n; for (long long i = 2; i * i <= n; i++) if (n % i == 0) { t = t / i * (i - 1); while (n % i == 0) n /= i; } if (n > 1) t = t / n * (n - 1); return t; } int main() { long long ...
#include <bits/stdc++.h> using namespace std; string parse(string str) { string returnme; for (int i = 0; i < str.length(); i++) { if (str[i] == _ || str[i] == ; || str[i] == - ) { } else { returnme.push_back(tolower(str[i])); } } return returnme; } int main() { ...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int foot = 0; int inch = 0; int q, o; if (n < 35) { if (n == 2) { inch++; } else for (int e = 1; e < n; e = e + 3) { inch++; } } else if (n == 35 || n == 36) { ...
#include <bits/stdc++.h> using namespace std; const int MOD = (int)1e9 + 7; const int FFTMOD = 1007681537; const int INF = (int)1e9; const long long LINF = (long long)1e18; const long double PI = acos((long double)-1); const long double EPS = 1e-9; inline long long gcd(long long a, long long b) { lo...
#include <bits/stdc++.h> using namespace std; const long long mx = 3e5 + 66; const long long mod = 1e9 + 7; const long long inf = 8e18 + 66; const int llg = 25; const long long mxk = 31700000; long long power(long long a, long long b, long long md) { if (b == 0) return 1; long long c = power(a, b ...
#include <bits/stdc++.h> using namespace std; const int sizes = 200001; int main() { long long int i, j, k, l, m, n, o, p, q, r, s, t, a[sizes], b[sizes], booked[1001]; cin >> n; o = 0; for (i = 0; i < n; i++) { cin >> a[i]; o = max(o, a[i]); } sort(a, a + n); memse...
#include <bits/stdc++.h> using namespace std; const int maxn = 1e3 + 10; long long inf = 1e18; set<pair<long long, pair<int, int> > > s; vector<pair<pair<int, int>, long long> > vec; long long dp[2][maxn][maxn], arr[maxn][maxn]; long long ps[maxn][maxn]; int n, m, a, b; bool mark[maxn][maxn]; void i...
#include <bits/stdc++.h> using namespace std; const int N = 200010, X = 2000010, P = 1000000007; int n, pc, ind; bool vis[X], chose[N]; int a[N], l[X], pr[N], fc[X]; int tag[X]; void apply(int x) { int lst = 0, cnt = 0; while (x != 1) { int pp = fc[x]; x /= pp; if (pp == lst) { ...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long int T = 1; while (T--) { long long int m, n, k, t, i; cin >> m >> n >> k >> t; vector<long long int> sol(m); for (i = 0; i < m; i++) cin >> sol[i]; ...
#include <bits/stdc++.h> using namespace std; int main() { int n, c, d, a, b, i; cin >> n >> a >> b; c = b, d = c; for (i = 2; i <= n; i++) { cin >> a >> b; c = max(c, d - a + b); d = d - a + b; } cout << c; return 0; }
#include <bits/stdc++.h> using namespace std; const int N = 1000, MD = 1000000007; char aa[N + 1], bb[N + 1], cc[N * 3]; int zz[N * 3]; void mult(int aa[][2], int bb[][2], int cc[][2]) { for (int i = 0; i < 2; i++) for (int j = 0; j < 2; j++) { long long c = 0; for (int k = 0; k < 2;...
#include <bits/stdc++.h> using namespace std; const int M = 1e5 + 5; const int inf = 1e9 + 5; const int mod = 1e9 + 7; vector<int> v[M]; int hx2[2 * M]; int hx[M]; int nxt[M]; int n, m; int KMP() { memset(nxt, 0, sizeof(nxt)); int la, lb; la = n; lb = m; int j, k; j = 0; ...
#include <bits/stdc++.h> using namespace std; int N, B, Q; int a[200005]; vector<int> adj[200005]; void init() { B = sqrt(N); for (int i = 1; i <= N; i++) { a[i] = i; adj[i / B].push_back(i); } } long long work(int l, int r) { if (l == r) return 0; int idx, idy, x, y, k; ...
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 5; long long a[N], pre[N]; int n; long long check(int p, int len) { return pre[p] - pre[p - len - 1] + pre[n] - pre[n - len]; } int main() { scanf( %d , &n); for (int i = 1; i <= n; i++) scanf( %lld , &a[i]); sort(a + 1, a +...
#include <bits/stdc++.h> using namespace std; int a[110], b[110], n; int main() { int t; cin >> t; while (t--) { cin >> n; for (register int i = 1; i <= n; i++) cin >> a[i]; for (register int i = 1; i <= n; i++) cin >> b[i]; sort(a + 1, a + n + 1); sort(b + 1, b + n + 1);...
#include <bits/stdc++.h> using namespace std; double EPS = 1e-9; int INF = 2000000000; long long INFF = 8000000000000000000LL; double PI = acos(-1); string IntToString(int a) { char x[100]; sprintf(x, %d , a); string s = x; return s; } int StringToInt(string a) { char x[100]; st...
#include <bits/stdc++.h> using namespace std; const int maxn = 1000 + 100; const int maxk = 45; const int mod = 1000000007; int dp[maxk][maxn]; int cnt[maxk][maxn]; void input_output() { int t; cin >> t; for (int i = 0; i < t; i++) { int n, k; cin >> n >> k; if (k < maxk) ...
#include <bits/stdc++.h> using namespace std; template <class T1, class T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p) { os << { << p.first << , << p.second << } ; return os; } const int N = 3e5 + 5; const int oo = 1e9 + 7; vector<pair<pair<int, int>, int> > X, Y; pair<int, int...
#include <bits/stdc++.h> using namespace std; const int MAXN = 2e6 + 10; int z[MAXN]; void Zvalue(const string &s) { z[0] = s.size(); int l = 0, r = 0, x; for (int i = 1; i < s.size(); i++) { if (r < i || z[i - l] >= r - i + 1) { r < i ? x = i : x = r + 1; while (x < s.size() &...
#include <bits/stdc++.h> using namespace std; int t, n; long long a[100005]; int get_bit(long long x) { int ans = 0; while (x) { ans++; x >>= 1; } return ans; } int main() { int i, j; scanf( %d , &t); while (t--) { scanf( %d , &n); for (i = 1; i <= n; i++)...
// Jai Shree Ram #include<bits/stdc++.h> typedef long long int ll; #define pb push_back #define max2(a,b) (a>b)?a:b #define mi2(a,b) (a<=b)?a:b #define fori(i,n) for(ll i=0;i<(ll)n;i++) #define ford(i,n) for(ll i=n;i>=0;i--) #define pll pair<ll,ll> #define mod 1000000007 #define ff first #defin...
#include <bits/stdc++.h> using namespace std; void solve() { int k, a, b; cin >> k >> a >> b; string s; cin >> s; int l = s.length(); double c = (double)l / k; int c1 = floor(c); int c2 = ceil(c); int flag1 = 0, flag2 = 0; if ((l - (c1 * (k - 1))) > b || (l - (c1 * (k - 1))) ...
#include <bits/stdc++.h> using namespace std; long long rt(long long a) { long long p = 0, q = a; while (p < q) { long long s = (p + q + 1) / 2; long long sv = s * (s + 1) / 2; if (sv < a) p = s; if (sv > a) q = s - 1; if (sv == a) return s; } if (p * (p + 1) / 2 == a) ...
#include <bits/stdc++.h> using namespace std; const long long INF = 1e15; long long arr[100003]; int main() { int n; scanf( %d , &n); for (int i = 0; i < n; i++) scanf( %lld , &arr[i]); if (n == 1 || n == 2) printf( 0 n ); else { long long res = INF; for (int i = -1; i <= 1...
#include <bits/stdc++.h> using namespace std; int main() { string x, y; cin >> x >> y; for (long long int i = 0; i < x.size(); i++) { if (x[i] == y[i]) cout << 0; else cout << 1; } }
#include <bits/stdc++.h> template <class T> T _diff(T a, T b) { return (a < b ? b - a : a - b); } template <class T> T _abs(T a) { return (a < 0 ? -a : a); } template <class T> T _max(T a, T b) { return (a > b ? a : b); } template <class T> T _min(T a, T b) { return (a < b ? a : b)...
#include <bits/stdc++.h> using namespace std; static inline void canhazfast() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); } template <typename T> T gcd(T a, T b) { return b == 0 ? a : gcd(b, a % b); } template <typename T> T extgcd(T a, T b, T &x, T &y) { ...
#include <bits/stdc++.h> using namespace std; const long long INFLL = 1e18; const int MAXN = 1e6 + 100; const long long INF = 1e9; const long long mod1 = 1e9 + 7; const long long mod2 = 2e9 + 11; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int t; cin >> t; while (t--) { ...
#include <bits/stdc++.h> using namespace std; const double long EPS = 1e-10; struct wor { double long x = 0, y = 0; }; double long dist(wor a, wor b) { double long answer = sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y)); return answer; } pair<vector<double long>, vector<lo...
#include <bits/stdc++.h> using namespace std; int main() { int n, k; scanf( %d %d , &n, &k); for (int i = 0; i < k; i++) { if (n % 10 == 0) { n /= 10; } else { n--; } } printf( %d n , n); }
#include <bits/stdc++.h> using namespace std; template <class U, class V> ostream& operator<<(ostream& os, const pair<U, V>& p) { os << ( << p.first << , << p.second << ) ; return os; } template <class U, class V> istream& operator>>(istream& in, pair<U, V>& p) { in >> p.first >> p.second;...
#include <bits/stdc++.h> using namespace std; long long k, l; int main() { cin >> k >> l; long long K = k; int res = 0; while (K < l) { K *= k; res++; } if (K == l) { cout << YES << endl; cout << res << endl; } else { cout << NO << endl; } retu...
#include <bits/stdc++.h> using namespace std; struct sgmnt { long long L, R; int mxL, mxR, w; sgmnt() {} sgmnt(long long L, int mxL, long long R, int mxR, int w) : L(L), mxL(mxL), R(R), mxR(mxR), w(w) {} }; const int MAXN = 3 * 1000 * 100 + 10; long long arr[MAXN]; sgmnt seg[MAXN * 4...
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 7; int l[N], r[N], n, len, posl, posr; char a[N], b[N]; int ans, ans1, ans2; vector<int> vec[30]; int main() { for (int i = 0; i < 30; ++i) vec[i].push_back(1); scanf( %s%s , a + 1, b + 1); n = strlen(a + 1); len = strlen(b ...
#include <bits/stdc++.h> using namespace std; int main() { int n, d, c = 0; cin >> d >> n; int a[n], i; for (i = 0; i < n; i++) cin >> a[i]; for (i = 0; i < n - 1; i++) { c += d - a[i]; } cout << c; }
#include <bits/stdc++.h> using namespace std; long long int ch(long long int x, long long int y) { if (abs(x - y) % 2 == 0) { return 0; } return 1; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); long long int q; cin >> q; while (q--) { l...
#include <bits/stdc++.h> using namespace std; const int maxn = 100005; struct node { double x, y, vx, vy; } a[maxn]; bool ck(double a, double b) { if (a - b > 1e-50 || (fabs(a - b) <= 1e-50)) return true; else return false; } int main() { int n; scanf( %d , &n); double ...
#include <bits/stdc++.h> using namespace std; const int N = 1005; int l[N][N], r[N][N], u[N][N], z[N][N]; int v[N][N]; void swap_left(int f, int g) { int fi = f / N; int fj = f % N; int gi = g / N; int gj = g % N; swap(l[fi][fj], l[gi][gj]); int ai = l[fi][fj] / N; int aj = l[fi][f...
#include <bits/stdc++.h> using namespace std; int head[100005], nxt[200005], v[200005], w[200005], tot = 0; int fa[100005], rk[100005]; int p[100005], k[100005], n, m; long long d[100005]; struct node { int a, b, c; long long len; } e[100005]; queue<int> q; inline int read() { int x = 0; ...
#include <bits/stdc++.h> using namespace std; using ll = long long; using ii = pair<int, int>; using vi = vector<int>; using vll = vector<long long>; using vii = vector<pair<int, int>>; const int N = 105; int matrix[N][N]; int main() { int n, m, k; scanf( %d%d%d , &n, &m, &k); for (int i =...
#include <bits/stdc++.h> using namespace std; int main() { long long q; cin >> q; while (q--) { long long c, m, x; cin >> c >> m >> x; long long a = min(c, m); long long left = m - a + x + c - a; if (left >= a) { cout << a << endl; } else { long long t...
#include <bits/stdc++.h> using namespace std; pair<double, double> midpoint(double x1, double y1, double x2, double y2) { return {(x1 + x2) / 2, (y1 + y2) / 2}; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; cin >> n; map<pair<double, double>, int> mp; ...
#include <bits/stdc++.h> using namespace std; int getFldsFromLine(char *line, std::vector<char *> &res, const char *sep = t n v f r ); int main(int argc, char **argv) { FILE *infile = stdin; char *line; line = (char *)calloc(5000000, sizeof(char)); if (line == NULL) { ...
#include <bits/stdc++.h> using namespace std; int main() { int w, h, u1, d1, u2, d2; cin >> w >> h >> u1 >> d1 >> u2 >> d2; int ans = w; if (d1 > d2) { ans += ((d1 + h) * (h - d1 + 1)) / 2; ans -= u1; ans = max(0, ans); ans += ((d1 + d2 - 1) * (d1 - d2) / 2); ans -= u2;...
#include <bits/stdc++.h> using namespace std; int main() { int n, m, k, r[1000], c[1000], min[1000], sum = 0; cin >> n >> m >> k; for (int i = 0; i < n; i++) { cin >> r[i] >> c[i]; min[i] = 9999999999; } for (int i = 0; i < n; i++) if (min[r[i] - 1] > c[i]) min[r[i] - 1] = c[i]...
#include <bits/stdc++.h> using namespace std; int n, s, f; int m; long long a[2 * 100005]; long long duc = 1e10; inline long long get(long long pos) { if (pos <= s) return s - pos + 1; else { return n - pos + s + 1; } } int main() { cin >> n; for (int i = 1; i <= n; i++) ...
#include <bits/stdc++.h> using namespace std; int dp[1002][20002]; int main() { ios_base::sync_with_stdio; int n, m, x, y, i, j, a; cin >> n; long long ans = 0; for (i = 1; i <= n; i++) { cin >> a; for (j = 0; j < a; j++) { dp[i][j] = dp[i - 1][j + a]; } for (j ...
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7, mod2 = 998244353; unsigned long long base = 131; const int w = 5e5 + 5; long long n, m; struct node { int x, y, z; } s[w]; int cmp(node x, node y) { if (x.x != y.x) return x.x > y.x; else return x.y > y....
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e5 + 1; int a[6]; int n; int b[MAXN]; int ptr[MAXN]; int f[MAXN][6]; int main() { for (int i = 0; i < 6; ++i) cin >> a[i]; cin >> n; for (int i = 0; i < n; ++i) cin >> b[i]; for (int i = 0; i < n; ++i) { for (int j = 0...
#include <bits/stdc++.h> const int maxi = 2000000000; const int maxq = 1000000000; const double eps = 1e-10; const double pi = acos(-1); const double inf = 1e+18; const int mo = 1000000007; using namespace std; char s[111111], s1[111111]; int main() { gets(s); gets(s1); int n = strlen(s); ...
#include <bits/stdc++.h> struct node { int same, rev; } T[524288]; int N, Q, a[100001]; inline void down(int p) { if (T[p].same) { T[p << 1].same = T[p].same; T[p << 1 | 1].same = T[p].same; T[p << 1].rev = T[p << 1 | 1].rev = 0; T[p].same = 0; } else if (T[p].rev) { if...
#include <bits/stdc++.h> using namespace std; const long long mod = 1e6 + 3; long long fastexp(long long a, long long b, long long n) { long long res = 1; while (b) { if (b & 1) res = res * a % n; a = a * a % n; b >>= 1; } return res; } int main() { vector<long long> p(11...
#include <bits/stdc++.h> using namespace std; mt19937 rnd(0); const long long MAXN = 2e6 + 1, MOD = 998244353, M = 1000000001; signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t; cin >> t; for (; t--;) { long long n, m; cin >> n >> m; long long...
#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; int main() { long long int t, n, i, j, m, d, k, q, y, z, l, r, a, b, c; cin >> t; while (t--) { ...
#include <bits/stdc++.h> using namespace std; long long a[150500]; int main() { ios_base::sync_with_stdio(false); int t; cin >> t; vector<long long> ans; for (int f = 0; f < t; f++) { long long n, m; cin >> n >> m; vector<long long> l; l.push_back(m % 10); for (lo...
#include <bits/stdc++.h> using namespace std; int sum(int a) { int s = 0; while (a > 0) { s += (a % 10); a = a / 10; } return s; } int main() { int n, a, b; cin >> n; while (sum(n) % 4 != 0) { n++; } cout << n << endl; return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; ll c[10]; int dx[] = {1, 0, -1, -1, 0, 1}; int dy[] = {1, 1, 0, -1, -1, 0}; int main() { int t; cin >> t; while (t--) { ll x, y; cin >> x >> y; for (int i = 0; i < 6; ++i) cin >> c[i]; long long ans = 5e1...
#include <bits/stdc++.h> using namespace std; const int mod = 998244353, mp = mod - 1; int k, n, m, g[105][105], f[105][105], tmp[105][105]; void mul(int ord) { if (ord) { for (int i = 1; i <= k; i++) for (int j = 1; j <= k; j++) tmp[i][j] = f[i][j], f[i][j] = 0; for (int i = 1; i <= k; ...
#include <bits/stdc++.h> using namespace std; int dp[222][105]; int dp2[105]; char cc[555]; char c[111]; char a[111]; int alen, clen; int main() { int b, d; scanf( %d %d n , &b, &d); gets(a); gets(c); alen = strlen(a); clen = strlen(c); for (int i = 0; i < clen; i++) { ...
#include <bits/stdc++.h> using namespace std; int main() { int a, b, l, r, start; cin >> a >> b >> l >> r; if (a == 3 && b == 1 && l == 4 && r == 10) { cout << 4 << endl; return 0; } if (r - l + 1 > 48) { if (a > b) cout << 2 * a - b; else cout << 1 + a; ...
#include <bits/stdc++.h> #include <string> #include <algorithm> #include <vector> #include <string.h> #include <stdlib.h> #include <chrono> #include <ctime> using namespace std; using namespace std::chrono; typedef long long ll; #define fast ios_base::sync_with_stdio(false); cin.tie(nullptr) #de...
#include <bits/stdc++.h> using namespace std; int v[4010], d[4010], p[4010], c[4010]; int main() { int n, ans = 0; scanf( %d , &n); for (int i = 0; i < n; i++) { scanf( %d%d%d , &v[i], &d[i], &p[i]); } for (int i = 0; i < n; i++) { if (p[i] >= 0) { c[ans++] = i; int...
#include <bits/stdc++.h> using namespace std; const int N = 1002; int n, m, k; long long fact(int x) { if (x < 0) return 0; long long ret = 1; for (int i = 1; i <= x; i++) ret = ret * i % 1000000007; return ret; } long long power(int b, int p) { if (!p) return 1; long long ret = powe...
#include <bits/stdc++.h> using namespace std; double a[19][19]; bool bz[19]; int b[19]; double f[270000][19]; int n; int _2[19]; int main() { cin >> n; _2[0] = 1; for (int i = 1; i <= n; i++) _2[i] = _2[i - 1] * 2; for (int i = 1; i <= n; i++) for (int j = 1; j <= n; j++) scanf( %l...
#include <bits/stdc++.h> using namespace std; int a[100], b[100]; int main() { int n, m, i, j, num, temp, maxn; scanf( %d , &n); for (i = 0; i < n; i++) scanf( %d , &a[i]); scanf( %d , &m); for (i = 0; i < m; i++) scanf( %d , &b[i]); num = temp = maxn = 0; for (i = 0; i < n; i++) ...
#include <bits/stdc++.h> using namespace std; const int INF = 1 << 29; double tick() { static clock_t oldticks; clock_t newticks = clock(); double diff = 1.0 * (newticks - oldticks) / CLOCKS_PER_SEC; oldticks = newticks; return diff; } int n, k; int main() { ios_base::sync_with_stdio...
#include <bits/stdc++.h> using namespace std; const int MAXN = 2e5 + 51, MOD = 998244353, INVP = 828542813; struct Matrix { int num[2][2]; Matrix() { memset(num, 0, sizeof(num)); } inline int *operator[](const int &x) { return num[x]; } inline const int *operator[](const int &x) const { return num...
#include <bits/stdc++.h> using namespace std; long long zero = 0; long long fexp(long long a, long long b) { long long ans = 1; while (b) { if (b & 1) ans = ans * a % 1000000007; b /= 2; a = a * a % 1000000007; } return ans; } long long multiply(long long a, long long b, long...
#include <bits/stdc++.h> using namespace std; const int INF = 1e9 + 10, MN = 202, ME = MN * MN; int n; bool adj[MN][MN], isinq[MN]; int q[MN], L, R, dist[MN]; int E, cap[ME], w[ME], from[ME], to[ME]; int par[MN]; int head[MN], prv[ME]; void Add(int s) { isinq[s] = true; q[R++] = s; if (R =...
#include <bits/stdc++.h> using namespace std; const int MOD = 1e9 + 7; void solve() { int n; cin >> n; vector<pair<int, int>> data(n); for (auto &x : data) cin >> x.first >> x.second; sort(data.begin(), data.end()); vector<vector<long long>> dp(2, vector<long long>(n, 0)); dp[0][0] = L...
#include <bits/stdc++.h> using namespace std; int main() { int T; cin >> T; while (T--) { string a, b, c; cin >> a >> b >> c; int n = a.size(); bool Ok = true; for (int i = 0; i < n; i++) Ok &= (c[i] == a[i] || b[i] == c[i]); puts(Ok ? YES : NO ); } }
#include <bits/stdc++.h> using namespace std; int a[100010]; char b[100010]; int main() { int n, ansl = -1e9, ansr = 1e9, l1 = -1e9, l2 = -1e9; scanf( %d , &n); for (int i = 1; i <= n; i++) { scanf( %d , &a[i]); } scanf( %s , b + 1); for (int i = 5; i <= n; i++) { if (b[i] ==...
#include <bits/stdc++.h> using namespace std; const int maxn = 55; const long long inf = 0x3f3f3f3f; const int mod = 998244353; const int MAX = 123123; const int N = 1e5 + 5; const double eps = 1e-6; inline int read() { int x = 0, f = 1; char ch = getchar(); while (ch < 0 || ch > 9 ) { ...
#include <bits/stdc++.h> int main() { int n; printf( YES n ); scanf( %d , &n); for (int i = 0; i < n; i++) { int x1, y1, x2, y2; scanf( %d %d %d %d , &x1, &y1, &x2, &y2); printf( %d n , ((12 + 2 * (x1 % 2) + (y1 % 2)) % 4) + 1); } return 0; }
#include <bits/stdc++.h> using namespace std; int i, j, k, l, s[1000005], n, m, tot, last[1000005], Next[1000005], to[1000005], dfn[1000005], low[1000005]; int vis[1000005], q[1000005], Q[1000005], q1[1000005], r, r1, G[1000005], T; vector<int> gt; int ans[1000005], A[1000005], B[1000005], a[1000005], b...
#include <bits/stdc++.h> #pragma GCC optimize( O3 ) #pragma GCC target( tune=native ) #pragma GCC optimize( fast-math ) using namespace std; const int DEBUG = 0; mt19937 gen( (unsigned)chrono::high_resolution_clock::now().time_since_epoch().count()); #pragma comment(linker, /STACK:16777216 ) void...
#include <bits/stdc++.h> using namespace std; int pos[1 << 12], num[1 << 12]; int p[1 << 12], q[1 << 12]; void maintain(int x, int y) { for (;;) { int t = pos[q[x] ^ num[x]]; if (t == x) return; else if (t == y) { swap(p[x], p[y]); swap(pos[p[x]], pos[p[y]]); ...
#include <bits/stdc++.h> using namespace std; int main() { long long w1, h1, w2, h2; cin >> w1 >> h1 >> w2 >> h2; cout << 2 * (w1 + h1 + h2) + 4 << endl; return 0; }
#include <bits/stdc++.h> template <typename T> bool chkmax(T &x, T y) { return x < y ? x = y, true : false; } template <typename T> bool chkmin(T &x, T y) { return x > y ? x = y, true : false; } using namespace std; long long ksm(long long a, long long b) { if (!b) return 1; long long ns...
#include <bits/stdc++.h> using namespace std; int main() { long long t; cin >> t; while (t--) { long long n; cin >> n; long long arr[n]; for (long long i = 0; i < n; i++) cin >> arr[i]; long long p = 0; while (p < n) { if (arr[p] < p) break; p++; ...
#include <bits/stdc++.h> using namespace std; const int maxn = 1e6 + 5; struct aa { int x, y; } s[maxn]; int vis1[maxn], vis2[maxn], vis3[maxn]; bool judge(int i) { if (vis2[s[i].x] + 1 > (vis1[s[i].x]) / 2 || vis2[s[i].y] + 1 > (vis1[s[i].y]) / 2) return false; else return t...
#include <bits/stdc++.h> using namespace std; int n; std::vector<int> G[100005]; int color[100005]; void DFS(int s, int co) { color[s] = co; for (int i = 0; i < G[s].size(); i++) { int to = G[s][i]; if (color[to] == 0) { DFS(to, -1 * co); } } } int main(int argc, char...
#include <bits/stdc++.h> using namespace std; const int SIZE = int(101); int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); string s; cin >> s; int i = 0; int a; string m[5]; while (1) { i++; if (s.size() % i == 0) { a = s.size() / i; } else { ...