func_code_string
stringlengths
59
71.4k
#include <bits/stdc++.h> using namespace std; const int N = (int)1e5 + 100; int dp[N]; int b[N]; int main() { int n; cin >> n; for (int i = 0; i < n; i++) cin >> b[i]; int Max = 0; vector<int> v; for (int i = 0; i < n; i++) { while (!v.empty()) { int ind = v.back(); ...
#include <bits/stdc++.h> using namespace std; const int dx[9] = {0, 1, -1, 0, 0, -1, -1, 1, 1}; const int dy[9] = {0, 0, 0, -1, 1, -1, 1, -1, 1}; const double pi = acos(-1.0); const int N = 110; long long n, m, ans; void input_data() { cin >> n >> m; } void get_ans() { if (n <= m) { ans = n; ...
#include <bits/stdc++.h> using namespace std; template <typename T> void solve() { int n, x; cin >> n >> x; vector<int> cs(n); for (auto& c : cs) { cin >> c; } int c_sum = accumulate(cs.begin(), cs.end(), 0); vector<vector<T>> mass(n + 1, vector<T>(c_sum + 1, 0)); mass[0][0] ...
#include <bits/stdc++.h> using namespace std; const int MAXN = 210; long long gcd(long long a, long long b) { if (b == 0) return a; return gcd(b, a % b); } long long lcm(long long a, long long b) { return a / gcd(a, b) * b; } long long LCM = 1, limit, X; int n, a[MAXN]; bool inCir[MAXN]; int m...
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5, aa[8] = {-1, 0, 1, -1, 2, -1, -1, -1}, bb[8] = {-1, -1, -1, 2, -1, 1, 0, -1}; int T, n, i, j; long long l, r, m, a[N], b[N], c[N], x, y, z, mn[8], u[4], d[4]; inline bool ckk(long long p, long long q, long long r) { for (x = ...
#include <bits/stdc++.h> using namespace std; struct SegmentTree { int n; struct node { long long add, mn; node() {} node(long long v) : mn(v), add(0) {} }; vector<node> tree; void push(int id, int l, int r) { if (tree[id].add != 0) { int m = (l + r) >> 1; ...
#include <bits/stdc++.h> #pragma GCC optimize( O3 ) using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int t; cin >> t; while (t--) { int n; cin >> n; int arr[n]; for (int i = 0; i < n; i++) cin >> arr[i]; if (n ...
#include <bits/stdc++.h> using namespace std; long long cal(long long x, long long a) { long long y = a, ans = 0, cnt = 1; while (x / (long long)(pow(a, cnt)) != 0) { ans += x / (long long)(pow(a, cnt)); cnt++; } return ans; } signed main() { long long n, b, mx = LLONG_MAX; v...
#include <bits/stdc++.h> const double PI = 2.0 * acos(0.0); const double EPS = 1e-9; using namespace std; int dr[] = {-1, 0, 1, 0, 1, 1, -1, -1}; int dc[] = {0, 1, 0, -1, -1, 1, -1, 1}; int V, E; int T; int N, M, K; string S; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); ...
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 50; const long long MAXN = 1e18 + 10; const int MAX = 1e5 + 10; const long long mod = 1e9 + 7; const int inf = 0x3f3f3f3f; const long long INF = 0x3f3f3f3f3f3f3f3f; const double eps = 1e-7; inline void solve() { int n, w; scanf(...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); int n; cin >> n; cin.get(); string s; getline(cin, s); vector<int> pref(n); for (int i = 0; i < n; ++i) { if (i != 0) pref[i] = pref[i - 1]; pref[i] += s[i] == ( ? +1 : -...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); ; long long i, j, k, l, r, m, n, o, t; cin >> n; cin >> l >> r; char str[100001]; cin >> str; long long len = strlen(str); l--; r--; if (str[l] == str[r]) { cout << 0 << endl; ...
#include <bits/stdc++.h> using namespace std; vector<int> vec; int result[50000]; int MIN(int i, int j) { int ans = 1e9; for (int a = i; a <= j; a++) { ans = min(ans, vec[a]); } return ans; } int main() { int n, m; scanf( %d %d , &n, &m); for (int i = 0; i < (n); i++) vec.p...
#include <bits/stdc++.h> using namespace std; const long long mod = 1000000007; const int N = 1e5 + 9; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ; int x; cin >> x; long long ans = 0, c = 0; int y[x]; for (int i = 0; i < x; i++) cin >> y[i];...
#include <bits/stdc++.h> using namespace std; string s[6]; vector<string> res; void draw(vector<string> &w, int x, int y, int dx, int dy, string s) { for (int k = 0; k < s.size(); k++, x += dx, y += dy) { w[x][y] = s[k]; } return; } int main() { for (int i = 0; i < 6; i++) cin >> s[i];...
#include <bits/stdc++.h> using namespace std; const int MX = 102, md = 1000000007; int n, k, i, j, e, c[MX][MX], f[MX][MX * MX]; long long m, p[MX], q[MX]; bool ifq; long long pw(long long a, long long b) { if (b == 0) return 1LL; if (b & 1) return (a * pw(a, b - 1)) % md; long long x = pw(a, b ...
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const long long INFF = 0x3f3f3f3f3f3f3f3f; const double pi = acos(-1.0); const double eps = 1e-9; const long long mod = 1e9 + 7; int read() { int x = 0, f = 1; char ch = getchar(); while (ch< 0 | ch> 9 ) { if (ch...
#include <bits/stdc++.h> using namespace std; int tr[400], ar[400]; vector<pair<int, int> > vv; int main() { int n; cin >> n; for (int i = 0; i < n; i++) cin >> ar[i]; for (int i = 0; i < n; i++) cin >> tr[i]; for (int i = 0; i < n; i++) { if (tr[i] == ar[i]) continue; int j; ...
#include <bits/stdc++.h> using namespace std; const long long inf = 1e15 + 9; const long long N = 1e5 + 5; long long A[N], n, k, B[N]; map<long long, long long> mm; void solve() { long long i, j, x = 0, y = 1, m; cin >> n; for (i = 0; i < n; i++) { cin >> x >> y; mm[x] = max(mm[x], y...
#include <bits/stdc++.h> using namespace std; struct ji { int nex, to; } edge[100005 << 1]; set<pair<int, int> > s[100005]; set<pair<int, int> >::iterator it; priority_queue<pair<int, int> > q; pair<int, int> ans[100005]; int E, n, r, x, y, z, cnt, head[100005], sz[100005], mx[100005], f[100005], ...
#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> v; for (long long int i = 0; i < n; i++) { long long int x; cin >> x; v.push_back(x); } l...
#include <bits/stdc++.h> using namespace std; long long gcd(long long a, long long b) { while (b) { a %= b; swap(a, b); } return a; } long long lcm(const long long &a, const long long &b) { return (a / gcd(a, b)) * b; } bool check(long long a) { int k = 0; while (a > 0) {...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); int n, m; cin >> n >> m; vector<int> v[n + 1]; for (int i = 0; i < m; i++) { int a, b; cin >> a >> b; v[a].push_back(b); } int cnt[n + 1]; for (int o = 1; o <= n; o++) { fo...
#include <bits/stdc++.h> using namespace std; void __print(int x) { cerr << x; } void __print(long x) { cerr << x; } void __print(long long x) { cerr << x; } void __print(unsigned x) { cerr << x; } void __print(unsigned long x) { cerr << x; } void __print(unsigned long long x) { cerr << x; } void __prin...
#include <bits/stdc++.h> using namespace std; const int MAXN = 5e4 + 10; int b[MAXN], n, a[MAXN]; int ID(int x) { x = x % n; if (x < 0) x += n; return x; } int main(void) { scanf( %d , &n); for (int i = 0; i < n; ++i) scanf( %d , a + i); vector<pair<int, int> > foo; for (int i = ...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int ex[n], e[n]; int temp = n; int i = 0; while (temp--) { cin >> ex[i] >> e[i]; i++; } int sum = e[0], m = e[0]; for (int j = 1; j < n; j++) { sum = sum - ex[j] + e[j]; if (sum > ...
#include <bits/stdc++.h> using namespace std; const int N = 300050; const int L = 19; const long long inf = 1e15; vector<int> E[N]; int par[N][L], dep[N]; void DFS(int u, int p) { dep[u] = dep[p] + 1; par[u][0] = p; for (int i = 1; i < L; i++) par[u][i] = par[par[u][i - 1]][i - 1]; for (in...
#include <bits/stdc++.h> using namespace std; const double eps = 1e-9; const int MAXB = 10; const int MAXN = 1025; vector<int> distGroup[MAXN]; int hasDist[MAXN]; int predecessor[MAXN]; vector<int> output; set<int> centers; string result, resultm; int maxDist[MAXN]; int minDist[MAXN]; vector<s...
#include <bits/stdc++.h> using namespace std; long long ans = 0; string s; int main() { ios_base::sync_with_stdio(false); cin >> s; int id = -1; for (int i = 0; i < (int)s.length(); i++) { for (int j = 1; j <= 4 && i - 2 * j >= 0; j++) if (s[i] == s[i - j] && s[i - j] == s[i - 2 * ...
#include <bits/stdc++.h> using namespace std; int main() { char ch; int state = 0; while ((ch = cin.get()) != EOF) switch (state) { case 0: if (isdigit(ch)) { cout << ch; state = 1; } if (ch == , ) { cout << ch; state...
#include <bits/stdc++.h> using namespace std; const int INF = 1e9; const int MN = 105; bool mark[500][500]; char s[MN]; int dis[500][500]; int ask(pair<int, int> now) { int res = INF; if (mark[now.first][now.second]) res = min(res, dis[now.first][now.second]); if (mark[now.first - 1][now.secon...
#include <bits/stdc++.h> using namespace std; const int MAXN = 5e3 + 5; const int inf = 1e9 + 7; vector<pair<int, int> > adj[MAXN]; int dp[MAXN][MAXN], tr[MAXN][MAXN]; int n, m, t; int solve(int u, int len) { if (u == n and !len) return 0; if (!len) return inf; if (dp[u][len] != -1) return dp[...
#include <bits/stdc++.h> int main() { int i, n, x = 2; scanf( %d , &n); for (i = 0; i < n - 1; i++) { printf( %d , x); x += (2 + i); if (x > n) x -= n; } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { unsigned long long N, x, y, input, r_code = 0; cin >> N >> x >> y; vector<unsigned long long> days; for (unsigned long long i = 0; i < N; i++) { cin >> input; days.push_back(input); } unsigned long long temp1; for (un...
#include <bits/stdc++.h> using namespace std; int lim = 1e6; int inf = 1e8; void err(istream_iterator<string> it) { cerr << endl; } template <typename T, typename... Args> void err(istream_iterator<string> it, T a, Args... args) { cerr << *it << = << a << t ; err(++it, args...); } template...
#include <bits/stdc++.h> using namespace std; void solve() { string s; cin >> s; map<char, long long> mp; for (long long i = 0; i < s.size(); i++) mp[s[i]]++; long long c = 0; for (auto it = mp.begin(); it != mp.end(); it++) { if (it->second & 1) c++; } if (c <= 1) cout <...
#include <bits/stdc++.h> using namespace std; const int N = 300001; set<pair<long long int, long long int> >* T[N]; int A[N]; int S[N]; char s[N]; vector<int> adj[N]; long long int MOD1 = 1000000007LL; long long int MOD2 = 1000000009LL; void dfs(int st, int p = -1, long long int hash1 = 0LL, ...
#include <bits/stdc++.h> using namespace std; long long int solve(string &s, vector<vector<long long int> > &pre, vector<vector<long long int> > &dp, long long int st, long long int en, long long int a, long long int b) { if (st > en) { return 0; } if (d...
#include <bits/stdc++.h> using namespace std; const long long MAXN = 1e5 + 1; const long long INF = 1e9 + 1; const long long MOD = 1e9; const long long BITS = 64; const long double EPS = 1e-12; void bye() { cout << n ; exit(0); } signed main() { ios_base::sync_with_stdio(false); cin....
#include <bits/stdc++.h> using namespace std; const int nmax = 110; int x[nmax]; char g[nmax][nmax]; int pos[nmax * nmax][2]; int main() { int a, b, c, d; scanf( %d%d%d%d , &a, &b, &c, &d); int q; scanf( %d , &q); for (int i = 0; i < q; ++i) { scanf( %d , &x[i]); } bool swa...
#include <bits/stdc++.h> const int INF = 0x3f3f3f3f; const long long int INFLL = 0x3f3f3f3f3f3f3f3fll; long long int getint() { long long int ret = 0; bool f = 0; char c; while ((c = getchar()) < 0 || c > 9 ) if (c == - ) f ^= 1; while (c >= 0 && c <= 9 ) { ret = ret * 10 + ...
#include <bits/stdc++.h> using namespace std; const int N = 109; const int INF = 1e9; char zbs[5] = { R , G , B , Y , W }; pair<int, int> a[N]; int main() { int n, ans = 11; cin >> n; for (int i = 0; i < int(n); ++i) { char t1, t2; cin >> t1 >> t2; a[i].second = int(t2 - 1...
#include <bits/stdc++.h> using namespace std; int n, m; vector<int> g[100001]; bool is_centroid[100001]; int centroid_parent[100001]; int mn[100001]; int sz[100001]; int level[100001]; int centroid_root; map<pair<int, int>, int> dist; void dfs(int nd, int p, int c) { sz[nd] = 1; if (p == c...
#include <bits/stdc++.h> using namespace std; const int maxn = 100010; vector<int> v[5 * maxn]; int t[5 * maxn]; int comp[5 * maxn]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n = 0, m = 0, x = 0, y = 0; cin >> n >> m; for (int i = 0; i < m; ++i) { cin >> x >...
#include <bits/stdc++.h> using namespace std; const int MAXN = 3005, MAXM = 55; const double inf = 1e9 + 5; vector<int> graph[MAXN]; double c[MAXN][MAXN]; int f[MAXN][MAXN]; priority_queue<pair<double, int> > q; double dist[MAXN]; int last[MAXN]; int n, Q; int upperBound[MAXM], lowerBound[MAXM]; ...
#include <bits/stdc++.h> using namespace std; int dp[513]; int n, m; int main() { scanf( %d %d , &n, &m); for (int i = 0; i < n; ++i) { scanf( %d , &dp[i + 1]); } double best = 0; for (int i = 0; i < m; ++i) { int x, y, z; scanf( %d %d %d , &x, &y, &z); best = max(bes...
/* ⣿⣿⣿⣿⣿⣿⡷⣯⢿⣿⣷⣻⢯⣿⡽⣻⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣇⠸⣿⣿⣆⠹⣿⣿⢾⣟⣯⣿⣿⣿⣿⣿⣿⣽⣻⣿⣿⣿⣿⣿⣿⣿ ⣿⣿⣿⣿⣿⣿⣻⣽⡿⣿⣎⠙⣿⣞⣷⡌⢻⣟⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣷⣿⣿⣿⣿⣿⣿⡄⠹⣿⣿⡆⠻⣿⣟⣯⡿⣽⡿⣿⣿⣿⣿⣽⡷⣯⣿⣿⣿⣿⣿⣿ ⣿⣿⣿⣿⣿⣿⣟⣷⣿⣿⣿⡀⠹⣟⣾⣟⣆⠹⣯⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡇⢠⡘⣿⣿⡄⠉⢿⣿⣽⡷⣿⣻⣿⣿⣿⣿⡝⣷⣯⢿⣿⣿⣿⣿ ⣿⣿⣿⣿⣿⣿⣯⢿⣾⢿⣿⡄⢄⠘⢿⣞⡿⣧⡈⢷⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡇⢸⣧⠘⣿⣷⠈⣦⠙⢿⣽⣷⣻⣽⣿⣿⣿⣿⣌⢿⣯⢿⣿⣿⣿ ⣿⣿⣿⣿⣿⣿⣟⣯⣿⢿⣿⡆⢸⡷⡈⢻⡽⣷⡷⡄⠻⣽⣿⣿⡿⣿⣿⣿⣿⣿⣿⣷⣿⣿⣿⣿⣏⢰⣯⢷⠈⣿⡆⢹⢷⡌⠻⡾⢋⣱⣯⣿⣿⣿⣿⡆⢻⡿⣿...
#include <bits/stdc++.h> const int N = int(1e5 + 3); using namespace std; bool is_prime(int n) { if (n == 2) return true; if (n % 2 == 0) return false; for (int i = 2; i * i <= n; ++i) if (n % i == 0) return false; return true; } void solve() { long long n; cin >> n; long lon...
#include <bits/stdc++.h> using namespace std; vector<int> adj[1005]; int w[1005]; int main() { int n, k; cin >> n >> k; if (n - k - 1 < k) return cout << -1, 0; cout << n * k << endl; for (int i = 1; i <= n; i++) { int t = w[i]; for (int j = i + 1; j <= n; j++) { if (w[i]...
#include <bits/stdc++.h> using namespace std; const int INF = (int)1e9; int main() { int n, d, l; vector<int> a; cin >> n >> d >> l; int a1 = 0; for (int i = 0; i < n - 1; i++) { if (d < 1) a1 = 1; else if (d >= l) a1 = l; else a1 = d + 1; a.push...
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n, m; cin >> n >> m; vector<int> v(n), rank(n + 1), v1(m); for (int i = 0; i < n; i++) { cin >> v[i]; rank[v[i]] = i + 1; } for (int i = 0; i < m; i++) cin >>...
#include <bits/stdc++.h> using namespace std; long long int maxi = 0; long long int nc2(long long int n) { return (n * (n - 1)) / 2; } int m[367]; int f[367]; int main() { int n, g; cin >> n; while (n--) { char c; int l, r; cin >> c >> l >> r; if (c == M ) { for ...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int a[n + 1]; for (int i = 1; i <= n; i++) { cin >> a[i]; } long long int f[n + 1]; f[0] = 0; for (int i = 1; i < n; i++) { f[i] = f[i - 1] ^ i; } long long sum = 0; for (int i = 1; i ...
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; long long res = 0; for (size_t i = 0; i < s.size(); ++i) { int c = s[i] - 0 ; int pc = (i > 0 ? s[i - 1] - 0 : 0); if (c % 4 == 0) { ++res; } if ((pc * 10 + c) % 4 == 0) { ...
#include <bits/stdc++.h> using namespace std; int nxt() { int res; scanf( %d , &res); return res; } inline void solve() { int n = nxt(); int k = nxt(); int d = nxt(); vector<vector<int> > ans; ans.push_back(vector<int>(d, 0)); while (int(ans.size()) < n) { vector<int> q...
#include <bits/stdc++.h> using namespace std; long long dp[5005][5005]; long long solve(long long x, long long y) { if (x == 0 || y == 0) return 1; if (dp[x][y] == 0) dp[x][y] = (solve(x - 1, y - 1) * y + solve(x - 1, y)) % 998244353; return dp[x][y]; } int main() { long long n, m, k; ...
#include <bits/stdc++.h> using namespace std; const int MOD = 1000000007; const double PI = 3.141592653528; const long long INF = 10000000000000000; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int t; cin >> t; while (t--) { int n; cin >> n; vector<pair<pair<int...
#include <bits/stdc++.h> using namespace std; int main() { int n, m, x1, y1, x2, y2, x, y; scanf( %d%d%d%d%d%d , &n, &m, &x1, &y1, &x2, &y2); x = abs(x1 - x2); y = abs(y1 - y2); if (x + y >= 7 || y >= 5 || x >= 5) printf( Second n ); else printf( First n ); return 0; }
#include <bits/stdc++.h> using namespace std; int main() { vector<int> num; int n; cin >> n; int k = -1, tmp; while (n > 0) { tmp = n % 10; num.push_back(tmp); if (tmp > k) k = tmp; n /= 10; } cout << k << endl; bool flag = true; bool main = true; whil...
#include <bits/stdc++.h> using namespace std; const int inf = 0x3f3f3f3f; const double eps = 1e-6; const double pi = acos(-1.0); int T[100005 << 2]; void update(int n, int L, int R, int p, int a) { if (L == R) { T[n] = a; return; } if (p > (L + R) / 2) update(n * 2 + 1, (L + R)...
#include <bits/stdc++.h> using namespace std; template <class T> void _R(T &x) { cin >> x; } void _R(int &x) { scanf( %d , &x); } void _R(int64_t &x) { scanf( %lld , &x); } void _R(double &x) { scanf( %lf , &x); } void _R(char &x) { scanf( %c , &x); } void _R(char *x) { scanf( %s , x); } void R...
#include <bits/stdc++.h> using namespace std; const int MAXN = 100005; int arr[2 * MAXN]; int main() { int n; scanf( %d , &n); for (int i = 1; i <= 2 * n; i++) scanf( %d , arr + i); sort(arr + 1, arr + 2 * n + 1); long long best = LONG_LONG_MAX; for (int start_x = 1; start_x <= n + 1; st...
#include <bits/stdc++.h> using namespace std; int dx[] = {0, 0, 1, -1, -1, -1, 1, 1}; int dy[] = {1, -1, 0, 0, -1, 1, 1, -1}; template <class T> inline T biton(T n, T pos) { return n | ((T)1 << pos); } template <class T> inline T bitoff(T n, T pos) { return n & ~((T)1 << pos); } template <cl...
#include <bits/stdc++.h> using namespace std; const int mod = 1000000007; const int INF = 1000000000; int s(int first) { int r = 0; while (first) { r += first % 10; first /= 10; } return r; } int main() { long long m; cin >> m; long long b = 1000 * 1000 * 1000; lo...
#include <bits/stdc++.h> using namespace std; int x[2000], y[2000], c[2000]; vector<int> poss; multiset<int> xx[2000]; vector<pair<int, int> > events; map<pair<int, int>, int> M; long long int sum = 0, ans = 0; int update(int e, int m) { if (e < 0) return 0; auto it = M.upper_bound(make_pair(e, ...
#include <bits/stdc++.h> using namespace std; long long xpow(long long a, long long b) { if (!b) return 1; if (b == 1) return a; if (b & 1) { return ((a * xpow(a, b - 1))); } else { long long p = xpow(a, b / 2); return ((p * p)); } } int32_t main() { ios_base::sync_with...
#include <bits/stdc++.h> using namespace std; long long a[5111], y, yy; int lmax[5111], cnt[5111], llmax; int N, i, j, k; int main() { scanf( %d , &N); for (i = 1; i <= N; i++) scanf( %I64d , &a[i]); for (llmax = 0, i = 1; i <= N; i++) { lmax[i] = 0; cnt[i] = 0; y = a[i]; w...
#include <bits/stdc++.h> using namespace std; int v[200001], i, n, poz; bool cmp(int a, int b) { return a < b; } int main() { cin >> n; for (i = 1; i <= n; i++) cin >> v[i]; sort(v + 1, v + n + 1, cmp); poz = 1; for (i = 1; i <= n; i++) { if (v[i] >= poz) poz++; } cout << poz -...
#include <bits/stdc++.h> using namespace std; void dropAny(const vector<int> &a, int offset, vector<bool> &used) { vector<int> next(used.size(), a.size()); for (int i = int(a.size()) - 1; i >= offset; --i) { next[a[i]] = i; } int best = -1; for (int i = 0; i < (int)used.size(); ++i) { ...
#include <bits/stdc++.h> #pragma GCC optimize( Ofast ) #pragma GCC optimize( unroll-loops ) #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native ) using namespace std; const int MAX = 1e3 + 5; const int MOD = 1e9 + 7; const int64_t INF = INT_MAX; const int64_t _INF = INT_MIN; in...
#include <bits/stdc++.h> using namespace std; const long long mod = 1000000007; long long fac[200001]; long long inv[200001]; long long modexp(long long b, long long e) { long long ans = 1; while (e > 0) { if (e & 1) { ans = (ans * b) % mod; } b = (b * b) % mod; e >>= 1...
#include <bits/stdc++.h> using namespace std; long long n, i, a, b, x, y, o, z, p, q, sum, c; int main() { cin >> n; vector<long long> v; for (i = 0; i < n; i++) { cin >> x; if (x == 0) o++; else v.push_back(x); } sort(v.begin(), v.end()); a = 0; b = v...
#include <bits/stdc++.h> using namespace std; const int N = 4 * 1000 * 100 + 10; int n, c[N], st[N], en[N], who[N], TM; vector<int> adj[N]; void dfs(int root, int par = 0) { st[root] = TM++; who[st[root]] = root; for (auto u : adj[root]) if (u ^ par) dfs(u, root); en[root] = TM; } st...
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; int num = 0, num1, num2; for (int i = 0; i < s.size(); i++) { if (s[i] == A ) { num1 = 0; for (int j = 0; j < i; j++) if (s[j] == Q ) num1++; num2 = 0; for (int j = i + 1;...
#include <bits/stdc++.h> using namespace std; using ll = long long; using ull = unsigned long long; using ld = long double; const ll llinf = (1ll << 61) - 1; const double eps = 1e-6, ldeps = 1e-9; template <class C, size_t Y> struct tp { void operator()(ostream &os, const C &t) { tp<C, Y - 1>(...
#include <bits/stdc++.h> using namespace std; long long int o[100001]; long long int sum[100001]; long long int dp[100001][2]; long long int dp1[100001][2]; long long int on[100001]; long long int a[100001]; int main() { int n; scanf( %d , &n); for (int i = 0; i < n - 1; i++) { scanf( ...
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 5; int a[maxn]; int n, x, k; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> x >> k; for (int i = 0; i < n; i++) cin >> a[i]; sort(a, a + n); long long ans = 0; for (int i = 0; i < n...
#include<bits/stdc++.h> using namespace std; int t,f,i,j,p,q,x,y,dx[128],dy[128]; char s[5008]; int main() { for(dx[ L ]=-(dx[ R ]=1),dy[ D ]=-(dy[ U ]=1),scanf( %d ,&t); t--; f?0:printf( 0 0 n )) for(scanf( %s ,s),f=i=p=q=0; s[i]; x||y?++i: (printf( %d %d n ,p,q)...
#include <bits/stdc++.h> using namespace std; const double pi = acos(-1.0); int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout << fixed; int a1, a2; cin >> a1 >> a2; int minutes = 0; while (a1 > 0 && a2 > 0) { if (a1 == 1 && a2 == 1) { break; } ...
#include <bits/stdc++.h> using namespace std; const int maxn = 300 * 1000 + 100; const long long mod = 1e9 + 7; const long long inf = 2 * 1e18; int n, m, k; int ans = -1; char c[maxn]; vector<int> adj[maxn]; int cnt[30][maxn]; int d_in[maxn]; bool mark[maxn], mark1[maxn]; void dfs(int v) { i...
#include <bits/stdc++.h> bool is_prime(int n) { if (n < 2) { return false; } for (int d = 2; d * d <= n; d++) { if (n % d == 0) { return false; } } return true; } int main() { int n; std::cin >> n; int m = n, cross = 0; while (!is_prime(m + cross)) { ...
#include <bits/stdc++.h> using namespace std; const int oo = 0x3f3f3f3f; const long long OO = 1LL << 61; const long long MOD = 10007; const int maxn = 100000 + 5; long long dp[(1 << (16)) + 6]; int ans[20], g[20], mark[20], full; int main() { int n, m, a, b, f; long long y; while (scanf( %d ...
#include <bits/stdc++.h> using namespace std; int s[105]; int main() { int n, x; while (cin >> n >> x) { for (int i = 0; i < n; i++) { cin >> s[i]; } sort(s, s + n); int index = lower_bound(s, s + n, x) - s; if (s[index] == x) { cout << 1 + x - index << endl; ...
#include <bits/stdc++.h> using namespace std; int a[111111]; int b[111111]; int main() { int n, i, j; vector<pair<int, int> > v; scanf( %d , &n); a[0] = a[1] = 1; for (i = 2; i <= n; i++) { if (a[i] == 0) { for (j = i * 2; j <= n; j += i) a[j] = 1; } } for (i = n ...
#include <bits/stdc++.h> using namespace std; const double pi = acos((double)(-1)); const int maxn = 100010; const int mod = 1e9 + 7; int moven2[10][5] = {{1, 0, 0}, {-1, 0, 0}, {0, 1, 0}, {0, -1, 0}, {0, 0, 1}, {0, 0, -1}}; int moven1[10][5] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}}; ...
#include <bits/stdc++.h> using namespace std; int main() { int n, m; int res = 0, cur = 0, tmp; cin >> n >> m; for (int i = 0; i < n; i++) { cin >> tmp; res = (cur + tmp) / m; cur = (cur + tmp) % m; cout << res << ; } }
#include <bits/stdc++.h> int main() { int n, count = 0, i = 0, ans, flag = 1; char s[201]; scanf( %d %s , &n, s); while (s[i] != 0 ) { if (s[i] == x ) count++; i++; } if (n / 2 > count) { ans = n / 2 - count; flag = 0; } else ans = count - n / 2; printf...
#include <bits/stdc++.h> using namespace std; const long long inf = 1e9 + 7; const int maxn = 5e1 + 10; const int maxq = 1e3 + 10; const int alf = 26; const long long dlm = 1e9 + 7; const int del = 998244353; const int eps = 1e-7; char t[maxn][maxn]; char g[maxn][maxn]; char t2[maxn][maxn]; int ...
#include <bits/stdc++.h> using namespace std; int ntest = 0, test = 0; inline void init(); inline void run(); inline void stop() { ntest = test - 1; } int main() { init(); while (++test <= ntest) { run(); } return 0; } const int INF = (int)1E9 + 5; const double EPS = 1E-11; con...
#include <bits/stdc++.h> using namespace std; int n, qc; int a[100005]; int freq[100005], ord[100005], inv[100005]; int cnt[100005] = {}, small[100005] = {}; int from[100005], to[100005]; const int ROOT = 320; const int BIG_COUNT = 100; const int SMALL = (100000 + BIG_COUNT - 1) / BIG_COUNT; inline ...
#include <bits/stdc++.h> using namespace std; struct ring { int c1; int c2; int r1; int r2; }; int contour(struct ring a, struct ring b, double dist) { int cnt = 0; if (dist >= a.r2 + b.r2 || dist <= b.r1 - a.r2 || dist <= a.r2 - b.r2) cnt++; if (dist >= a.r1 + b.r2 || dist <= b.r1 -...
#include <bits/stdc++.h> using namespace std; inline int read() { int x = 0; char ch = getchar(); bool positive = 1; for (; !isdigit(ch); ch = getchar()) if (ch == - ) positive = 0; for (; isdigit(ch); ch = getchar()) x = x * 10 + ch - 0 ; return positive ? x : -x; } inline void ...
#include <bits/stdc++.h> using namespace std; const int INF = 1e9; int n, m; double dp_mai[155], dp_cul[155]; int d_mai[155], d_cul[155]; bool adj[155][155], used[155]; void dijk(int source, int *d, double *dp) { fill(d + 1, d + n + 1, INF); memset(used, 0, sizeof(used)); d[source] = 0; dp...
#include <bits/stdc++.h> using namespace std; using pii = pair<int, int>; using ll = long long; using pll = pair<ll, ll>; template <class T> ostream &operator<<(ostream &os, const vector<T> &v) { for (const T &t : v) os << t << t; return os << endl; } template <class T> istream &operator>>(...
#include <bits/stdc++.h> using namespace std; bool cmp(const pair<int, int>& p1, const pair<int, int>& p2) { return p1.first < p2.first; } struct node { int a; int b; }; bool operator<(const node& x, const node& y) { return x.a > y.a; } int sol(int x) { int ans = 0; if (x == 0) return ...
#include <bits/stdc++.h> inline int min(const int &first, const int &second) { return (((second - first) >> (32 - 1)) & (first ^ second)) ^ first; } inline int max(const int &first, const int &second) { return (((second - first) >> (32 - 1)) & (first ^ second)) ^ second; } inline long long min(const l...
#include <bits/stdc++.h> #pragma GCC optimize( Ofast ) #pragma GCC optimize( unroll-loops ) #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native ) using namespace std; using ll = long long; using ull = unsigned long long; using db = double; using ld = long double; template <type...
#include <bits/stdc++.h> using namespace std; int p[100009], a[100009], pos[100009], m, n, ri[100009], le[100009]; set<pair<int, int>> st; inline bool cmp(const int& A, const int& B) { return p[A] < p[B]; } int getdis(int x, int y) { if (x == y) return 1000000000; int d = (p[y] - p[x] + m) % m; if...
#include <bits/stdc++.h> using namespace std; double A[200009]; double B[200009]; int main() { int N, i; cin >> N; for (i = 0; i < N; i++) { cin >> A[i]; } B[0] = A[0]; for (i = 1; i < N; i++) { B[i] = (B[i - 1] + 1) * A[i]; } double sum = 0; for (i = 0; i < N; i+...
#include <bits/stdc++.h> using namespace std; long long int powm(long long int a, int b, int n) { long long int rm = 1; while (b) { if (b % 2) { rm = (rm * a) % n; } a = (a * a) % n; b /= 2; } return rm; } int nxt[int(1e5 + 1000)] = {0}, g, r, tq[int(1e5 + 1000)];...