func_code_string stringlengths 59 71.4k |
|---|
#include <bits/stdc++.h> using namespace std; int main() { int i, j, k, n, m, t, l; cin >> t; while (t--) { string s, p, q = abacaba , r; cin >> n >> s; int cnt = 0, cntt = 0; p = s; r = s; for (i = 0; i < n; i++) { int c = 0; for (j = i, k = 0; j < i... |
#include <bits/stdc++.h> using namespace std; int main() { long long d, n, m; cin >> d >> n >> m; vector<pair<long long, long long>> V(m); for (auto &x : V) cin >> x.first >> x.second; sort(V.begin(), V.end()); bool poss = true; for (int i = 0; i < V.size() - 1; i++) poss = poss &&... |
#include <bits/stdc++.h> using namespace std; const long long maxn = 3e5, N = 2e6 + 90, SQ = 300, base = 1999, mod = 1e9 + 7, INF = 1e9 + 1, lg = 30; const long double eps = 1e-4; long long n, a[maxn], b[maxn], c[maxn], d[maxn], cnt[maxn], s1, s2, tot; inline bool check() { for (long lon... |
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t) { t--; int a, b, c, d; cin >> a >> b >> c >> d; cout << b << << c << << c << n ; } return 0; } |
#include <bits/stdc++.h> using namespace std; int main() { long long int n, k, l, mx = 0, m, i, j, s = 0; cin >> n >> k; long long int a[n], t[n], sum[n], dv[n]; for (i = 0; i < n; i++) { cin >> a[i]; s += a[i]; dv[i] = s; } s = 0; for (i = 0; i < n; i++) { cin >>... |
#include <bits/stdc++.h> using namespace std; const int INF = 1e9; int main() { ios_base::sync_with_stdio(false); cin.tie(0); int n, m; cin >> n >> m; int sum = 0; vector<int> a(n); map<int, int> c; c[0] = 1; bool fl = 0; long long ans = 0; for (int i = 0; i < n; i++) {... |
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e6 + 3; bool in[113]; bool odw[113]; bool prze[113]; vector<int> v[113]; string tab[MAXN]; vector<char> ans; bool por = false; void DFS(int x) { prze[x] = true; odw[x] = true; for (auto it : v[x]) { if (prze[it]) ... |
#include <bits/stdc++.h> using namespace std; const int Maxn = 200005; int n, m; long long ans[Maxn]; struct Segment { long long l, r; int pos; } A[Maxn], land[Maxn]; bool cmp(const Segment &a, const Segment &b) { return a.l < b.l || a.l == b.l && a.r < b.r; } struct node { int pos; ... |
#include <bits/stdc++.h> using namespace std; int x, k, n, q, cnt; long long num[10]; int bel[1 << 10]; struct Square { long long num[75][75]; Square() { for (int i = 1; i <= 70; i++) { for (int j = 1; j <= 70; j++) num[i][j] = 1e18; num[i][i] = 0; } } Square operat... |
#include <bits/stdc++.h> using namespace std; const int N = 110; int a[N * N], n, T, dp[N * N], rec[305]; int cal(int x) { int m = n * x, len = 0; for (int i = 1; i <= m; i++) { if (a[i] >= dp[len]) dp[++len] = a[i]; else { int pos = upper_bound(dp + 1, dp + len + 1, a[i]) - ... |
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int r = 0; int rr = 0; int prev = 10000; while (n--) { int a, b; cin >> a >> b; if (a != b) r = 1; else { if (a > prev) rr = 1; } prev = a; } if (r == 1) ... |
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define endl n #define x1 fgdfgdg const ll DIM = 2E5+7; ll A[DIM]; ll GCD(ll a,ll b){ if (a==0 || b==0)return a+b; return GCD(b%a,a); } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.ti... |
#include <bits/stdc++.h> using namespace std; int k, d; string a, b = CODEFORCES ; int main() { cin >> a; if (a == b) { cout << YES n ; return 0; } for (int i = 0; i < a.size(); i++) { for (int j = i; j < a.size(); j++) { string h; for (int l = 0; l < i; l++) ... |
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 10; struct node { int x, flag; } a[2 * N]; bool cmp(const node a, const node b) { if (a.x == b.x) return a.flag > b.flag; else return a.x < b.x; } vector<pair<int, int> > ans; int main(void) { int n, k, l, r; ... |
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int a[3000]; int ert = 0, at = 0, as = 0; int k = 1; while (k < 3000) { ert++; if (ert % 10 == 0) at++; if (ert % 10 == 0 and at % 10 == 0) as++; if (k <= 9) { a[k] = ert % 10; ... |
#include <bits/stdc++.h> using namespace std; long long prime[2000006]; int main() { long long i, j; prime[1] = 1; for (i = 2; i < 2000006; i++) { for (j = 2 * i; j < 2000006; j += i) prime[j] = 1; } long long n; cin >> n; long long a[n], co = 0; for (i = 0; i < n; i++) { ... |
#include <bits/stdc++.h> using namespace std; int table[20][20]; int A[20] = {0, 0, 4, 6, 8, 9, 11, 13, 15, 17}; int a[20][20]; int first_x, last_x, first_y, last_y; int n, m; int ans = 0, cur = 0; void solve(int x, int y) { if (x > last_x) { if (cur > ans) { ans = cur; for (in... |
#include <bits/stdc++.h> using namespace std; const double EPS = 1e-6; const double PI = acos(-1); const int INF = 1e9; void FAST() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); } signed main() { FAST(); int n; cin >> n; vector<long long> a(n + n); for... |
#include <bits/stdc++.h> using namespace std; int main() { int n, m, i, j, first, end, count = 0; cin >> n >> m; vector<int> a(m + 1, 0); for (i = 0; i < n; i++) { cin >> first >> end; for (j = first; j <= end; j++) a[j] = 1; } for (i = 1; i < m + 1; i++) { if (a[i] == 0) c... |
#include <bits/stdc++.h> using namespace std; void swap(int& a, int& b) { int tmp; tmp = a; a = b; b = tmp; } void QuickSort(int l, int h, int a[], int b[]) { int i = l, j = h; int pivot = a[l + rand() % (h - l + 1)]; while (i <= j) { while (a[i] < pivot) i++; while (a[j]... |
#include <bits/stdc++.h> using namespace std; int main() { set<int> s; long long int n, m, k, a; cin >> n >> m; while (n--) { cin >> k; while (k--) { cin >> a; s.insert(a); } } if (s.size() == m) { cout << YES << n ; } else { c... |
#include <bits/stdc++.h> using namespace std; int n, m, q; pair<int, bool> a[400100]; int dsu[200100]; pair<int, int> query[200100]; long long ans[200100]; int last[200100]; long long prsum[400100]; int f(int x) { if (dsu[x] < 0) return x; int r = f(dsu[x]); dsu[x] = r; return r; } ... |
#include <bits/stdc++.h> const int maxi = 2000000000; const int maxq = 1000000000; const double eps = 1e-10; const double pi = 3.1415926535897932; const double inf = 1e+18; const int mo = 1000000007; using namespace std; long long l, r; int main() { cin >> l >> r; if (l == r) { puts( 0 )... |
#include <bits/stdc++.h> using namespace std; double PI = 3.1415926535897932384626433; double DP[(1 << 20)]; vector<double> fx, fy, lg; double calc(double px, double py, double t, double al) { double d = sqrt((px - t) * (px - t) + py * py); double sina = sin(al * (PI / 180.0)); double sinb = fabs(... |
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int arr[n + 1]; vector<int> v; for (int i = 0; i < n; i++) { cin >> arr[i]; if (arr[i] == 1) { v.push_back(1); } else { v[v.size() - 1] = max(arr[i], v[v.size() - 1]); } } ... |
#include <bits/stdc++.h> using namespace std; int i; int main() { string s; cin >> s; int k; i = 0; while (s[i] == 0 ) { i++; } int f = 0, v = 0; bool b = false; while (i != s.size()) { if (s[i] == 4 ) f++; else if (s[i] == 7 ) v++; i+... |
#include <bits/stdc++.h> using namespace std; int n, k; struct node { int sz; vector<int> m, M; node() { sz = 1; for (int i = 0; i < k; ++i) { int tmp; scanf( %d , &tmp); m.push_back(tmp); M.push_back(tmp); } } bool operator<(const node &nd) co... |
#include <bits/stdc++.h> const int N = 100005; using namespace std; int n, a[N], b[N], flag[N]; int main() { scanf( %d , &n); for (int i = 1; i <= n; i++) scanf( %d , &a[i]), b[i] = 1; int now = a[n]; for (int i = n - 1; i >= 1; i--) { if (now > a[i]) b[i] = -1, flag[i] = 1, now = ... |
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 100; const int LOG = 18; const int inf = 1e9 + 10; struct node { int nex[2], val; node() { nex[0] = nex[1] = -1; val = inf; } }; vector<node> v; vector<int> div2[N]; bool mark[N]; int t[N]; node tmp; int go... |
#include <bits/stdc++.h> using namespace std; const int N = 2e6 + 7; const int inf = 0x3f3f3f3f; const long long INF = 0x3f3f3f3f3f3f3f3f; const int mod = 1000000007; const double eps = 1e-6; const double PI = acos(-1); int n, k, miu[N], Pown[N], sum[N]; int Power(int a, int b) { int ans = 1; ... |
#include <bits/stdc++.h> using namespace std; int main() { int q; scanf( %d , &q); for (int i = 0; i < q; i++) { int l, r, d; scanf( %d %d %d , &l, &r, &d); if ((double)l / d > 1) printf( %d n , d); else { int f = ((double)r / d) + 1; printf( %d n , f * d)... |
#include <bits/stdc++.h> using namespace std; const int _ = 1e5 + 7; const int __ = 4e5 + 7; const int L = 11; int n, Q; long long a[_], pw[L + 7]; namespace SGT { long long num[__], minx[__], tag[__]; bool cov[__]; bool flag; void Build(int k, int l, int r) { if (l == r) { int j = 0; ... |
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5; long long f[15], all[15]; long long n, k; int solve(int rem) { if (!rem) return 1; return solve(rem - 1) * 2; } long long solve(int i, string& str) { if (i == str.size()) return 1; long long ret = solve(i + 1, str); i... |
#include <bits/stdc++.h> const int mod = 1e9 + 7; const int p_mod = 998244353; using namespace std; long long fast_pow(long long a, long long b) { long long res = 1; while (b) { if (b & 1) res = (res * a) % mod; b >>= 1; a = (a * a) % mod; } return res % mod; } const int N ... |
#include <bits/stdc++.h> using namespace std; long long n; int main() { cin >> n; if (n == 1) cout << -1; else cout << n << << n + 1 << << n * (n + 1); return 0; } |
#include <bits/stdc++.h> using namespace std; struct item { string n, c; int a, s; }; item make(string n, string c, int a, int s) { item z; z.a = a; z.c = c; z.n = n; z.s = s; return z; } struct rez { string n, t, h; int b; }; bool f2(rez a, rez b) { return a.b > ... |
#include <bits/stdc++.h> using namespace std; int main() { int x, y, sum = 0; vector<pair<int, int>> v(1e5); map<int, int> ways; scanf( %d , &x); for (int i = 0; i < x; i++) { scanf( %d , &y); sum += y; v[i] = pair<int, int>(y, sum); if (i != x - 1) ways[sum]++; } ... |
#include <bits/stdc++.h> using namespace std; int n; bool ison[100010]; char temp[100]; int q, t; int isprime[100010]; int prime[100010]; vector<int> pr[100010]; void preprocess() { fill(isprime, isprime + 100010, 0); fill(ison, ison + 100010, false); fill(prime, prime + 100010, -1); f... |
#include <bits/stdc++.h> using namespace std; int n, m, x; void ans(int x1, int x2, int y1, int y2, int now) { if (x1 + 1 > x2 - 1 || y1 + 1 > y2 - 1) { cout << 0; return; } else { if (now + 1 == x) { if ((x2 - x1 - 1) == 1 || (y2 - y1 - 1) == 1) { if ((x2 - x1 - 1) == ... |
#include <bits/stdc++.h> using namespace std; int32_t main() { ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); long long t; cin >> t; while (t--) { long long d, m; cin >> d >> m; long long j = 1, ans = 1, sum = 0; while (sum + j <= d) { ans = ans * (j + 1) % m; ... |
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; int ind = s.size() - 1; for (int i = 0; i < s.size(); ++i) { if (s[i] == 0 ) { ind = i; break; } } bool flag = 0; for (int i = 0; i < s.size(); ++i) { if (!flag && s[i] == 0... |
#include <bits/stdc++.h> using namespace std; long long solve(int n) { int x = n; long long cnt = 0, ans = 0; while (x) { x = x / 10; cnt++; } ans = n * cnt + cnt - 1; int k = 1; for (int i = 0; i < cnt - 1; i++) { k = k * 10; ans = ans - k; } return ans; ... |
#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) ... |
#include <bits/stdc++.h> using namespace std; int main() { int k; vector<int> A; for (int i = 0; i < 4; ++i) { cin >> k; A.push_back(k); } sort(A.begin(), A.end()); if (A[0] + A[1] + A[2] == A[3] or A[0] + A[3] == A[1] + A[2]) { cout << YES ; } else { cout << NO... |
#include <bits/stdc++.h> using namespace std; queue<pair<int, int> > q; int n, s[3][7005], f[3][7005], k[3], dd[3][7005]; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n; for (int i = 1; i <= 2; i++) { cin >> k[i]; for (int j = 1; j <= k[i]; j++) cin >> s[... |
#include <bits/stdc++.h> using namespace std; const int inf = 1e9 + 10; const double pi = acos(-1.0); const double eps = 1e-8; struct node1 { int y, x1, x2; } a[5050]; int tp1; struct node2 { int x, y1, y2; } b[5050]; int tp2; bitset<5050> bs[5050]; int main() { int n; tp1 = tp2 ... |
#include <bits/stdc++.h> using namespace std; vector<int> prime; int isprime[1000005]; void Find() { for (int i = 2; i < 1000005; i++) { if (isprime[i] == 0) { prime.push_back(i); for (int j = i * 2; j < 1000005; j += i) isprime[j] = 1; } } } vector<int> v[1000005]; int... |
#include <bits/stdc++.h> using namespace std; struct Node { int l, r; long long maxi, lzy, maxiwthpre; }; struct Line { int l, r, v; bool operator<(Line L) const { return l < L.l; } }; int N, M; Node seg[800050]; long long pre[200005]; Line arr[200005]; void build(int l, int r, int i... |
#include <bits/stdc++.h> using namespace std; signed main() { ios_base::sync_with_stdio(0); cin.tie(0); long long ct; cin >> ct; while (ct--) { long long n, k; cin >> n >> k; vector<long long> a(n), was(n + 1), s; long long tmp = 0; for (long long i = 0; i < (n); ++... |
#include <bits/stdc++.h> using namespace std; template <typename T, typename U> ostream& operator<<(ostream& os, const pair<T, U>& _p) { return os << ( << _p.first << , << _p.second << ) ; } template <typename T> ostream& operator<<(ostream& os, const vector<T>& _V) { bool f = true; os << ... |
#include <bits/stdc++.h> using namespace std; int main() { int n, m, k, ans; int a[105]; while (cin >> n >> m >> k) { ans = 1000000; for (int i = 0; i < n; i++) { cin >> a[i]; } m--; for (int i = 1; m - i >= 0; i++) { if (a[m - i] <= k && a[m - i]) { ... |
#include <bits/stdc++.h> using namespace std; void solve() { int x, y, n; cin >> x >> y >> n; int k = (n / x) * x + y; if (k <= n) { cout << k; } else { cout << k - x; } cout << endl; } int main() { int test_cases; cin >> test_cases; while (test_cases--) { ... |
#include <bits/stdc++.h> using namespace std; long long pw(long long a, long long b, long long md) { return (!b ? 1 : (b & 1 ? a * pw(a * a % md, b / 2, md) % md : pw(a * a % md, b / 2, md) % md)); } const long long MOD = 1e9 + 7, MAXN = 1e6 + 10; bool prime[MAXN]; ... |
#include <bits/stdc++.h> using namespace std; const int MOD = 1000000007; const int MAX = 1000005; int SetBit(int n, int x) { return n | (1 << x); } int ClearBit(int n, int x) { return n & ~(1 << x); } int ToggleBit(int n, int x) { return n ^ (1 << x); } bool CheckBit(int n, int x) { return (bool)(n & (1 ... |
#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; long long gcd(long long a, long long b) { if (a % b == 0) return b; else return gcd(b, a % b); } void palindrome(string s) { int i = 0; int j = s.size() - 1; while (i < j) { if (s[i] != s[j]) return; i++; j--; } ... |
#include <bits/stdc++.h> using namespace std; int sum(int[][3], int, int); bool valid(int); int main() { int A[3][3]; for (int i = 0; i < 3; ++i) for (int j = 0; j < 3; ++j) cin >> A[i][j]; for (int i = 0; i < 3; ++i) { for (int j = 0; j < 3; ++j) cout << !(sum(A, i, j) % 2); cout ... |
#include <bits/stdc++.h> using namespace std; int const mod = 1e9 + 7; inline void SAFE_ADD(int& a, int b) { a += b; if (a >= mod) a -= mod; } struct Matr { vector<vector<int> > _data; Matr(int sz) : _data(sz, vector<int>(sz, 0)) {} void ones() { for (int i = 0; i < _data.size(); ++i... |
#include <bits/stdc++.h> using namespace std; const int MAX_N = 100 + 10; int a[MAX_N]; int main() { int n, count = 0, f = 0, h = 0, b; cin >> n; for (int i = 0; i < n; i++) { cin >> b; if (b < 0) count++; if (count == 3) { f++; a[f] = i - h; h += a[f]; ... |
#include <bits/stdc++.h> using namespace std; const int maxn = 100005; const int maxm = 300005; int n, m, cnt1, cnt2, ans; int head[maxn], Head[maxn]; int dis1[maxn], vis1[maxn]; int use1[maxn], use2[maxn]; int num[maxn], ok[maxn]; struct nood { int nex, to, w; int fr; }; nood e[maxm], E[m... |
#include <bits/stdc++.h> using namespace std; const int MAX_N = 2e5; vector<int> gr[MAX_N]; int indx(int h, int t) { return h * 450 + t; } int win = 1e9; int lose = 0; bool draw = false; int used[MAX_N] = {0}; void bfs(int st_indx) { queue<pair<int, int>> q; q.push({0, st_indx}); used[st_i... |
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; int a[n]; for (int i = 0; i < n; ++i) cin >> a[i]; m--; int cnt = 0; for (int i = 0; i < n; ++i) if (1) { bool ok = 0; for (int j = i + m; j >= 0 && j >= i - m; --j) if (j ... |
#include <bits/stdc++.h> using namespace std; const int N = 250; int a[N + 5], ans; double fac[20005]; double POI(int P) { double ans = 0; double v = log(P); for (int i = (int)(1); i <= (int)(N); i++) if (a[i] < 0) return -1e300; else ans += v * a[i] - P - fac[a[i]]; ... |
#include <bits/stdc++.h> using namespace std; template <class T> void gi(T &x) { int f; char c; for (f = 1, c = getchar(); c < 0 || c > 9 ; c = getchar()) if (c == - ) f = -1; for (x = 0; c <= 9 && c >= 0 ; c = getchar()) x = x * 10 + (c & 15); x *= f; } const int N = 4e5 + 10... |
#include <bits/stdc++.h> using namespace std; long long gcd(long long a, long long b) { if (b == 0) return a; return gcd(b, a % b); } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long n, ans = 0, pot; long long a, b, c, e; cin >> n; if (n <= 2) { ... |
#include <bits/stdc++.h> using namespace std; const int MAX_N = 100000; const long long INFLL = 1e15; int N, Q; long long a[MAX_N + 1], b[MAX_N + 1]; long long S = 0; long long zero(long long x) { return (x > 0) ? x : -x; } struct SEG1 { struct NODE { int l, r; bool b; }; vector<... |
#include <bits/stdc++.h> using namespace std; const int intmax = 0x3f3f3f3f; const long long lldmax = 0x3f3f3f3f3f3f3f3fll; double eps = 1e-8; template <class T> inline void checkmin(T &a, T b) { if (b < a) a = b; } template <class T> inline void checkmax(T &a, T b) { if (b > a) a = b; } t... |
#include <bits/stdc++.h> using namespace std; long long fast_expo(long long base, long long exp, long long module) { long long ans = 1; while (exp) { if (exp & 1) ans = (ans * base) % module; base = (base * base) % module; exp >>= 1; } return ans; } bool primes[100001]; void ... |
#include <bits/stdc++.h> using namespace std; long long int MOD = 1000000007; long long int gcd(long long int a, long long int b) { if (b == 0) return a; else return gcd(b, a % b); } long long int lcm(long long int a, long long int b) { return a / gcd(a, b) * b; } long long int pow... |
#include <bits/stdc++.h> using namespace std; int main() { int n, m; scanf( %d%d , &m, &n); vector<int> a(n, 0); for (int i = 0; m > 0; i = (i + 1) % n) { a[i]++; m--; } for (int i = 0; i < n; i++) printf( %d , a[i]); return 0; } |
#include <bits/stdc++.h> using namespace std; long long a, b; bool used[1000005]; int main() { cin >> a >> b; long long max_num = 0, s = 0, max_id; for (;; max_num++) { if (s + max_num + 1 > a + b) break; s += max_num + 1; max_id = max_num; } s = 0; int cnt = 0; for... |
#include <bits/stdc++.h> using namespace std; char BUF[500010]; int n, m; int up[500010], down[500010], L[500010], R[500010]; int main() { scanf( %d%d , &n, &m); for (int i = 0; i < n; ++i) { scanf( %s , &BUF); for (int j = 0; j < m; ++j) switch (BUF[j]) { case 1 : i... |
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 11, mod = 1e9 + 7; const double EPS = 1e-7; const int INF = 2e9; const int base = 500; const int dx[] = {1, -1, 0, 0}; const int dy[] = {0, 0, 1, -1}; int m, t, r, w[333], ans; bool ct[333 + base + 11]; int main() { if (fopen( str... |
#include <bits/stdc++.h> using namespace std; const int MOD = 1e9 + 7; const int MX = 2e5 + 5; const long long INF = 1e18; const long double PI = 4 * atan((long double)1); template <class T> bool ckmin(T& a, const T& b) { return a > b ? a = b, 1 : 0; } template <class T> bool ckmax(T& a, const T... |
#include <bits/stdc++.h> using namespace std; bool win(long long a, long long b) { if (a < b) swap(a, b); if (!b) return (false); if (!win(b, a % b)) return (true); long long p = a / b; return (p % (b + 1) % 2 == 0); } int main() { int T; scanf( %d , &T); while (T--) { long... |
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; if (n == 1) cout << 5; else cout << 25; return 0; } |
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); long long n, m; cin >> n >> m; long long on[n + 2]; long long is[n + 1]; int inst[n + 2]; is[0] = 1; int pval = m; inst[0] = 0; for (int i(1); i <= n; i++) { cin... |
#include <bits/stdc++.h> using namespace std; long long read() { long long a = 0, b = getchar(), c = 1; while (!isdigit(b)) c = b == - ? -1 : 1, b = getchar(); while (isdigit(b)) a = a * 10 + b - 0 , b = getchar(); return a * c; } long long n, ans, p[200005]; pair<long long, long long> a[20... |
#include <bits/stdc++.h> using namespace std; template <typename T> inline T abs(T t) { return t < 0 ? -t : t; } const long long modn = 1000000007; inline long long mod(long long x) { return x % modn; } const int MAXN = 212345; int n, m, k; pair<long long, long long> s[MAXN]; long long d, v, V; ... |
#include <bits/stdc++.h> using namespace std; long long int GC(long long int a, long long int b) { if (b == 0) return a; else return GC(b, a % b); } long long int inv_gc(long long int a, long long int b) { return a / GC(a, b) * b; } long long int Ceil(long long int a, long long int b... |
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 10; const int P = 998244353; int T, n; int ans[N]; vector<int> e[N]; int f[N]; bool dfs(int x, int fa, int y) { for (auto v : e[x]) if (v != fa && !dfs(v, x, y)) return 0; if (f[x] % y == 0) { f[fa]--; return 1; ... |
#include <bits/stdc++.h> using namespace std; long long con[2][2005][2005] = {0}; long long add[2][2005][2005] = {0}; long long can[2][2005][2005] = {0}; long long MOD = 1e9 + 7; char all[2005][2005]; long long how[2][2005][2005]; int main() { long long N, M, i, j, k, t = 0, l, r; scanf( %lld %l... |
#include <bits/stdc++.h> using namespace std; int main() { int a, b, c, d, e, f; cin >> a >> b >> c >> d >> e >> f; cout << (a + b + f) * (a + b + f) - b * b - d * d - f * f << endl; return 0; } |
#include <bits/stdc++.h> using namespace std; long long int __gcd(long long int a, long long int b) { return (a % b) ? __gcd(b, a % b) : b; } bool prime(long long int k) { for (long long int i = 2; i * i <= k; i++) if (k % i == 0) { return false; } return true; } void pdash(i... |
#include <bits/stdc++.h> using namespace std; const int N = 200200; int n, s[N] = {}, d[N] = {}, top = 0; long long sum = 0; int main() { scanf( %d , &n); s[++top] = 0; for (int i = 1, t, x, y; i <= n; ++i) { scanf( %d , &t); if (t == 1) scanf( %d%d , &x, &y), sum += x * y, d[x... |
#include <bits/stdc++.h> using namespace std; int main() { int a, b, c, n; cin >> a >> b >> c >> n; int tot = n - a - b + c; if (tot <= 0 || a < c || b < c) return 0 * puts( -1 ); cout << tot << endl; return 0; } |
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n; cin >> n; vector<int> visited(n); vector<int> a(n); vector<int> ans(n); for (int i = 0; i < n; i++) { cin >> a[i]; a[i]--; } for (int i = 0; i ... |
#include <bits/stdc++.h> using namespace std; const double pi = acos(-1.0); const double eps = 1e-8; const int T = 23; inline double sqr(double x) { return x * x; } inline int dcmp(double x) { return fabs(x) <= eps ? 0 : (x > 0 ? 1 : -1); } int n; double r, v, s, t; bool check(double x) { double l... |
#include <bits/stdc++.h> using namespace std; template <typename T, typename U> inline void smin(T &a, const U &b) { if (a > b) a = b; } template <typename T, typename U> inline void smax(T &a, const U &b) { if (a < b) a = b; } template <class T> inline void gn(T &first) { char c, sg = 0; ... |
#include <bits/stdc++.h> using namespace std; string c = abacaba ; int f(string str) { int cnt = 0; for (int i = 0; i < str.size(); i++) { if (c.size() > str.size() - i) { break; } if (c == str.substr(i, c.size())) cnt++; } return cnt; } bool f1(string str) { for... |
#include <bits/stdc++.h> long long n; int main() { scanf( %lld , &n); printf( %lld n , n - n / 2 - n / 3 - n / 5 - n / 7 + n / 6 + n / 10 + n / 14 + n / 15 + n / 21 + n / 35 - n / 30 - n / 42 - n / 70 - n / 105 + n / 210); } |
#include <bits/stdc++.h> using namespace std; template <typename T, typename U> std::pair<T, U> operator+(const std::pair<T, U>& l, const std::pair<T, U>& r) { return {l.first + r.first, l.second + r.second}; } typedef void (*callback_function)(void); const long long ZERO = 0LL; const long long INF64 ... |
#include <bits/stdc++.h> using namespace std; const int mod = 998244353; const int N = 505; int fac[N], inv_fac[N]; int mod_pow(int b, int p) { int ans = 1; while (p) { if (p & 1) { ans = (1ll * ans * b) % mod; p--; } b = (1ll * b * b) % mod; p /= 2; } r... |
#include <bits/stdc++.h> using namespace std; const int maxn = 1100; long long x, y; int n; int main() { std::ios::sync_with_stdio(false); while (cin >> n) { long long x1, x2, y1, y2; x1 = y1 = 1000000000; x2 = y2 = -1000000000; for (int i = 0; i < n; ++i) { cin >> x >>... |
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 40; const int inf = 0x3fffffff; void read(int &x) { char ch; bool flag = 0; for (ch = getchar(); !isdigit(ch) && ((flag |= (ch == - )) || 1); ch = getchar()) ; for (x = 0; isdigit(ch); x = (x << 1) + (x << 3) + ... |
#include <bits/stdc++.h> using namespace std; int n, d, h; struct edge { int n1; int n2; }; edge vertices[100000]; int main() { cin >> n >> d >> h; if (d > 2 * h || (h == 1 && d == 1 && n > 2)) cout << -1 << endl; else { int idx = 0; int usedNode = 1; for (int i... |
#include <bits/stdc++.h> using namespace std; stack<char> st; string s, ans = ; char mn[111111]; long long n; int main() { cin >> s; n = s.size(); mn[n - 1] = s[n - 1]; for (int i = n - 2; i >= 0; i--) { mn[i] = min(mn[i + 1], s[i]); } for (int i = 0; i < n;) { if (st.e... |
#include <bits/stdc++.h> using namespace std; long long full, n, k, x, i, ans, a[100001], b[100001]; void f(long long l, long long r, long long d) { if (l > r) return; if (l == 0) ans += r / d + 1; else ans += (r / d) - (l - 1) / d; } int main() { cin >> n >> k; for (i = 1; i <... |
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); int n, m; cin >> n >> m; bool aOk = true, bOk = true; vector<vector<int>> a(n, vector<int>(m)), b(n, vector<int>(m)); for (int i = 0; i < n; i++) { for (int j = 0; j < m; j... |
#include <bits/stdc++.h> using namespace std; int dp[111111]; int main() { int n, m; cin >> n >> m; vector<int> a; for (int i = 0; i < n; i++) { int x; cin >> x; a.push_back(x); } reverse(a.begin(), a.end()); set<int> b; for (int i = 0; i < n; i++) { if (b.f... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.