solution
stringlengths
53
181k
difficulty
int64
0
27
#include <bits/stdc++.h> using namespace std; using cat = long long; template <typename T> struct vec3 { int N[3]; vector<T> data; vec3() = default; vec3(int N0, int N1, int N2, T val = 0) : N{N0, N1, N2} { data.resize(N0 * N1 * N2, val); } T& operator()(int i0, int i1, int i2) { return data[(i0 * N...
27
#include <bits/stdc++.h> using namespace std; long long ans = 0, l; int f(int a, int b, int c) { for (int i = 0; i <= l; i++) { int k = a + i; long long rem = k - b - c; rem = min(rem, l - i); if (rem >= 0) ans -= (rem + 2) * (rem + 1) / 2; } return 0; } int main() { int a, b, c; cin >> a >> b...
13
#include <bits/stdc++.h> using namespace std; const int N = 1001; vector<int> arr[N]; int govt[N]; bool visited[N]; void dfs(int ver, int& tot, int& edg) { visited[ver] = true; tot++; edg += arr[ver].size(); for (int i = 0, sz = arr[ver].size(); i < sz; i++) { int neigh = arr[ver][i]; if (!visited[neigh...
7
#include <bits/stdc++.h> using namespace std; const int N = 1e5; vector<pair<int, int>> g[N]; map<pair<int, int>, int> cost; set<pair<int, int>> a[N], b[N]; multiset<long long> dp; set<pair<int, pair<int, int>>> dp2; void solve() { auto minr = *dp2.begin(); long long ans = 1e18; if ((int)(dp).size()) { ans = ...
23
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7, siz = 1e5 + 5; long long t, n, m, k; vector<long long> have[siz]; bool prime[siz]; int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> n; for (long long i = 1; i <= n; i++) { long long x, from; cin >> x >> from; ...
11
#include <bits/stdc++.h> using namespace std; const int inf = 0x3f3f3f3f; const int maxn = 1e5 + 7; const double pi = acos(-1.0); int n, m; long long a[maxn], b[maxn], c[maxn], v[maxn], t[maxn]; long long dp[maxn]; void discretization() { sort(b + 1, b + 1 + n); int len = unique(b + 1, b + 1 + n) - b - 1; for (in...
12
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 123; int n, ar[maxn], er[maxn], fn[maxn]; inline void update(int x, int v) { for (x++; x <= n; x += x & -x) fn[x] += v; } inline int query(int x) { int ret = 0; for (x++; x; x -= x & -x) ret += fn[x]; return ret; } int main() { scanf("%d", &...
12
#include <bits/stdc++.h> #pragma comment(linker, "/stack:100000000") using namespace std; const int N = 1e6; int dp[N]; int p[4][N]; bool mex[5]; int main() { p[0][0] = 1; for (int i = 1; i < N; i++) { int L = (int)(ceil(pow(i, 0.25)) + 1e-9); int R = min((int)sqrt((double)i), i - 1); for (int(j) = 0; (...
14
#include <bits/stdc++.h> using namespace std; const int MAX = 2e5 + 5; long long numbers[MAX]; long long frq[MAX]; long long dp[MAX]; int main() { ios_base::sync_with_stdio(0); int n; cin >> n; for (int i = 0; i < n; ++i) { cin >> numbers[i]; frq[numbers[i]]++; } dp[0] = 0; dp[1] = frq[1]; for (...
7
#include <bits/stdc++.h> double pi = acos(-1); using namespace std; int n; int arr[150002]; int freq[150002]; bool cond[150002]; int cnt = 0; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n; for (int i = 0; i < n; i++) cin >> arr[i]; sort(arr, arr + n); for (int i = 0; i < n; ...
7
#include <bits/stdc++.h> using namespace std; int main() { int n, a[300010]; cin >> n; for (int i = 0; i < n; i++) { cin >> a[i]; } sort(a, a + n); long long int f = 0; if (n % 2 == 0) { for (int i = 0; i < n / 2; i++) { f += (a[i] + a[n - i - 1]) * (a[i] + a[n - i - 1]); } } else { ...
1
#include <bits/stdc++.h> using namespace std; int main() { int tc; cin >> tc; while (tc--) { int n; cin >> n; map<int, bool> mp, mpp; int arr[n]; for (int i = 0; i < n; i++) { cin >> arr[i]; mp[arr[i]] = 1; } int ans = -1; for (int i = 1; i <= 1024; i++) { int cnt...
4
#include <bits/stdc++.h> using namespace std; inline long long read() { long long sum = 0, ff = 1; char ch = getchar(); while (!isdigit(ch)) { if (ch == '-') ff = -1; ch = getchar(); } while (isdigit(ch)) sum = sum * 10 + (ch ^ 48), ch = getchar(); return sum * ff; } inline void write(long long x) {...
16
#include <bits/stdc++.h> using namespace std; const int N = 10000000 + 5, mod = 1000000007; const long long hash_num = 20000623LL; char s1[N], s2[N]; int a[N], b[N]; int n; long long k, cnt1, cnt2, hash_a, hash_b, fac_n; bool org_ok; inline long long get_hash(int *a, int n) { long long ret = 0; for (int i = 1; i <=...
9
#include <bits/stdc++.h> using namespace std; int main() { int n = 0, m = 0, c = 0; cin >> n >> m >> c; int a[n]; int b[m]; for (int i = 0; i < n; i++) { cin >> a[i]; } for (int i = 0; i < m; i++) { cin >> b[i]; } for (int i = 0; i < n - m + 1; i++) { int count = 0; for (int j = i; j <...
4
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long int t, z = 1; cin >> t; while (t--) { long long int n; cin >> n; long long int s = 1, d = 1; vector<long long int> a; while ((s + (1 << d)) <= n) { ...
11
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; bool prime = true; for (int i = 2; i * i <= n; i++) { if (n % i == 0) { prime = false; break; } } if (prime) cout << 1 << '\n'; else if (n % 2 == 0) cout << 2 << '\n'; else { prime = true; for...
8
#include <bits/stdc++.h> using namespace std; const int MAXN = 2e5 + 100; const long long INF = 1e18; int N; pair<int, int> pts[MAXN]; long long dp[MAXN][2]; pair<int, int> mn[MAXN][2]; int cmp1(const pair<int, int>& a, const pair<int, int>& b) { return max(b.first, b.second) - max(a.first, a.second); } bool cmp2(con...
13
#include <bits/stdc++.h> using namespace std; using ll = long long; using ull = unsigned long long; using ld = long double; template <typename T> ostream& operator<<(ostream& os, const vector<T>& v) { for (const auto& x : v) os << x << " "; return os << "\n"; } template <typename T> istream& operator>>(istream& is,...
5
#include <bits/stdc++.h> using namespace std; int main(void) { long long int test, a, b, n, c, j; cin >> test; while (test--) { cin >> a >> b >> n; c = a ^ b; long long int ans[5] = {c, a, b}; j = n + 1; cout << ans[j % 3] << endl; } }
1
#include <bits/stdc++.h> using namespace std; int best[100000]; int second[100000]; long long best_vals[100000]; long long second_vals[100000]; struct Cube { int i; long long c, h; }; map<long long, vector<Cube> > colours; bool operator<(const Cube& self, const Cube& other) { return self.h > other.h; } int main() {...
9
#include <bits/stdc++.h> using namespace std; const long long OO = (long long)1e15; using namespace std; long long Pow(long long B, long long P) { long long R = 1; while (P > 0) { if (P & 1) R = (R * B); P /= 2; B = (B * B); } return R; } long long GCD(long long a, long long b) { while (b) { b...
9
#include <bits/stdc++.h> using namespace std; const int N = 2 * 1e5 + 10; const int mod = 998244353; inline int add(int a, int b) { return a + b >= mod ? a + b - mod : a + b; } inline int mul(int a, int b) { return a * 1ll * b % mod; } long long f[N]; long long fp(long long b, long long p) { if (p == 0) return 1; r...
12
#include <bits/stdc++.h> using namespace std; const int INF = 1 << 29; int main() { const int ORD[10][9] = { {1, 2, 3, 4, 5, 6, 7, 8, 9}, {2, 0, 3, 4, 5, 6, 7, 8, 9}, {3, 1, 4, 0, 5, 6, 7, 8, 9}, {4, 2, 5, 1, 6, 0, 7, 8, 9}, {5, 3, 6, 2, 7, 1, 8, 0, 9}, {6, 4, 7, 3, 8, 2, 9, 1, 0}, {7, 5, 8, 4...
11
#include <bits/stdc++.h> using namespace std; const int N = 100005; int dr8[] = {0, 0, 1, -1, 1, 1, -1, -1}; int dc8[] = {1, -1, 0, 0, -1, 1, -1, 1}; int dr4[] = {0, 1, -1, 0}; int dc4[] = {1, 0, 0, -1}; int freq[100]; pair<int, int> heap[100]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.ti...
11
#include <bits/stdc++.h> using namespace std; const int N = (int)1e5 + 1; const long long INF = (long long)1e18; int n, m; vector<vector<int> > a, b; vector<long long> sumRow, sumCol; long long getZeroRow() { vector<long long> tmp = sumCol; sort(tmp.begin(), tmp.end()); long long res = 0; for (int i = 1; i <= 4...
12
#include <bits/stdc++.h> using namespace std; int arr[2005]; int dp[2005]; int n, k; bool valid(int v) { memset(dp, 0, sizeof(dp)); dp[0] = 0; for (int i = 1; i < n; i++) { dp[i] = i; for (int j = i - 1; j >= 0; j--) { int diff = abs(arr[i] - arr[j]); if (diff <= 1LL * v * (i - j)) dp[i] = min...
12
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 10; const int mod = 1e9 + 9; int n, m; long long pot[maxn]; bool test() { long long p = 1; for (int i = 1; i <= m; ++i) { p *= 2LL; if (p > n) return true; } return false; } int main() { cin >> n >> m; if (!test()) { cout << 0 ...
5
#include <bits/stdc++.h> using namespace std; int a[100001], i, n, x, q, m; char c; int main() { int sum1 = 0, sum2 = 0; cin >> n; for (i = 1; i <= 100000; i++) a[i] = 0; for (i = 1; i <= n; i++) { cin >> x; a[x]++; } for (i = 1; i <= 100000; i++) { sum1 = sum1 + a[i] / 2; sum2 = sum2 + a[i]...
6
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); long long n, d, cur = 0, ans = 0; cin >> n >> d; for (int i = int(0); i < (int)d; ++i) { string s; cin >> s; bool is = true; for (int j = int(0); j < (int)s.size(); ++j) { if (s[j] == '0') is = fal...
0
#include <bits/stdc++.h> using namespace std; const int M = 1000000007; const int MM = 998244353; const long double PI = acos(-1); 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 pow...
19
#include <bits/stdc++.h> using namespace std; int main() { int t, x, s; scanf("%d%d%d", &t, &s, &x); if (t == x) puts("YES"); else if (((x - t) % s == 0 && (x - t) / s > 0) || ((x - t - 1) % s == 0 && (x - t - 1) / s > 0)) puts("YES"); else puts("NO"); }
1
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL); int t; cin >> t; while (t--) { int n, mm, x; int l, r; cin >> n >> x >> mm; int m = x, M = x; for (int i = 0; i < mm; i++) { cin >> l >> r; if ((r >= m && r...
5
#include <bits/stdc++.h> using namespace std; inline bool setmin(int &x, int y) { return (y < x) ? x = y, 1 : 0; } inline bool setmax(int &x, int y) { return (y > x) ? x = y, 1 : 0; } inline bool setmin(long long &x, long long y) { return (y < x) ? x = y, 1 : 0; } inline bool setmax(long long &x, long long y) { return ...
20
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> x, y; for (int i = 0; i < n; ++i) { int tx, ty; cin >> tx >> ty; x.push_back(tx); y.push_back(ty); } if (n % 2) { cout << "NO" << endl; return 0; } int hi = n / 2, ok = 1; for (int i = 1; i ...
10
#include <bits/stdc++.h> using namespace std; const int inf = 987654321; const long long int INF = 123456789987654321; const long long int mod = 1000000009; vector<long long int> factorial, inv_factorial; long long int pw(long long int x, long long int n) { long long int ret = 1; while (n) { if (n % 2) { ...
21
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int nxt = 5, kk = 2; string s[5] = {"Sheldon", "Leonard", "Penny", "Rajesh", "Howard"}; if (n < 6) { cout << s[n - 1] << endl; return 0; } while (nxt < n) { nxt += kk * 5; kk *= 2; } int diff = n - (nxt - (kk /...
3
#include <bits/stdc++.h> using namespace std; #define sim template < class c #define ris return * this #define dor > debug & operator << #define eni(x) sim > typename \ enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) { sim > struct rge { c b, e; }; sim > rge<c> range(c i, c j) { return rge<c>{i, j}; } s...
6
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); int t, n; cin >> t; while (t--) { cin >> n; long long temp; long long arr[n]; int ans = n; for (int i = 0; i < n; i++) { cin >> arr[i]; if (i == 0) temp = arr[i]; else if (arr[i]...
0
#include<bits/stdc++.h> using namespace std; int sum(long long int n) { int s =0 ; while(n) { s += (n%10); n /= 10; } return s; } long long int gcd(long long int a,long long int b) { if(b==0) return a; return gcd(b,a%b); } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NUL...
0
#include <bits/stdc++.h> using namespace std; int main() { string ss; cin >> ss; int poss[ss.size()]; int l = 0, r = ss.size() - 1; for (int i = 0; i < ss.size(); i++) { if (ss[i] == 'l') poss[r--] = i + 1; else poss[l++] = i + 1; } for (int i = 0; i < (int)ss.size(); i++) printf("%d\n...
4
#include <bits/stdc++.h> const long long INF = 1e18 + 1; const double EPS = 1e-10; const long long P = 1e9 + 7; const long long Q = 31; using namespace std; void hello() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); } void show(vector<long long>& arr) { for (auto i : arr) cout << i << " "; cout << ...
10
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; int nums[n]; int maxi = 0; for (int i = 0; i < n; i++) { cin >> nums[i]; if (nums[i] > maxi) { maxi = nums[i]; } } int diffs[maxi + 1]; int mo[maxi + 1]; for (int i = 0; i <= maxi; i++) { diffs[i]...
16
#include <bits/stdc++.h> using namespace std; long n, k; long ans; vector<long> vt[200005]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> n >> k; long d = (n - 1) / k; ans = 2 * d; if (n - 1 - d * k > 0) ans++; if (n - 1 - d * k > 1) ans++; cout << ans << "\n"; long cur = 2; for (lon...
10
#include <bits/stdc++.h> using namespace ::std; vector<vector<int> > graph; int n; long long int apps[100001], mult[100001]; long long int egcd(long long int a, long long int b, long long int &x, long long int &y) { if (b == 0) { x = 1; y = 0; return a; } long long int d = egcd(b, a...
13
#include <bits/stdc++.h> using namespace std; int main() { bool flag = 0; int c = INT_MAX; int ax[3][3] = {{0, 1, 2}, {-1, 0, 1}, {-2, -1, 0}}; int **ar; int cou; int n, m, i, j, x, y, nx, ny, k, l, o; cin >> n >> m; ar = (int **)calloc(n, sizeof(int *)); for (i = 0; i < n; i++) { ar[i] = (int *)c...
5
#include <bits/stdc++.h> using namespace std; template <class T> void checkmin(T &t, T x) { if (x < t) t = x; } template <class T> void checkmax(T &t, T x) { if (x > t) t = x; } const int N = 105555; int m, n, c; int a[N]; int b[N]; int main() { cin >> n >> m >> c; for (int i = 1; i <= n; i++) cin >> a[i]; fo...
4
#include <bits/stdc++.h> int ksm(int a, int b) { int jg = 1; while (b > 0) { if (b & 1) jg = 1ll * jg * a % 1000000007; a = 1ll * a * a % 1000000007; b = (b >> 1); } return jg; } int hangls(int sz[102][102], int n) { int jg = 1; for (int i = 0; i < n; i++) { int wz = -1; for (int j = i; ...
18
#include <bits/stdc++.h> using namespace std; double sides[405]; int main() { std::cout << std::fixed; std::cout << std::setprecision(10); double theta = 0; for (int i = 2; i < 405; i++) { sides[i] = cos(2 * acos(0) / (i * 2)) / sin(2 * acos(0) / (i)); } int T; int n; cin >> T; while (T--) { c...
12
#include <bits/stdc++.h> using namespace std; vector<pair<long long, pair<long long, long long>>> v; map<long long, long long> mp; long long po[300005]; int main() { ios_base::sync_with_stdio(false); cin.tie(0); long long n, m, x; cin >> n >> m; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { ...
12
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 10, mod = 1e9 + 7; int rd() { int x = 0, w = 1; char ch = 0; while (ch < '0' || ch > '9') { if (ch == '-') w = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') { x = (x << 3) + (x << 1) + (ch ^ 48); ch = getchar(); } ret...
23
#include <bits/stdc++.h> using namespace std; long long a, b, c, s; int N, Q; int ac[100005][20], level[100005]; vector<int> v[100005], tv[100005]; int p[300005]; void dfs(int cur, int lev) { level[cur] = lev; for (int nxt : v[cur]) { if (!level[nxt]) { tv[cur].push_back(nxt); dfs(nxt, lev + 1); ...
15
#include<bits/stdc++.h> using namespace std; #define endl "\n" #define pb push_back typedef long long ll; const double pi = acos(-1.0); const int mod = (1 ? 1000000007 : 998244353); const int inf = (1 ? 0x3f3f3f3f : 0x7fffffff); const int dx[] = { -1,0,1,0 }, dy[] = { 0,1,0,-1 }; const ll INF = (1 ? 0x3f3f3f3f3f3f3f3f ...
0
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false), cin.tie(0), cout.tie(0); int n; cin >> n; int crnt = 1; vector<int> arr(n); for (auto &i : arr) cin >> i; sort(arr.begin(), arr.end()); for (int i = 0; i < n; i += 1) if (arr[i] >= crnt) crnt++; cout << crnt <<...
4
#include <bits/stdc++.h> using namespace std; long long a[110]; long long n; bool che(long long x) { for (long long i = 2; i < x; i++) { if (x % i == 0) return true; } return false; } signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long t; cin >> t; while (t--) { ci...
0
#include <bits/stdc++.h> using namespace std; char st1[2020], p[520]; int pre[2020], l1, l2; int dp[2020][2020]; int main() { int i, j, k; while (scanf("%s", &st1) != EOF) { scanf("%s", &p); memset(pre, -1, sizeof(pre)); l1 = strlen(st1); l2 = strlen(p); for (i = 0; i < l1; i++) if (st1[i]...
14
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); long long t, n, m, i, j, k, x, y, xx, yy, ans, a, b, dx, dy, s; cin >> t; while (t--) { cin >> n >> m >> x >> y >> xx >> yy; if (x > xx) swap(x, xx); if (y > yy) swap(y, yy); xx -= x - 1; yy...
10
#include <bits/stdc++.h> using namespace std; const int N = 4e5 + 5; const double eps = 1e-9; const int MAX_N = 1e6 + 5; const long long M = (long long)1e9 + 7; int Int() { int x; scanf("%d", &x); return x; } long long Long() { long long x; scanf("%lld", &x); return x; } void Char(char* ch) { scanf("%s", ch...
14
#include <bits/stdc++.h> using namespace std; const int MXN = 1e6 + 1; const int TMXN = 1e6 * 4 + 1; const long long INFL = 1e18; int n, p; string second[MXN]; bool cmp(string a, string b) { return (a + b) < (b + a); } int main() { scanf("%d", &n); for (int i = 1; i <= n; i++) { cin >> second[i]; } sort(sec...
9
#include <bits/stdc++.h> using namespace std; int main() { multiset<int> lenx, leny; set<int> nodex, nodey; int n, m, k; while (cin >> n >> m >> k) { char ch; int x; nodex.insert(0); nodey.insert(0); nodex.insert(n); nodey.insert(m); lenx.insert(n); leny.insert(m); while (k--...
7
#include <bits/stdc++.h> using namespace std; int tt; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> tt; while (tt--) { int n; vector<int> a, b; cin >> n; a.assign(n, 0); b.assign(n, 0); for (int i = 0; i < n; ++i) { cin >> a[i]; } for (int i = 0; i < ...
3
#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; cin >> n; vector<long long int> arr1(n), arr2(n); for (int i = 0; i < n; i++) cin >> arr1[i]; for (int i = 0; i < n; i++) cin >> arr2[i]; if (arr1[0] != 0 || arr...
7
#include <bits/stdc++.h> using namespace std; int n, m; char x[1011][1022]; int biga[1001], smla[1001], bigb[1001], smlb[1001]; bool cmpa(int i, int j) { if (biga[i] != biga[j]) return biga[i] > biga[j]; return smla[i] < smla[j]; } bool cmpb(int i, int j) { if (bigb[i] != bigb[j]) return bigb[i] > bigb[j]; retu...
12
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); int t; cin >> t; while (t--) { int n, k; cin >> n >> k; long long l = 0, r = k + 1; while (r - l > 1) { long long mid = (l + r) / 2; if ((mid * (mid + 1)) / 2 < k) l = mid; ...
5
#include <bits/stdc++.h> using namespace std; template <typename T> void chkmax(T &x, T y) { x = x > y ? x : y; } template <typename T> void chkmin(T &x, T y) { x = x > y ? y : x; } template <typename T> void update(T &x, T y, T mod) { x = x + y > mod ? x + y - mod : x + y; } const int INF = (1ll << 30); template...
15
#include <bits/stdc++.h> using namespace std; long long labs(long long a) { return a < 0 ? (-a) : a; } long long max(long long a, long long b) { return a > b ? a : b; } long long min(long long a, long long b) { return a < b ? a : b; } template <typename T> struct Point { T x, y; Point() {} Point(T xx, T yy) : x(x...
2
#include <bits/stdc++.h> using namespace std; int l; long long bad(int a, int b, int c, int v) { if (a + v < b + c) { return 0; } int x = min(l - v, a + v - b - c); if (0 > x) { return 0; } return (1LL * (x + 1) * (x + 2)) / 2; } int main() { ios_base::sync_with_stdio(false); vector<int> v(3); ...
13
#include <bits/stdc++.h> using namespace std; int main(void) { int n, m, a, prev = 1; long long k = 0; cin >> n >> m >> a; while (m--) { if (a > prev) k += a - prev; else if (a < prev) k += (n - prev) + a; prev = a; cin >> a; } cout << k; return 0; }
2
#include <bits/stdc++.h> using namespace std; const int maxn = 1010000; int n, ax[maxn], ay[maxn], bx[maxn], by[maxn]; int s[3010][3010], sx1[3010][3010], sx2[3010][3010], sy1[3010][3010], sy2[3010][3010]; int sum = 0, q[maxn]; void init() { scanf("%d", &n); for (int i = (1); i <= (n); ++i) { scanf("%d%d%d%...
16
#include <bits/stdc++.h> using namespace std; const int Mod = 1000000007; const int Maxn = 1010101; long long p, k, Ans; bool visited[Maxn]; void dfs(long long v) { visited[v] = true; if (!visited[v * k % p]) dfs(v * k % p); } int main() { cin >> p >> k; Ans = 1; if (k == 1) Ans = p; for (int i = 1; i < p; ...
10
#include <bits/stdc++.h> using namespace std; int main() { int n, k, a[100], otv = 0; bool check = false; cin >> n >> k; for (int i = 0; i < n; i++) { cin >> a[i]; if (a[i] <= k && otv == i) otv++; } for (int i = n - 1; i != 0 && n != otv; i--) { if (a[i] <= k) otv++; else break;...
0
#include <bits/stdc++.h> using namespace std; ifstream Cin("input.txt"); ofstream Cout("output.txt"); int main() { long long n, k, ans, i, j; cin >> n >> k; if (!n) { cout << 86400; return 0; } vector<pair<long long, long long> > r(n + 2); vector<vector<long long> > dp(n + 2, ...
11
#include <bits/stdc++.h> using namespace std; inline long long gcd(long long a, long long b) { a = ((a) < 0 ? -(a) : (a)); b = ((b) < 0 ? -(b) : (b)); while (b) { a = a % b; swap(a, b); } return a; } const long long inf = 2147383647; const long long mod = 1000000007; const double pi = 2 * acos(0.0); c...
10
#include <bits/stdc++.h> using namespace std; const int maxn = 3e5 + 3000; const long long mod = 1e9 + 7; int n; int a[maxn]; long long qpow(long long a, long long p) { long long ans = 1; while (p > 0) { if (p & 1) ans = ans * a % mod; a = a * a % mod; p >>= 1; } return ans; } vector<int> factor[max...
23
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n; cin >> n; int a[n + 10]; int q = n / 2; for (int i = 0; i < n; i++) { cin >> a[i]; } int g = 1, s = 0, b = 0; int tt = a[0]; vector<int> v; for (int i = 1; i < n; i++) { ...
7
#include <bits/stdc++.h> using namespace std; mt19937_64 mt(time(0)); const int MAXN = 1e5 + 10; vector<int> edges[MAXN]; pair<int, int> dp[MAXN]; vector<int> solve(int i) { queue<int> q; dp[i] = {0, 0}; q.push(i); while (!q.empty()) { int cur = q.front(); q.pop(); for (int nxt : edges[cur]) { ...
13
#include <bits/stdc++.h> using namespace std; enum { NOT_LETTER, CONSONANT, VOWEL }; string consonant_set = "BCDFGHJKLMNPQRSTVWXZbcdfghjklmnpqrstvwxz"; int letter(char c) { if ((c < 'A' || c > 'z') && !(c > 'Z' && c < 'a')) { return NOT_LETTER; } else if (consonant_set.find(c) != string::npos) { return CONS...
0
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; int n, k = 0, m = -1; n = s.length(); for (int i = 0; i < n; i++) { if (s[i] == '1') { m = i; break; } } if (m == -1) cout << "no"; else { for (int i = m + 1; i < n; i++) { if (s[i] == '0') k...
2
#include <bits/stdc++.h> #pragma GCC optimize("O3,no-stack-protector") #pragma GCC target( \ "sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native") using namespace std; struct SegTree { vector<int> t; vector<int> changed; SegTree(int len) : t(4 * len, 0), changed(4 * len, 0) {} void Push(int v, int...
15
#include <bits/stdc++.h> using namespace std; int main() { int n, k; int pos; int flag = 0; int a[105]; cin >> n >> k; for (int i = 1; i <= n; ++i) { cin >> a[i]; } int savedCandies = 0; int totalCandies = 0; for (int i = 1; i <= n; ++i) { if (a[i] + savedCandies > 8) { totalCandies +=...
1
#include <bits/stdc++.h> const int MN = 100005, MS = 1 << 18 | 7; namespace HASH { const int mod = 1e9 + 7; const int bs = 29; const int iv = 758620695; int _w[MN << 1], *w = _w + MN; void init(int N) { w[0] = 1; for (int i = 1; i < N; ++i) { w[+i] = 1ll * w[i - 1] * bs % mod; w[-i] = 1ll * w[1 - i] * iv % ...
25
#include <bits/stdc++.h> using namespace std; vector<int> v[100100]; bool fl = 0; int n, m, st[100100], k; int was[100100], in_dfs[100100]; bool cmp(int A, int B) { if (st[A] > st[B]) return 1; return 0; } int dfs(int x, int t) { if (fl == 1) return -1; was[x] = 1; in_dfs[x] = t; for (int i = 0; i < v[x].si...
10
#include <bits/stdc++.h> using namespace std; struct node { int t, next; } a[1000010]; unordered_map<int, bool> mp[1000010]; vector<int> v[1000010], have[1000010], h; stack<int> st; int head[1000010], dfn[1000010], low[1000010], from[1000010], in[1000010], n, m, cl, cnt, tot; bool inq[1000010]; inline int rd() { ...
24
#include <bits/stdc++.h> using namespace std; const int maxn = 1005; const int maxm = maxn * 25; const int inf = 0x3f3f3f3f; const int mod = 1e9 + 7; char s[1005]; bool vis[1000]; int main() { int n; while (cin >> n) { scanf("%s", s); int len = strlen(s); bool flag = true; memset(vis, 0, sizeof(vis)...
8
#include <bits/stdc++.h> using namespace std; long long fact[4004], mmi[4004]; long long B[4004][4004]; long long power(long long N, long long expo) { long long ans = 1; while (expo) { if (expo % 2) ans = ans * N % 1000000007; N = N * N % 1000000007; expo /= 2; } return ans; } int main() { fact[0]...
11
#include <bits/stdc++.h> using namespace std; int main() { int n, a[101], s = 0, k = 0; cin >> n; for (int i = 1; i <= n; i++) cin >> a[i], s += a[i]; for (int i = 1; i <= n; i++) if ((s - a[i]) % 2 == 0) k++; cout << k; }
1
#include<bits/stdc++.h> using namespace std; #define ll long long #define ln cout<<"\n" #define rep(i,s,n) for(ll i = (s);i<(n);++i) #define pc(x) __builtin_popcount(x) #define pi pair<int,int> #define pl pair<ll,ll> #define fr first #define sc second #define pb push_back #define gcd(a,b) __gcd(a,b) #define len(x) (in...
2
#include <bits/stdc++.h> using namespace std; struct actor { int l, h; int k; int id; }; bool operator<(actor a1, actor a2) { if (a1.h != a2.h) return a1.h < a2.h; if (a1.l != a2.l) return a1.l < a2.l; return a1.id < a2.id; } struct part { int a, b; int id; }; bool operator<(part p1, part p2) { if (p1...
13
#include <bits/stdc++.h> using namespace std; int main() { int a, b, c; cin >> a >> b >> c; int n = 0; string s = "No"; for (int m = 0; m < c + 1; m++) { n = (c - (b * m)) / a; int f = n * a; int se = m * b; if (f > -1 && se > -1 && f + se == c) { s = "Yes"; } } cout << s << endl...
3
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") using namespace std; template <typename T, typename TT> inline ostream &operator<<(ostream &os, const pair<T, TT> &t) { return os << t.first << " " << t.second; } template <typename T> inline ostream &operator<<(ostream &os, const vector<T> &t) { for (T i : t) ...
7
#include <bits/stdc++.h> using namespace std; const int maxn = 100007; const long long mod = 998244353; const long long ool = 1e18 + 7; const int ooi = 1e9 + 7; const int apsz = 26; const int o = 1; const int maxd = 20; int main(void) { ios::sync_with_stdio(false); cin.tie(0); long long n; cin >> n; long long...
4
#include <bits/stdc++.h> using namespace std; stringstream ss; long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; } long long lcm(long long a, long long b) { return a * b / gcd(a, b); } const int maxn = 1e6 + 5; long long d[maxn]; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);...
1
#include <bits/stdc++.h> using namespace std; int64_t modex(int64_t a, int64_t b, int64_t p) { int64_t res = 1; a %= p; while (b > 0) { if (b & 1) res = (res * a) % p; a = (a * a) % p; b >>= 1; } return res; } int dx[] = {1, 0, -1, 0, 1, -1, -1, 1}; int dy[] = {0, 1, 0, -1, 1, 1, -1, -1}; int64_t ...
8
#include <bits/stdc++.h> using namespace std; const int N = 200005; const int MOD = 1e9 + 7; long long n, k; long long a[N]; int main() { ios_base::sync_with_stdio(0); cin >> n >> k; for (int i = 1; i <= n; i++) { cin >> a[i]; } long long ans = 0; long long p = 0; for (int i = 1; i <= n; i++) { if...
5
#include <bits/stdc++.h> const int MAXN = 102, ALPHABET_SIZE = 26; char shouldOccur[MAXN]; int next[MAXN]; int prefix[MAXN][ALPHABET_SIZE]; bool cando[MAXN][MAXN]; void calc_next(char *pattern, int plen) { int i, j = 0; for (i = 2; i <= plen; ++i) { while (j > 0 && pattern[i] != pattern[j + 1]) { j = next...
13
#include <bits/stdc++.h> using namespace std; int main() { int k, r; int minimo = INT_MAX; cin >> k >> r; for (int i = 1; i <= 10; i++) { int aux = k * i; if (aux % 10 == r || !(aux % 10)) { cout << i << endl; break; } } return 0; }
0
#include <bits/stdc++.h> using namespace std; const double AE = 1e-13; bool ok(int m1, int m2, double x1, double x2) { double p1, p2; long long t1, t2; p1 = (m1 + m2) / (2 * x1); p2 = (m1 + m2) / (2 * x2); t1 = p1 = floor(p1 + AE); t2 = p2 = ceil(p2); if (t1 >= t2) return true; p1 = (m1 - m2) / (2 * x1)...
9
#include <bits/stdc++.h> using namespace std; void ga(int N, int *A) { for (int i(0); i < N; i++) scanf("%d", A + i); } struct bs { long long A[(7)]; void clr() { (memset(A, 0, sizeof(A))); } void tr(int H) { for (int i(0); i < H >> 6; i++) A[i] = -1; for (int k(H - (H & 63)); k < H; k++) ad(k); } b...
17
#include <bits/stdc++.h> using namespace std; const long long N = 2e5; vector<long long> p(N), size1(N); long long find(long long u) { if (p[u] == u) return u; return p[u] = find(p[u]); } void sets(long long a, long long b) { a = find(a); b = find(b); if (size1[a] < size1[b]) swap(a, b); p[b] = a; size1[a...
9
#include <bits/stdc++.h> using namespace std; const int mxn = 1e6 + 20; const long long inf = 1e18; const int mod = 1e9 + 7; int n, ans, bin[mxn], A[mxn], dp[mxn]; int main() { ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL); cin >> n; bin[0] = 1; for (int i = 1; i <= n; i++) { int a; ci...
14