output
stringlengths
52
181k
instruction
stringlengths
296
182k
#include <bits/stdc++.h> using namespace std; const int maxn = 1e6 + 7; const int rr = 2333; const int mod = 999998639; long long pre[maxn], poww[maxn]; char str[maxn]; string s, s1, s2, ans = ""; long long hashp(long long l, long long r) { return (pre[r] - pre[l - 1] * poww[r - l + 1] % mod + mod) % mod; } int main(...
### Prompt Please provide a cpp coded solution to the problem described below: Asterix, Obelix and their temporary buddies Suffix and Prefix has finally found the Harmony temple. However, its doors were firmly locked and even Obelix had no luck opening them. A little later they found a string s, carved on a rock bel...
#include <bits/stdc++.h> using namespace std; char pattern[1000005]; int p[1000005]; void preprocessing(char pattern[]) { int size = strlen(pattern + 1); p[1] = 0; int k = 0; for (int i = 2; i <= size; i++) { while (k > 0 && pattern[i] != pattern[k + 1]) { k = p[k]; } if (pattern[i] == pattern...
### Prompt Construct a CPP code solution to the problem outlined: Asterix, Obelix and their temporary buddies Suffix and Prefix has finally found the Harmony temple. However, its doors were firmly locked and even Obelix had no luck opening them. A little later they found a string s, carved on a rock below the temple...
#include <bits/stdc++.h> int n, tlen, ans; int nxt[1000020], rnxt[1000020]; char t[1000020]; bool yes, vis[1000020]; void getnxt() { int j = 0; nxt[1] = 0; tlen = strlen(t + 1); for (int i = 2; i <= tlen; i++) { while (j && t[i] != t[j + 1]) j = nxt[j]; if (t[i] == t[j + 1]) j++; nxt[i] = j; } } v...
### Prompt Create a solution in Cpp for the following problem: Asterix, Obelix and their temporary buddies Suffix and Prefix has finally found the Harmony temple. However, its doors were firmly locked and even Obelix had no luck opening them. A little later they found a string s, carved on a rock below the temple's ...
#include <bits/stdc++.h> using namespace std; const int maxn = 1e6 + 10; const int INF = 0x3f3f3f3f; void read(int &val) { int x = 0; int bz = 1; char c; for (c = getchar(); (c < '0' || c > '9') && c != '-'; c = getchar()) ; if (c == '-') { bz = -1; c = getchar(); } for (; c >= '0' && c <= '9'...
### Prompt Please formulate a cpp solution to the following problem: Asterix, Obelix and their temporary buddies Suffix and Prefix has finally found the Harmony temple. However, its doors were firmly locked and even Obelix had no luck opening them. A little later they found a string s, carved on a rock below the tem...
#include <bits/stdc++.h> using namespace std; const int N = 1000002; int check[N]; vector<int> prefix(int n, string pattern) { int index = 0; vector<int> lps(n); for (int i = 1; i < n;) { if (pattern[index] == pattern[i]) { lps[i] = index + 1; i++; index++; } else { if (index) ...
### Prompt Please create a solution in CPP to the following problem: Asterix, Obelix and their temporary buddies Suffix and Prefix has finally found the Harmony temple. However, its doors were firmly locked and even Obelix had no luck opening them. A little later they found a string s, carved on a rock below the tem...
#include <bits/stdc++.h> using namespace std; const char IO_MODE = 0; inline long long ReadInt() { long long x = 0, f = 1; char ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); } ...
### Prompt In Cpp, your task is to solve the following problem: Asterix, Obelix and their temporary buddies Suffix and Prefix has finally found the Harmony temple. However, its doors were firmly locked and even Obelix had no luck opening them. A little later they found a string s, carved on a rock below the temple's...
#include <bits/stdc++.h> using namespace std; int z[1000001]; void z_algo(string s) { z[0] = (int)s.length(); int i; int l, r, k; l = 0, r = 0; int n = s.length(); for (i = 1; i < n; i++) { if (r < i) { l = i; r = i; while (r < n && s[r - l] == s[r]) r++; z[i] = r - l; r--;...
### Prompt Construct a cpp code solution to the problem outlined: Asterix, Obelix and their temporary buddies Suffix and Prefix has finally found the Harmony temple. However, its doors were firmly locked and even Obelix had no luck opening them. A little later they found a string s, carved on a rock below the temple...
#include <bits/stdc++.h> using namespace std; char s[1000005]; int len, b[1000005]; void preprocess() { int i = 0, j = -1; b[0] = -1; while (i < len) { while (j >= 0 && s[j] != s[i]) j = b[j]; i++; j++; b[i] = j; } } bool kmp(int i, int l, int len_suffix) { int j = 0; while (i < l) { whi...
### Prompt Your challenge is to write a Cpp solution to the following problem: Asterix, Obelix and their temporary buddies Suffix and Prefix has finally found the Harmony temple. However, its doors were firmly locked and even Obelix had no luck opening them. A little later they found a string s, carved on a rock bel...
#include <bits/stdc++.h> using namespace std; int main(void) { int *pi, cnt = 0; char *s = new char[1000001]; cin >> s; int len = strlen(s); pi = new int[len]; memset(pi, 0, sizeof(pi)); for (int i = 1; i < len; i++) { int j = pi[i - 1]; while (j > 0 && s[i] != s[j]) j = pi[j - 1]; if (s[i] ==...
### Prompt Generate a cpp solution to the following problem: Asterix, Obelix and their temporary buddies Suffix and Prefix has finally found the Harmony temple. However, its doors were firmly locked and even Obelix had no luck opening them. A little later they found a string s, carved on a rock below the temple's ga...
#include <bits/stdc++.h> using namespace std; void z_function(string const& s, int* z) { int n = (int)s.length(); for (int i = 1, l = 0, r = 0; i < n; ++i) { if (i <= r) z[i] = min(r - i + 1, z[i - l]); while (i + z[i] < n && s[z[i]] == s[i + z[i]]) ++z[i]; if (i + z[i] - 1 > r) l = i, r = i + z[i] - 1;...
### Prompt Generate a CPP solution to the following problem: Asterix, Obelix and their temporary buddies Suffix and Prefix has finally found the Harmony temple. However, its doors were firmly locked and even Obelix had no luck opening them. A little later they found a string s, carved on a rock below the temple's ga...
#include <bits/stdc++.h> using namespace std; inline int gc() { static const int BUF = 1e7; static char buf[BUF], *bg = buf + BUF, *ed = bg; if (bg == ed) fread(bg = buf, 1, BUF, stdin); return *bg++; } inline int ri() { int x = 0, f = 1, c = gc(); for (; c < 48 || c > 57; f = c == '-' ? -1 : f, c = gc()) ...
### Prompt Generate a Cpp solution to the following problem: Asterix, Obelix and their temporary buddies Suffix and Prefix has finally found the Harmony temple. However, its doors were firmly locked and even Obelix had no luck opening them. A little later they found a string s, carved on a rock below the temple's ga...
#include <bits/stdc++.h> using namespace std; int p[2000000]; bool used[2000000]; string s; int main(void) { cin >> s; p[0] = 0; int n = s.length(); for (int i = 1; i < n; i++) { int j = p[i - 1]; while (j && s[j] != s[i]) j = p[j - 1]; if (s[j] == s[i]) p[i] = j + 1; } for (int i = 1; i < n - 1...
### Prompt Create a solution in cpp for the following problem: Asterix, Obelix and their temporary buddies Suffix and Prefix has finally found the Harmony temple. However, its doors were firmly locked and even Obelix had no luck opening them. A little later they found a string s, carved on a rock below the temple's ...
#include <bits/stdc++.h> const int MAXN = 1E6 + 10; int next[MAXN]; char text[MAXN]; void GetNext(const char* p) { int j = 0; next[0] = next[1] = 0; for (int i = 1; p[i]; ++i) { while (j && p[i] != p[j]) j = next[j]; if (p[i] == p[j]) ++j; next[i + 1] = j; } } bool KMP(const char* t, int len_t, cons...
### Prompt In Cpp, your task is to solve the following problem: Asterix, Obelix and their temporary buddies Suffix and Prefix has finally found the Harmony temple. However, its doors were firmly locked and even Obelix had no luck opening them. A little later they found a string s, carved on a rock below the temple's...
#include <bits/stdc++.h> using namespace std; const int MaxN = 1e6 + 7; string s; int p[MaxN], deg[MaxN], H[MaxN], x = 31, Sum; void v() { deg[0] = 1; for (int i = 1; i <= s.size(); i++) deg[i] = deg[i - 1] * x; H[0] = 0; H[1] = s[0]; for (int i = 2; i <= s.size(); i++) H[i] = H[i - 1] * x + s[i - 1]; } int F...
### Prompt Your challenge is to write a CPP solution to the following problem: Asterix, Obelix and their temporary buddies Suffix and Prefix has finally found the Harmony temple. However, its doors were firmly locked and even Obelix had no luck opening them. A little later they found a string s, carved on a rock bel...
#include <bits/stdc++.h> int n; char s[1024000]; long h[1024000]; int p[1024000]; long pow(long a, long b) { if (b <= 0) return 1; else if (b % 2 == 1) return a * pow(a, b - 1); else { long root = pow(a, b / 2); return root * root; } } void rollHash() { h[n - 1] = s[n - 1]; for (int i = n - ...
### Prompt Develop a solution in CPP to the problem described below: Asterix, Obelix and their temporary buddies Suffix and Prefix has finally found the Harmony temple. However, its doors were firmly locked and even Obelix had no luck opening them. A little later they found a string s, carved on a rock below the tem...
#include <bits/stdc++.h> using namespace std; char s[1000006]; int pre[1000006]; int vis[1000005]; void prefix(int l) { pre[0] = -1; for (int i = 1, j = -1; i <= l; i++) { while (j != -1 && s[j] != s[i - 1]) j = pre[j]; pre[i] = ++j; } } int main() { memset(vis, 0, sizeof(vis)); cin >> s; int l = st...
### Prompt Create a solution in CPP for the following problem: Asterix, Obelix and their temporary buddies Suffix and Prefix has finally found the Harmony temple. However, its doors were firmly locked and even Obelix had no luck opening them. A little later they found a string s, carved on a rock below the temple's ...
#include <bits/stdc++.h> using namespace std; int main(int argc, char *argv[]) { cin.tie(NULL); ios_base::sync_with_stdio(false); string str; cin >> str; int n = str.size(); vector<int> table(n); table[0] = 0; for (int i = 1, j = 0; i < n; i++) { while (j != 0 && str[i] != str[j]) j = table[j - 1]; ...
### Prompt Your challenge is to write a Cpp solution to the following problem: Asterix, Obelix and their temporary buddies Suffix and Prefix has finally found the Harmony temple. However, its doors were firmly locked and even Obelix had no luck opening them. A little later they found a string s, carved on a rock bel...
#include <bits/stdc++.h> using namespace std; char s[1000009]; unsigned long long st[1000009], d[1000009]; int n; unsigned long long H(int l, int r) { l--; return st[r] - st[l] * d[r - l]; } bool Check(int k) { for (int i = 2; i + k - 1 < n; i++) if (H(1, k) == H(i, i + k - 1)) return 1; return 0; } int mai...
### Prompt Develop a solution in CPP to the problem described below: Asterix, Obelix and their temporary buddies Suffix and Prefix has finally found the Harmony temple. However, its doors were firmly locked and even Obelix had no luck opening them. A little later they found a string s, carved on a rock below the tem...
#include <bits/stdc++.h> using namespace std; const pair<long long, long long> M = make_pair(1e9 + 7, 1e9 + 9); const long long base = 347; const int N = 1e6 + 7; ostream& operator<<(ostream& os, pair<long long, long long> hash) { return os << "(" << hash.first << ", " << hash.second << ")"; } pair<long long, long lo...
### Prompt Please formulate a cpp solution to the following problem: Asterix, Obelix and their temporary buddies Suffix and Prefix has finally found the Harmony temple. However, its doors were firmly locked and even Obelix had no luck opening them. A little later they found a string s, carved on a rock below the tem...
#include <bits/stdc++.h> using namespace std; int n, prefix[1000001], avail[1000001] = {0}; string s; void print() { for (int j = 0; j < n; j++) cout << prefix[j] << " "; cout << endl; return; } void build_prefix_array() { int i = 1, j = 0; prefix[0] = 0; while (i < n) { if (s[j] == s[i]) { prefix...
### Prompt In Cpp, your task is to solve the following problem: Asterix, Obelix and their temporary buddies Suffix and Prefix has finally found the Harmony temple. However, its doors were firmly locked and even Obelix had no luck opening them. A little later they found a string s, carved on a rock below the temple's...
#include <bits/stdc++.h> using namespace std; vector<int> pref(const string& s) { int n = s.size(); vector<int> p(n); for (int i = 1; i < n; i++) { int j = p[i - 1]; while (j > 0 && s[i] != s[j]) j = p[j - 1]; if (s[i] == s[j]) p[i] = j + 1; } return p; } int main() { string s; cin >> s; vec...
### Prompt Construct a cpp code solution to the problem outlined: Asterix, Obelix and their temporary buddies Suffix and Prefix has finally found the Harmony temple. However, its doors were firmly locked and even Obelix had no luck opening them. A little later they found a string s, carved on a rock below the temple...
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; vector<int> K; K.resize(s.size(), 0); K[0] = 0; for (int i = 1; i < s.size(); i++) { int temp = K[i - 1]; while (s[temp] != s[i] && temp != 0) temp = K[temp - 1]; if (s[i] == s[temp]) K[i] = temp + 1; else ...
### Prompt Please create a solution in CPP to the following problem: Asterix, Obelix and their temporary buddies Suffix and Prefix has finally found the Harmony temple. However, its doors were firmly locked and even Obelix had no luck opening them. A little later they found a string s, carved on a rock below the tem...
#include <bits/stdc++.h> using namespace std; vector<int> prefix(string s) { int n = s.length(); vector<int> p(n); p[0] = 0; for (int i = 1; i < n; i++) { int j = p[i - 1]; while (j > 0 && s[i] != s[j]) j = p[j - 1]; if (s[i] == s[j]) j++; p[i] = j; } return p; } int main() { string s; c...
### Prompt Create a solution in cpp for the following problem: Asterix, Obelix and their temporary buddies Suffix and Prefix has finally found the Harmony temple. However, its doors were firmly locked and even Obelix had no luck opening them. A little later they found a string s, carved on a rock below the temple's ...
#include <bits/stdc++.h> using namespace std; vector<unsigned long long> p_pow, h; void p_hash(const string& str) { p_pow.resize(str.size()); h.resize(str.size()); const int p = 53; p_pow[0] = p; for (size_t i = 1; i < str.size(); ++i) p_pow[i] = p_pow[i - 1] * p; for (size_t i = 0; i < str.size(); ++i) { ...
### Prompt Please provide a cpp coded solution to the problem described below: Asterix, Obelix and their temporary buddies Suffix and Prefix has finally found the Harmony temple. However, its doors were firmly locked and even Obelix had no luck opening them. A little later they found a string s, carved on a rock bel...
#include <bits/stdc++.h> using namespace std; int pi[1000005], n, mx, k; char sir[1000005]; int main() { cin >> (sir + 1); n = strlen(sir + 1); pi[1] = 0; for (int i = 2; i <= n; ++i) { while (k > 0 && sir[i] != sir[k + 1]) { k = pi[k]; } if (sir[i] == sir[k + 1]) ++k; pi[i] = k; if (i...
### Prompt Your challenge is to write a CPP solution to the following problem: Asterix, Obelix and their temporary buddies Suffix and Prefix has finally found the Harmony temple. However, its doors were firmly locked and even Obelix had no luck opening them. A little later they found a string s, carved on a rock bel...
#include <bits/stdc++.h> using namespace std; int Z[1000005], n, L = 0, R = 0; string S; vector<pair<int, int> > luu; int main() { cin >> S; n = S.size(); Z[0] = n; for (int i = 1; i < n; i++) if (i > R) { L = R = i; while (R < n && S[R] == S[R - L]) R++; Z[i] = R - L; R--; } els...
### Prompt Please create a solution in cpp to the following problem: Asterix, Obelix and their temporary buddies Suffix and Prefix has finally found the Harmony temple. However, its doors were firmly locked and even Obelix had no luck opening them. A little later they found a string s, carved on a rock below the tem...
#include <bits/stdc++.h> using namespace std; char s[1000005]; int z[1000005], l = -1, r = -1, wynik, indeks; int out[1000005]; int main() { scanf("%s", s); int n = strlen(s); int ile = 0; for (int i = 1; n > i; i++) { if (r > i) z[i] = min(r - i + 1, z[i - l]); while (z[i] + i < n and s[i + z[i]] == s[...
### Prompt Create a solution in cpp for the following problem: Asterix, Obelix and their temporary buddies Suffix and Prefix has finally found the Harmony temple. However, its doors were firmly locked and even Obelix had no luck opening them. A little later they found a string s, carved on a rock below the temple's ...
#include <bits/stdc++.h> using namespace std; const int maxn = 1e6 + 100, base = 37; long long hashing[maxn], po[maxn]; string s; void hsh() { for (int i = 1; i < s.size(); i++) hashing[i] = (s[i] - 'a' + 1) + (hashing[i - 1] * base); } long long f(int len, long long k) { for (int i = len + 1; i < s.size() - 1;...
### Prompt Create a solution in CPP for the following problem: Asterix, Obelix and their temporary buddies Suffix and Prefix has finally found the Harmony temple. However, its doors were firmly locked and even Obelix had no luck opening them. A little later they found a string s, carved on a rock below the temple's ...
#include <bits/stdc++.h> using namespace std; template <class T1> void deb(T1 e) { cout << e << endl; } template <class T1, class T2> void deb(T1 e1, T2 e2) { cout << e1 << " " << e2 << endl; } template <class T1, class T2, class T3> void deb(T1 e1, T2 e2, T3 e3) { cout << e1 << " " << e2 << " " << e3 << endl; } ...
### Prompt Create a solution in cpp for the following problem: Asterix, Obelix and their temporary buddies Suffix and Prefix has finally found the Harmony temple. However, its doors were firmly locked and even Obelix had no luck opening them. A little later they found a string s, carved on a rock below the temple's ...
#include <bits/stdc++.h> using namespace std; long i, j, n, k, xl, yl, len = -1; string s1, s2, s; vector<long> pi(1000001), ans(1000001); char c; int main() { cin >> s; n = s.length(); for (i = 1; i < n; i++) { j = pi[i - 1]; while (s[j] != s[i] && j > 0) j = pi[j - 1]; if (s[j] == s[i]) ++j; pi[...
### Prompt Please provide a CPP coded solution to the problem described below: Asterix, Obelix and their temporary buddies Suffix and Prefix has finally found the Harmony temple. However, its doors were firmly locked and even Obelix had no luck opening them. A little later they found a string s, carved on a rock bel...
#include <bits/stdc++.h> char str[1000010]; int l; int nxt[1000010]; int cnt[1000010]; int main() { scanf("%s", str); l = strlen(str); memset(nxt, -1, sizeof(nxt)); int k; for (int i = 1; i < l; i++) { for (k = nxt[i - 1]; k >= 0 && str[i] - str[k + 1]; k = nxt[k]) ; if (str[k + 1] == str[i]) { ...
### Prompt Construct a cpp code solution to the problem outlined: Asterix, Obelix and their temporary buddies Suffix and Prefix has finally found the Harmony temple. However, its doors were firmly locked and even Obelix had no luck opening them. A little later they found a string s, carved on a rock below the temple...
#include <bits/stdc++.h> using namespace std; int len; int p[1000006]; char str[1000006]; bool record[1000006]; void calulate_kmp_prefix() { p[1] = 0; int k = 0; for (int i = 2; i <= len; i++) { while (k > 0 && str[i] != str[k + 1]) { k = p[k]; } if (str[i] == str[k + 1]) { k++; } ...
### Prompt Your challenge is to write a cpp solution to the following problem: Asterix, Obelix and their temporary buddies Suffix and Prefix has finally found the Harmony temple. However, its doors were firmly locked and even Obelix had no luck opening them. A little later they found a string s, carved on a rock bel...
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 10; int p[N], d[N], ans; string s; void prefix(string s) { int j = 0; for (int i = 1; i < (int)s.size(); i++) { while (j > 0 && s[i] != s[j]) j = p[j - 1]; j += (s[i] == s[j]); p[i] = j; } } int main() { cin >> s; if (s.size() < 3) ...
### Prompt Please formulate a cpp solution to the following problem: Asterix, Obelix and their temporary buddies Suffix and Prefix has finally found the Harmony temple. However, its doors were firmly locked and even Obelix had no luck opening them. A little later they found a string s, carved on a rock below the tem...
#include <bits/stdc++.h> using namespace std; string s; bool poklapanje(int x) { int n = s.size(); for (int i = 0; i < x; i++) { if (s[i] != s[n - x + i]) return false; } return true; } int main() { cin >> s; int n = s.size(); int p[n]; p[0] = 0; for (int i = 1; i < n; i++) { int j = p[i - 1];...
### Prompt Your challenge is to write a cpp solution to the following problem: Asterix, Obelix and their temporary buddies Suffix and Prefix has finally found the Harmony temple. However, its doors were firmly locked and even Obelix had no luck opening them. A little later they found a string s, carved on a rock bel...
#include <bits/stdc++.h> using namespace std; int xx[] = {0, 0, 1, -1, 1, -1, 1, -1}; int yy[] = {1, -1, 0, 0, 1, -1, -1, 1}; struct Point { double x, y; }; char str[1000009]; int F[1000009]; inline long long MAX(long long a, long long b) { return (a > b) ? a : b; } inline long long MIN(long long a, long long b) { re...
### Prompt Construct a Cpp code solution to the problem outlined: Asterix, Obelix and their temporary buddies Suffix and Prefix has finally found the Harmony temple. However, its doors were firmly locked and even Obelix had no luck opening them. A little later they found a string s, carved on a rock below the temple...
#include <bits/stdc++.h> using namespace std; char a[6000086]; long long ne[2000305]; long long n; long long maxn = 0; void _next() { ne[1] = 0; for (int i = 2, j = 0; i <= n; i++) { while (a[i] != a[j + 1] && j > 0) j = ne[j]; if (a[i] == a[j + 1]) ne[i] = ++j; if (i != n) maxn = max(ne[i], maxn); } ...
### Prompt Your task is to create a CPP solution to the following problem: Asterix, Obelix and their temporary buddies Suffix and Prefix has finally found the Harmony temple. However, its doors were firmly locked and even Obelix had no luck opening them. A little later they found a string s, carved on a rock below t...
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:64000000") using namespace std; char s[1000006]; int z[1000006]; void calc_z() { int n = (int)strlen(s); int l = 0, r = 0; for (int i = 1; i <= int(n); i++) { if (i < r) { z[i] = min(z[i - l], r - i); } while (i + z[i] < n && s[z[i]] == s[...
### Prompt Construct a CPP code solution to the problem outlined: Asterix, Obelix and their temporary buddies Suffix and Prefix has finally found the Harmony temple. However, its doors were firmly locked and even Obelix had no luck opening them. A little later they found a string s, carved on a rock below the temple...
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; const int maxn = 1e6 + 10; const int b = 256; string s; long long int ph[maxn]; long long int pw[maxn]; inline long long int get(int l, int r); inline bool check(int f); vector<int> v; int main() { ios_base::sync_with_stdio(false); cin.tie(0); ...
### Prompt Develop a solution in cpp to the problem described below: Asterix, Obelix and their temporary buddies Suffix and Prefix has finally found the Harmony temple. However, its doors were firmly locked and even Obelix had no luck opening them. A little later they found a string s, carved on a rock below the tem...
#include <bits/stdc++.h> using namespace std; int main() { char *s = new char[1 << 20]; int *t = new int[1 << 20]; int n = 0; cin >> s; while (s[n]) n++; int k = -1; t[0] = -1; for (int i = 1; i < n; i++) { char si = s[i]; while (k != -1 && s[k + 1] != si) k = t[k]; if (s[k + 1] == si) k++; ...
### Prompt Your challenge is to write a CPP solution to the following problem: Asterix, Obelix and their temporary buddies Suffix and Prefix has finally found the Harmony temple. However, its doors were firmly locked and even Obelix had no luck opening them. A little later they found a string s, carved on a rock bel...
#include <bits/stdc++.h> using namespace std; vector<int> z; void z_function(string s) { int n = s.size(); z.resize(n); for (int i = 1, l = 0, r = 0; i < n; ++i) { if (i <= r) z[i] = min(r - i + 1, z[i - l]); while (i + z[i] < n && s[z[i]] == s[i + z[i]]) ++z[i]; if (i + z[i] - 1 > r) l = i, r = i + z...
### Prompt Please formulate a cpp solution to the following problem: Asterix, Obelix and their temporary buddies Suffix and Prefix has finally found the Harmony temple. However, its doors were firmly locked and even Obelix had no luck opening them. A little later they found a string s, carved on a rock below the tem...
#include <bits/stdc++.h> using namespace std; vector<int> computeZ(string s) { int n = s.size(); vector<int> z(n, 0); for (int i = 1, l = 0, r = 0; i < n; i++) { if (i <= r) { z[i] = min(r - i + 1, z[i - l]); } while (i + z[i] < n && s[z[i]] == s[i + z[i]]) { ++z[i]; } if (i + z[i]...
### Prompt Please provide a Cpp coded solution to the problem described below: Asterix, Obelix and their temporary buddies Suffix and Prefix has finally found the Harmony temple. However, its doors were firmly locked and even Obelix had no luck opening them. A little later they found a string s, carved on a rock bel...
#include <bits/stdc++.h> using namespace std; template <class T> void cmin(T &a, T b) { if (b < a) a = b; } template <class T> void cmax(T &a, T b) { if (b > a) a = b; } template <class T> int len(const T &c) { return (int)c.size(); } bool is_palindrome(const string &s, int start, int end) { int siz = end - sta...
### Prompt Generate a cpp solution to the following problem: Asterix, Obelix and their temporary buddies Suffix and Prefix has finally found the Harmony temple. However, its doors were firmly locked and even Obelix had no luck opening them. A little later they found a string s, carved on a rock below the temple's ga...
#include <bits/stdc++.h> using namespace std; int z[1000006], dp[1000006]; int N; char ch[1000006]; void zee() { int L, R, k, a, ans; z[0] = 0; L = R = -1; for (a = 1; a < N; a++) { if (a > R) { L = R = a; while (ch[R - L] == ch[R]) R++; z[a] = R - L; R--; } else { k = a - ...
### Prompt Please create a solution in Cpp to the following problem: Asterix, Obelix and their temporary buddies Suffix and Prefix has finally found the Harmony temple. However, its doors were firmly locked and even Obelix had no luck opening them. A little later they found a string s, carved on a rock below the tem...
#include <bits/stdc++.h> using namespace std; vector<int> fail(string s) { int n = s.length(); vector<int> res(n); res[0] = 0; for (int i = 1, k = 0; i < n; i++) { while (k > 0 && s[k] != s[i]) { k = res[k - 1]; } if (s[i] == s[k]) k++; res[i] = k; } return res; } vector<int> p[1001000...
### Prompt Construct a cpp code solution to the problem outlined: Asterix, Obelix and their temporary buddies Suffix and Prefix has finally found the Harmony temple. However, its doors were firmly locked and even Obelix had no luck opening them. A little later they found a string s, carved on a rock below the temple...
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:1000000000,1000000000") using namespace std; const long long inf = 1e18 + 7; const long long mod = 1e9 + 7; const double eps = 1e-9; const double PI = 2 * acos(0.0); const double E = 2.71828; char s[1000005]; long long p[1000005]; int main(void) { gets(s); lo...
### Prompt Please provide a Cpp coded solution to the problem described below: Asterix, Obelix and their temporary buddies Suffix and Prefix has finally found the Harmony temple. However, its doors were firmly locked and even Obelix had no luck opening them. A little later they found a string s, carved on a rock bel...
#include <bits/stdc++.h> using namespace std; string s; int z[(1000000 + 5)]; void input() { getline(cin, s); } int M[(1000000 + 5)]; void solve() { z[0] = s.size(); int l = 0, r = 0; for (int i = 1; i <= s.size() - 1; ++i) { if (i > r) { l = r = i; while (s[r] == s[r - l] && r < s.size()) ++r; ...
### Prompt Your task is to create a CPP solution to the following problem: Asterix, Obelix and their temporary buddies Suffix and Prefix has finally found the Harmony temple. However, its doors were firmly locked and even Obelix had no luck opening them. A little later they found a string s, carved on a rock below t...
#include <bits/stdc++.h> using namespace std; vector<int> Z_Algorithm(const string& s) { int n = s.size(); vector<int> Z(n); int L = 0, R = 0; for (int i(1); i < (n); ++i) { if (R > i) { if (Z[i - L] + i >= R) { L = i; Z[i] = R - i; for (int j(R); j < (n); ++j) { if (...
### Prompt Your task is to create a CPP solution to the following problem: Asterix, Obelix and their temporary buddies Suffix and Prefix has finally found the Harmony temple. However, its doors were firmly locked and even Obelix had no luck opening them. A little later they found a string s, carved on a rock below t...
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 10; vector<int> v[N]; int z[N]; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); string s; cin >> s; int l = 0, r = 0; for (int i = 1; i < s.size(); i++) { if (i <= r) z[i] = min(r - i + 1, z[i - l]); while (i + z[i] <...
### Prompt Develop a solution in cpp to the problem described below: Asterix, Obelix and their temporary buddies Suffix and Prefix has finally found the Harmony temple. However, its doors were firmly locked and even Obelix had no luck opening them. A little later they found a string s, carved on a rock below the tem...
#include <bits/stdc++.h> int p[1000001]; char s[1000005]; int x[27]; int main() { scanf("%s", &s); int len = 0; p[len] = 0; int i = 1; int length = strlen(s) - 1; while (i < strlen(s)) { if (s[i] == s[len]) { len++; p[i] = len; i++; } else { if (len != 0) { len = p[le...
### Prompt Your challenge is to write a Cpp solution to the following problem: Asterix, Obelix and their temporary buddies Suffix and Prefix has finally found the Harmony temple. However, its doors were firmly locked and even Obelix had no luck opening them. A little later they found a string s, carved on a rock bel...
#include <bits/stdc++.h> using namespace std; void lps(string s, int *a) { long long int n = s.length(); long long int i = 1; long long int len = 0; a[0] = 0; while (i < n) { if (s[i] == s[len]) { len++; a[i] = len; i++; } else { if (len != 0) { len = a[len - 1]; ...
### Prompt Create a solution in CPP for the following problem: Asterix, Obelix and their temporary buddies Suffix and Prefix has finally found the Harmony temple. However, its doors were firmly locked and even Obelix had no luck opening them. A little later they found a string s, carved on a rock below the temple's ...
#include <bits/stdc++.h> using namespace std; const int MX = 1000001; const int MI = 100001; const int MT = 10001; char a[MX]; int z[MX], x[MX], y[MX]; vector<int> z_function(string s) { int n = (int)s.length(); vector<int> z(n); for (int i = 1, l = 0, r = 0; i < n; ++i) { if (i <= r) z[i] = min(r - i + 1, z[...
### Prompt Develop a solution in Cpp to the problem described below: Asterix, Obelix and their temporary buddies Suffix and Prefix has finally found the Harmony temple. However, its doors were firmly locked and even Obelix had no luck opening them. A little later they found a string s, carved on a rock below the tem...
#include <bits/stdc++.h> int arr[1000005]; char str[1000005]; int max = -(1 << 30); void f(int len) { int idx = 1; int length = 0; arr[0] = 0; while (idx < len) { if (str[length] != str[idx]) { if (length == 0) { arr[idx++] = 0; } else length = arr[length - 1]; } else { ...
### Prompt Generate a cpp solution to the following problem: Asterix, Obelix and their temporary buddies Suffix and Prefix has finally found the Harmony temple. However, its doors were firmly locked and even Obelix had no luck opening them. A little later they found a string s, carved on a rock below the temple's ga...
#include <bits/stdc++.h> using namespace std; const long long int maxn = 1000010; char p[maxn]; long long int f[maxn]; long long int n; int main() { scanf(" %s", p); n = strlen(p); f[0] = -1; long long int j = -1, i = 0; while (i <= n) { while (j >= 0 && p[i] != p[j]) j = f[j]; j++; i++; f[i] ...
### Prompt Please create a solution in cpp to the following problem: Asterix, Obelix and their temporary buddies Suffix and Prefix has finally found the Harmony temple. However, its doors were firmly locked and even Obelix had no luck opening them. A little later they found a string s, carved on a rock below the tem...
#include <bits/stdc++.h> using namespace std; const long long LINF = 1e18 + 100100, INF = 2e9 + 100100; const double EPS = 1e-9, PI = acos(-1); const int MOD = 1e9 + 7, P = 239, MAXN = 1e5 + 100; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); vector<int> zfunc(const string &s) { int n = (int)(s)...
### Prompt Create a solution in Cpp for the following problem: Asterix, Obelix and their temporary buddies Suffix and Prefix has finally found the Harmony temple. However, its doors were firmly locked and even Obelix had no luck opening them. A little later they found a string s, carved on a rock below the temple's ...
#include <bits/stdc++.h> using namespace std; int fx[4] = {1, -1, 0, 0}; int fy[4] = {0, 0, 1, -1}; const double PI = acos(-1.0); const double EPS = 1e-6; const int MOD = (int)1e9 + 7; const int maxn = (int)2e5 + 5; int z_function(string s) { int n = (int)s.length(); vector<int> z(n); z[0] = 0; int maxMatch = 0...
### Prompt Please create a solution in cpp to the following problem: Asterix, Obelix and their temporary buddies Suffix and Prefix has finally found the Harmony temple. However, its doors were firmly locked and even Obelix had no luck opening them. A little later they found a string s, carved on a rock below the tem...
#include <bits/stdc++.h> using namespace std; int main() { int pi[1000005]; string str; int i, n, now = -1; cin >> str; n = str.length(); pi[0] = -1; for (i = 1; i < n; i++) { while (now != -1 && str[i] != str[now + 1]) now = pi[now]; if (str[i] == str[now + 1]) pi[i] = ++now; else ...
### Prompt In CPP, your task is to solve the following problem: Asterix, Obelix and their temporary buddies Suffix and Prefix has finally found the Harmony temple. However, its doors were firmly locked and even Obelix had no luck opening them. A little later they found a string s, carved on a rock below the temple's...
#include <bits/stdc++.h> using namespace std; int i, n, k, pref[1000005]; bool u; string s; int main() { ios_base::sync_with_stdio(0); cin.tie(0); getline(cin, s); n = s.length(); for (i = 1; i < n; ++i) { while (k && s[i] != s[k]) k = pref[k - 1]; if (s[i] == s[k]) ++k; pref[i] = k; } if (!pr...
### Prompt Your challenge is to write a cpp solution to the following problem: Asterix, Obelix and their temporary buddies Suffix and Prefix has finally found the Harmony temple. However, its doors were firmly locked and even Obelix had no luck opening them. A little later they found a string s, carved on a rock bel...
#include <bits/stdc++.h> using namespace std; const int maxn = 1e6; long long int partial_hash[maxn]; long long int base = 37; vector<int> v; long long int P[maxn]; string s; long long int H(int s, int e) { if (s == 0) return partial_hash[e]; s--; return partial_hash[e] - partial_hash[s] * P[e - s]; } bool ism(lo...
### Prompt Your challenge is to write a cpp solution to the following problem: Asterix, Obelix and their temporary buddies Suffix and Prefix has finally found the Harmony temple. However, its doors were firmly locked and even Obelix had no luck opening them. A little later they found a string s, carved on a rock bel...
#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 __print(float x) { cer...
### Prompt In cpp, your task is to solve the following problem: Asterix, Obelix and their temporary buddies Suffix and Prefix has finally found the Harmony temple. However, its doors were firmly locked and even Obelix had no luck opening them. A little later they found a string s, carved on a rock below the temple's...
#include <bits/stdc++.h> const int N = 1000009; const int p = 31; const int m = 1e9 + 7; using namespace std; int n; string s; long long p_pow[N], h[N + 1]; void preProcess(string const& s) { p_pow[0] = 1; h[0] = 0; n = s.size(); for (int i = 1; i <= n; i++) p_pow[i] = (p_pow[i - 1] * p) % m; for (int i = 1; ...
### Prompt Generate a cpp solution to the following problem: Asterix, Obelix and their temporary buddies Suffix and Prefix has finally found the Harmony temple. However, its doors were firmly locked and even Obelix had no luck opening them. A little later they found a string s, carved on a rock below the temple's ga...
#include <bits/stdc++.h> using namespace std; const double PI = acos(-1); const double eps = 1e-9; const int inf = 2000000000; const long long infLL = 9000000000000000000; int __gcd(int a, int b) { return b == 0 ? a : __gcd(b, a % b); } int power(int x, int n) { if (n == 0) return 1; else if (n % 2 == 0) { ...
### Prompt In cpp, your task is to solve the following problem: Asterix, Obelix and their temporary buddies Suffix and Prefix has finally found the Harmony temple. However, its doors were firmly locked and even Obelix had no luck opening them. A little later they found a string s, carved on a rock below the temple's...
#include <bits/stdc++.h> using namespace std; int main() { ios ::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); string s; cin >> s; int n = s.length(); vector<int> z(n, 0); multiset<int> z_; for (int i = 1, l = 0, r = 0; i < n; i++) { if (i > r) { l = r = i; while (r < n ...
### Prompt Your task is to create a Cpp solution to the following problem: Asterix, Obelix and their temporary buddies Suffix and Prefix has finally found the Harmony temple. However, its doors were firmly locked and even Obelix had no luck opening them. A little later they found a string s, carved on a rock below t...
#include <bits/stdc++.h> using namespace std; char s[1000005]; int z[1000005]; int main() { gets(s); int ln = strlen(s); int j, l = 0, r = 0, b, st; for (int i = 1; i < ln; i++) { if (i <= r) { st = i - l; b = r - i + 1; if (z[st] < b) { z[i] = z[st]; } else { for (j ...
### Prompt In CPP, your task is to solve the following problem: Asterix, Obelix and their temporary buddies Suffix and Prefix has finally found the Harmony temple. However, its doors were firmly locked and even Obelix had no luck opening them. A little later they found a string s, carved on a rock below the temple's...
#include <bits/stdc++.h> using namespace std; const int M = 3e6 + 5; int a[M], n, nxt[M], len; char s[M], sb[M]; void Next() { int j = 0; for (int i = 2; i <= len; i++) { while (j && s[j + 1] != s[i]) j = nxt[j]; if (s[j + 1] == s[i]) j++; nxt[i] = j; } } int main() { scanf("%s", s + 1); len = str...
### Prompt Your challenge is to write a CPP solution to the following problem: Asterix, Obelix and their temporary buddies Suffix and Prefix has finally found the Harmony temple. However, its doors were firmly locked and even Obelix had no luck opening them. A little later they found a string s, carved on a rock bel...
#include <bits/stdc++.h> using namespace std; long long izq, der, agregar = 1, mod = (1E16) + 61, cuanto = -1, inv = 576923081, val[1000000], ag[1000000]; char cad[1000000]; int l, cuantos, longitud[1000000]; bool iguales(int a, int b, int dif) { for (int j = 0; j < dif; j++) if (cad[a + j] !=...
### Prompt Please formulate a Cpp solution to the following problem: Asterix, Obelix and their temporary buddies Suffix and Prefix has finally found the Harmony temple. However, its doors were firmly locked and even Obelix had no luck opening them. A little later they found a string s, carved on a rock below the tem...
#include <bits/stdc++.h> using namespace std; int main() { int n; int m; cin >> n >> m; vector<int> price(n); for (int i = 0; i < n; ++i) { cin >> price[i]; } sort(price.begin(), price.end()); map<string, int> fruit; for (int i = 0; i < m; ++i) { string s; cin >> s; ++fruit[s]; } v...
### Prompt Your task is to create a Cpp solution to the following problem: The spring is coming and it means that a lot of fruits appear on the counters. One sunny day little boy Valera decided to go shopping. He made a list of m fruits he wanted to buy. If Valera want to buy more than one fruit of some kind, he incl...
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; int arr[101]; for (int i = 0; i < n; i++) cin >> arr[i]; sort(arr, arr + n); map<string, int> mp; string s; for (int i = 0; i < m; i++) { cin >> s; mp[s]++; } vector<pair<int, string> > v; for (map<string, ...
### Prompt Please create a solution in CPP to the following problem: The spring is coming and it means that a lot of fruits appear on the counters. One sunny day little boy Valera decided to go shopping. He made a list of m fruits he wanted to buy. If Valera want to buy more than one fruit of some kind, he includes i...
#include <bits/stdc++.h> using namespace std; int main() { int n, m, _min = 0, _max = 0; cin >> n >> m; vector<int> price(n); for (int i = 0; i < n; ++i) cin >> price[i]; sort(price.begin(), price.end()); map<string, int> M; string fruit; for (int i = 0; i < m; ++i) { cin >> fruit; M[fruit] += 1...
### Prompt Construct a Cpp code solution to the problem outlined: The spring is coming and it means that a lot of fruits appear on the counters. One sunny day little boy Valera decided to go shopping. He made a list of m fruits he wanted to buy. If Valera want to buy more than one fruit of some kind, he includes it i...
#include <bits/stdc++.h> using namespace std; const long long inf = 1000000000000ll; const double pi = acos(-1.0); int p[100]; int main() { map<string, int> f; memset(p, 200, sizeof(p)); vector<int> v; int n, m; cin >> n >> m; for (int i = 0; i < n; ++i) cin >> p[i]; string s; for (int i = 0; i < m; ++i...
### Prompt Generate a CPP solution to the following problem: The spring is coming and it means that a lot of fruits appear on the counters. One sunny day little boy Valera decided to go shopping. He made a list of m fruits he wanted to buy. If Valera want to buy more than one fruit of some kind, he includes it into t...
#include <bits/stdc++.h> using namespace std; const long long M = 2e5 + 9, MOD = 1e9 + 7; int a[M], b[M]; map<string, int> mp; string s; int main() { ios::sync_with_stdio(false); cin.tie(0); int n, m; cin >> n >> m; for (int i = 0; i < n; i++) cin >> a[i]; sort(a, a + n); while (m--) { cin >> s; m...
### Prompt Create a solution in CPP for the following problem: The spring is coming and it means that a lot of fruits appear on the counters. One sunny day little boy Valera decided to go shopping. He made a list of m fruits he wanted to buy. If Valera want to buy more than one fruit of some kind, he includes it into...
#include <bits/stdc++.h> using namespace std; int sum_of_digits(long long int num) { if (num < 10) return num; int sum = 0; while (num > 0) { sum += num % 10; num = num / 10; } return sum_of_digits(sum); } int main() { int n, m; cin >> n >> m; vector<int> a; for (int i = 0; i < n; i++) { i...
### Prompt Construct a Cpp code solution to the problem outlined: The spring is coming and it means that a lot of fruits appear on the counters. One sunny day little boy Valera decided to go shopping. He made a list of m fruits he wanted to buy. If Valera want to buy more than one fruit of some kind, he includes it i...
#include <bits/stdc++.h> const int MOD = 1e9 + 7; const long long INF = 1e18; const int mxn = 1e6 + 9; using namespace std; void SoLuTioN() { int n, k; cin >> n >> k; vector<int> v(n); for (int i = 0; i < n; i++) cin >> v[i]; sort(v.begin(), v.end()); map<string, int> m; string str[k]; cin.ignore(); f...
### Prompt In cpp, your task is to solve the following problem: The spring is coming and it means that a lot of fruits appear on the counters. One sunny day little boy Valera decided to go shopping. He made a list of m fruits he wanted to buy. If Valera want to buy more than one fruit of some kind, he includes it int...
#include <bits/stdc++.h> using namespace std; map<string, int> m; map<string, int>::iterator it; string str; int a[110], n, m1, mn, mx, f[110]; int main() { cin >> n >> m1; for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 0; i < m1; i++) { cin >> str; m[str]++; } it = m.begin(); int i = 0; fo...
### Prompt Please formulate a Cpp solution to the following problem: The spring is coming and it means that a lot of fruits appear on the counters. One sunny day little boy Valera decided to go shopping. He made a list of m fruits he wanted to buy. If Valera want to buy more than one fruit of some kind, he includes i...
#include <bits/stdc++.h> using namespace std; string s; int a[200]; int main() { int n, m, i; cin >> n >> m; map<string, int> ma; vector<int> v; for (i = 0; i < n; i++) { cin >> a[i]; } sort(a, a + n); for (i = 0; i < m; i++) { cin >> s; ma[s]++; } for (map<string, int>::iterator it = ma...
### Prompt Please formulate a cpp solution to the following problem: The spring is coming and it means that a lot of fruits appear on the counters. One sunny day little boy Valera decided to go shopping. He made a list of m fruits he wanted to buy. If Valera want to buy more than one fruit of some kind, he includes i...
#include <bits/stdc++.h> using namespace std; bool compare(int p1, int p2) { if (p1 > p2) return true; else return false; } int main() { vector<int> v1, v2; int n, m; cin >> n >> m; map<string, int> mymap; for (int i = 0; i < n; i++) { int r; cin >> r; v1.push_back(r); v2.push_back...
### Prompt Your challenge is to write a cpp solution to the following problem: The spring is coming and it means that a lot of fruits appear on the counters. One sunny day little boy Valera decided to go shopping. He made a list of m fruits he wanted to buy. If Valera want to buy more than one fruit of some kind, he ...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int nfruit, ntags, fruit = 0, x = 0, y = 0; bool fruk; string auglis; cin >> ntags >> nfruit; string mas[nfruit]; int num[nfruit]; int tagi[ntags]; for (int i = 0; i < ntags; i++) { cin >>...
### Prompt Construct a Cpp code solution to the problem outlined: The spring is coming and it means that a lot of fruits appear on the counters. One sunny day little boy Valera decided to go shopping. He made a list of m fruits he wanted to buy. If Valera want to buy more than one fruit of some kind, he includes it i...
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; vector<int> v, a; for (int i = 0; i < n; i++) { int tmp; cin >> tmp; v.push_back(tmp); } map<string, int> ma; for (int i = 0; i < m; i++) { string s; cin >> s; ma[s]++; } for (auto i = ma.begin(...
### Prompt Construct a CPP code solution to the problem outlined: The spring is coming and it means that a lot of fruits appear on the counters. One sunny day little boy Valera decided to go shopping. He made a list of m fruits he wanted to buy. If Valera want to buy more than one fruit of some kind, he includes it i...
#include <bits/stdc++.h> using namespace std; double eps = 1e-9; double pi = acos(-1); int fx[8] = {1, -1, 0, 0, 1, -1, -1, 1}; int fy[8] = {0, 0, 1, -1, 1, -1, 1, -1}; struct fruit { string name; int cnt; }; bool big(fruit p1, fruit p2) { return p1.cnt > p2.cnt; } bool small(fruit p1, fruit p2) { return p1.cnt < p...
### Prompt Your task is to create a Cpp solution to the following problem: The spring is coming and it means that a lot of fruits appear on the counters. One sunny day little boy Valera decided to go shopping. He made a list of m fruits he wanted to buy. If Valera want to buy more than one fruit of some kind, he incl...
#include <bits/stdc++.h> int strlen(char *str) { int i = 0; while (str[i]) { i++; } return i; } int cuvinteEgale(char *s1, char *s2) { if (strlen(s1) != strlen(s2)) { return 0; } for (int i = 0; i < strlen(s1); i++) { if (s1[i] != s2[i]) { return 0; } } return 1; } void bubbleSor...
### Prompt Generate a CPP solution to the following problem: The spring is coming and it means that a lot of fruits appear on the counters. One sunny day little boy Valera decided to go shopping. He made a list of m fruits he wanted to buy. If Valera want to buy more than one fruit of some kind, he includes it into t...
#include <bits/stdc++.h> using namespace std; const double pi = 2.0 * acos(0.0); const double eps = 1.0e-9; const int dr[] = {-1, 0, 1, 0}, dc[] = {0, 1, 0, -1}; const int dr6[] = {1, 1, 0, -1, -1, 0}, dc6[] = {0, 1, 1, 0, -1, -1}; const int dr8[] = {-1, -1, 0, 1, 1, 1, 0, -1}, dc8[] = {0, 1, 1, 1, 0, -1, -1,...
### Prompt Please formulate a CPP solution to the following problem: The spring is coming and it means that a lot of fruits appear on the counters. One sunny day little boy Valera decided to go shopping. He made a list of m fruits he wanted to buy. If Valera want to buy more than one fruit of some kind, he includes i...
#include <bits/stdc++.h> using namespace std; int price[102]; unordered_map<string, int> freq; bool cmp_fruit(pair<string, int> p1, pair<string, int> p2) { return p1.second > p2.second; } bool cmp_price(int val1, int val2) { return val1 > val2; } int main() { int n, m, p; scanf("%d %d", &n, &m); for (int i = 0;...
### Prompt Your task is to create a Cpp solution to the following problem: The spring is coming and it means that a lot of fruits appear on the counters. One sunny day little boy Valera decided to go shopping. He made a list of m fruits he wanted to buy. If Valera want to buy more than one fruit of some kind, he incl...
#include <bits/stdc++.h> using namespace std; int a[100010], b[100010], c[100010]; long long mn = 1e9, mx = -1e9, ans, cnt, sm; bool ok, okk, used[1000010], use[10]; int main() { vector<pair<int, string> > v; int n, m; cin >> n >> m; for (int i = 0; i < n; i++) { cin >> a[i]; } sort(a, a + n); for (in...
### Prompt Your challenge is to write a Cpp solution to the following problem: The spring is coming and it means that a lot of fruits appear on the counters. One sunny day little boy Valera decided to go shopping. He made a list of m fruits he wanted to buy. If Valera want to buy more than one fruit of some kind, he ...
#include <bits/stdc++.h> using namespace std; int main(int argc, char const *argv[]) { int n, m; cin >> n >> m; std::vector<int> v(n, 0); int k = 0; while (n--) { cin >> v[k]; k++; } map<string, int> mp; string temp; while (m--) { cin >> temp; if (mp.find(temp) == mp.end()) { mp[...
### Prompt Please formulate a CPP solution to the following problem: The spring is coming and it means that a lot of fruits appear on the counters. One sunny day little boy Valera decided to go shopping. He made a list of m fruits he wanted to buy. If Valera want to buy more than one fruit of some kind, he includes i...
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; int a[1005]; for (int i = 0; i < n; ++i) cin >> a[i]; map<string, int> fr; for (int i = 0; i < m; ++i) { string cs; cin >> cs; fr[cs]++; } vector<int> tt; for (map<string, int>::iterator it = fr.begin(); it...
### Prompt Your challenge is to write a Cpp solution to the following problem: The spring is coming and it means that a lot of fruits appear on the counters. One sunny day little boy Valera decided to go shopping. He made a list of m fruits he wanted to buy. If Valera want to buy more than one fruit of some kind, he ...
#include <bits/stdc++.h> using namespace std; int main() { int a, b, c, d, e, i, j, x[105], mini, maks, y[505]; string temp; map<string, int> z; cin >> a >> b; for (i = 0; i < a; i++) { cin >> x[i]; } c = 0; for (i = 1; i <= b; i++) { cin >> temp; if (z[temp] == 0) { c++; y[c] = ...
### Prompt Create a solution in Cpp for the following problem: The spring is coming and it means that a lot of fruits appear on the counters. One sunny day little boy Valera decided to go shopping. He made a list of m fruits he wanted to buy. If Valera want to buy more than one fruit of some kind, he includes it into...
#include <bits/stdc++.h> using namespace std; bool compare(pair<int, int> p1, pair<int, int> p2) { if (p1.second < p2.second) return true; else if (p1.second > p2.second) return false; else if (p1.first < p2.first) return true; else return false; } void solve() { long long int n, m = 0, k = 0,...
### Prompt Please create a solution in Cpp to the following problem: The spring is coming and it means that a lot of fruits appear on the counters. One sunny day little boy Valera decided to go shopping. He made a list of m fruits he wanted to buy. If Valera want to buy more than one fruit of some kind, he includes i...
#include <bits/stdc++.h> using namespace std; int main() { string s1; int Min = 0, Max = 0, i, j, n, m, count = 1; vector<string> v; vector<int> c; int a[110]; scanf("%d %d ", &n, &m); for (i = 0; i < n; i++) cin >> a[i]; sort(a, a + n); for (i = 1; i <= m; i++) { cin >> s1; v.push_back(s1); ...
### Prompt In CPP, your task is to solve the following problem: The spring is coming and it means that a lot of fruits appear on the counters. One sunny day little boy Valera decided to go shopping. He made a list of m fruits he wanted to buy. If Valera want to buy more than one fruit of some kind, he includes it int...
#include <bits/stdc++.h> using namespace std; int main() { int n, m, b, c; cin >> n >> m; int a[n]; for (b = 0; b < n; b++) { cin >> a[b]; } sort(a, a + n); map<string, int> m1; string x[m]; for (b = 0; b < m; b++) { cin >> x[b]; m1[x[b]]++; } int d[m], e = 0; for (b = 0; b < m; b++)...
### Prompt Construct a Cpp code solution to the problem outlined: The spring is coming and it means that a lot of fruits appear on the counters. One sunny day little boy Valera decided to go shopping. He made a list of m fruits he wanted to buy. If Valera want to buy more than one fruit of some kind, he includes it i...
#include <bits/stdc++.h> using namespace std; const int dx[4] = {0, 1, 0, -1}; const int dy[4] = {1, 0, -1, 0}; const int inf = 1010101010; const double PI = 4 * atan(1); struct myLT { bool operator()(pair<string, int> const& a, pair<string, int> const& b) { if (a.second > b.second) return true; if (a.second ...
### Prompt Develop a solution in cpp to the problem described below: The spring is coming and it means that a lot of fruits appear on the counters. One sunny day little boy Valera decided to go shopping. He made a list of m fruits he wanted to buy. If Valera want to buy more than one fruit of some kind, he includes i...
#include <bits/stdc++.h> using namespace std; int main() { int n, m, a[105]; string s[105]; cin >> n >> m; for (int i = 0; i < n; i++) { cin >> a[i]; } for (int i = 0; i < m; i++) { cin >> s[i]; } sort(a, a + n); map<string, int> mp; for (int i = 0; i < m; i++) { mp[s[i]]++; } int ce...
### Prompt Generate a cpp solution to the following problem: The spring is coming and it means that a lot of fruits appear on the counters. One sunny day little boy Valera decided to go shopping. He made a list of m fruits he wanted to buy. If Valera want to buy more than one fruit of some kind, he includes it into t...
#include <bits/stdc++.h> using namespace std; const int inf = 12641; string s; int an, a, i, j, n, m, x[101], z[101], mini, maxi, u, b[34]; map<int, int> y; std::map<int, int>::iterator it; int main() { cin >> n >> m; b[0] = 1; for (i = 1; i <= 33; i++) b[i] = ((b[i - 1] * 31) % inf + inf) % inf; for (i = 0; i ...
### Prompt Your challenge is to write a CPP solution to the following problem: The spring is coming and it means that a lot of fruits appear on the counters. One sunny day little boy Valera decided to go shopping. He made a list of m fruits he wanted to buy. If Valera want to buy more than one fruit of some kind, he ...
#include <bits/stdc++.h> using namespace std; int a[101], n, m, cnt[101]; string s[101], x[101]; int main() { cin >> n >> m; for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 0; i < m; i++) cin >> s[i]; sort(a, a + n); sort(s, s + m); int mini = 0, maxi = 0, p = 0; for (int i = 0; i < m;) { x[p] =...
### Prompt Your task is to create a Cpp solution to the following problem: The spring is coming and it means that a lot of fruits appear on the counters. One sunny day little boy Valera decided to go shopping. He made a list of m fruits he wanted to buy. If Valera want to buy more than one fruit of some kind, he incl...
#include <bits/stdc++.h> using namespace std; template <class T> void OUT(T x, int n) { for (int i = 0; i < n; ++i) cout << x[i] << ' '; cout << endl; } template <class T> void OUT(T x, int n, int m) { for (int i = 1; i <= n; ++i) OUT(x[i], m); cout << endl; } template <class T> void checkmod(T& a, T m) { a =...
### Prompt Please provide a Cpp coded solution to the problem described below: The spring is coming and it means that a lot of fruits appear on the counters. One sunny day little boy Valera decided to go shopping. He made a list of m fruits he wanted to buy. If Valera want to buy more than one fruit of some kind, he ...
#include <bits/stdc++.h> using namespace std; map<string, int> mp; bool cmp(const string x, const string y) { return mp[x] > mp[y]; } int main() { int n, m; cin >> n >> m; vector<int> vi(n); vector<string> vs; for (int i = 0; i < n; i++) cin >> vi[i]; for (int i = 0; i < m; i++) { string s; cin >> s...
### Prompt Your task is to create a cpp solution to the following problem: The spring is coming and it means that a lot of fruits appear on the counters. One sunny day little boy Valera decided to go shopping. He made a list of m fruits he wanted to buy. If Valera want to buy more than one fruit of some kind, he incl...
#include <bits/stdc++.h> using namespace std; bool cmp(pair<string, long long int>& a, pair<string, long long int>& b) { return a.second < b.second; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout << fixed; cout.precision(10); long long int n, m; cin >> n >> m; long long int a[n]; ...
### Prompt Construct a cpp code solution to the problem outlined: The spring is coming and it means that a lot of fruits appear on the counters. One sunny day little boy Valera decided to go shopping. He made a list of m fruits he wanted to buy. If Valera want to buy more than one fruit of some kind, he includes it i...
#include <bits/stdc++.h> using namespace std; const int N = 105; int p[105]; char s[105][35]; int am[105]; int pertition(int l, int r) { int i = l; for (int j = l; j < r; j++) { if (strcmp(s[j], s[r]) >= 0) { swap(s[j], s[i]); i++; } } swap(s[i], s[r]); return i; } void quicksort(int l, in...
### Prompt Create a solution in Cpp for the following problem: The spring is coming and it means that a lot of fruits appear on the counters. One sunny day little boy Valera decided to go shopping. He made a list of m fruits he wanted to buy. If Valera want to buy more than one fruit of some kind, he includes it into...
#include <bits/stdc++.h> using namespace std; const int maxn = 112; int p[maxn]; char s[maxn]; vector<int> v; map<string, int> m; int main() { int a, b; scanf("%d %d", &a, &b); for (int i = 0; i < a; i++) { scanf("%d", p + i); } sort(p, p + a); for (int i = 0; i < b; i++) { scanf("%s", s); m[str...
### Prompt Your challenge is to write a CPP solution to the following problem: The spring is coming and it means that a lot of fruits appear on the counters. One sunny day little boy Valera decided to go shopping. He made a list of m fruits he wanted to buy. If Valera want to buy more than one fruit of some kind, he ...
#include <bits/stdc++.h> using namespace std; bool cmp(pair<string, int> a, pair<string, int> b) { return a.second > b.second; } int main() { int n, m; while (cin >> n >> m) { int price[n]; string fruit; map<string, int> List; for (int i = 0; i < n; i++) cin >> price[i]; for (int i = 0; i < m;...
### Prompt Your challenge is to write a cpp solution to the following problem: The spring is coming and it means that a lot of fruits appear on the counters. One sunny day little boy Valera decided to go shopping. He made a list of m fruits he wanted to buy. If Valera want to buy more than one fruit of some kind, he ...
#include <bits/stdc++.h> using namespace std; struct vienas { string pavad; int kiekis; vienas(string PAVAD, int KIEKIS) { pavad = PAVAD; kiekis = KIEKIS; } }; void SKAITYMAS(vector<int>& KAINOS, map<string, int>& PREKIU_KIEKIAI_MAP, set<string>& PREKIU_PAVAD); bool LYGINIMAS(vienas a, vi...
### Prompt Please create a solution in CPP to the following problem: The spring is coming and it means that a lot of fruits appear on the counters. One sunny day little boy Valera decided to go shopping. He made a list of m fruits he wanted to buy. If Valera want to buy more than one fruit of some kind, he includes i...
#include <bits/stdc++.h> struct fruit { int num; char name[50]; }; int compare_intup(const int *a, const int *b) { return *a - *b; } int compare_intdown(const int *a, const int *b) { return *b - *a; } int compare_listint(const struct fruit *a, const struct fruit *b) { return b->num - a->num; } int main(void) { ...
### Prompt Generate a Cpp solution to the following problem: The spring is coming and it means that a lot of fruits appear on the counters. One sunny day little boy Valera decided to go shopping. He made a list of m fruits he wanted to buy. If Valera want to buy more than one fruit of some kind, he includes it into t...