output
stringlengths
52
181k
instruction
stringlengths
296
182k
#include <bits/stdc++.h> using namespace std; string sol(string a) { int l = a.length(); for (int i = 0; i < l; i++) { if (a[i] == 'u') return sol(a.replace(i, 1, "oo")); if (a[i] == 'k' && a[i + 1] == 'h') return sol(a.erase(i, 1)); } return a; } int main() { int n; cin >> n; string a[n]; set<string> ans; for (int i = 0; i < n; i++) { cin >> a[i]; string p = sol(a[i]); ans.insert(p); } cout << ans.size(); }
### Prompt Please formulate a cpp solution to the following problem: There are some ambiguities when one writes Berland names with the letters of the Latin alphabet. For example, the Berland sound u can be written in the Latin alphabet as "u", and can be written as "oo". For this reason, two words "ulyana" and "oolyana" denote the same name. The second ambiguity is about the Berland sound h: one can use both "h" and "kh" to write it. For example, the words "mihail" and "mikhail" denote the same name. There are n users registered on the Polycarp's website. Each of them indicated a name represented by the Latin letters. How many distinct names are there among them, if two ambiguities described above are taken into account? Formally, we assume that two words denote the same name, if using the replacements "u" <image> "oo" and "h" <image> "kh", you can make the words equal. One can make replacements in both directions, in any of the two words an arbitrary number of times. A letter that resulted from the previous replacement can participate in the next replacements. For example, the following pairs of words denote the same name: * "koouper" and "kuooper". Making the replacements described above, you can make both words to be equal: "koouper" <image> "kuuper" and "kuooper" <image> "kuuper". * "khun" and "kkkhoon". With the replacements described above you can make both words to be equal: "khun" <image> "khoon" and "kkkhoon" <image> "kkhoon" <image> "khoon". For a given list of words, find the minimal number of groups where the words in each group denote the same name. Input The first line contains integer number n (2 ≀ n ≀ 400) β€” number of the words in the list. The following n lines contain words, one word per line. Each word consists of only lowercase Latin letters. The length of each word is between 1 and 20 letters inclusive. Output Print the minimal number of groups where the words in each group denote the same name. Examples Input 10 mihail oolyana kooooper hoon ulyana koouper mikhail khun kuooper kkkhoon Output 4 Input 9 hariton hkariton buoi kkkhariton boooi bui khariton boui boi Output 5 Input 2 alex alex Output 1 Note There are four groups of words in the first example. Words in each group denote same name: 1. "mihail", "mikhail" 2. "oolyana", "ulyana" 3. "kooooper", "koouper" 4. "hoon", "khun", "kkkhoon" There are five groups of words in the second example. Words in each group denote same name: 1. "hariton", "kkkhariton", "khariton" 2. "hkariton" 3. "buoi", "boooi", "boui" 4. "bui" 5. "boi" In the third example the words are equal, so they denote the same name. ### Response ```cpp #include <bits/stdc++.h> using namespace std; string sol(string a) { int l = a.length(); for (int i = 0; i < l; i++) { if (a[i] == 'u') return sol(a.replace(i, 1, "oo")); if (a[i] == 'k' && a[i + 1] == 'h') return sol(a.erase(i, 1)); } return a; } int main() { int n; cin >> n; string a[n]; set<string> ans; for (int i = 0; i < n; i++) { cin >> a[i]; string p = sol(a[i]); ans.insert(p); } cout << ans.size(); } ```
#include <bits/stdc++.h> using namespace std; int main() { int n; scanf("%d", &n); set<string> st; string s; while (n--) { cin >> s; string tmp = ""; int idx = s.size() - 1; while (idx >= 0) { if (s[idx] == 'u') tmp += "oo"; else if (s[idx] == 'h') { tmp += 'h'; while (idx >= 1 && s[idx - 1] == 'k') idx--; } else tmp += s[idx]; idx--; } st.insert(tmp); } cout << st.size() << endl; }
### Prompt Please provide a cpp coded solution to the problem described below: There are some ambiguities when one writes Berland names with the letters of the Latin alphabet. For example, the Berland sound u can be written in the Latin alphabet as "u", and can be written as "oo". For this reason, two words "ulyana" and "oolyana" denote the same name. The second ambiguity is about the Berland sound h: one can use both "h" and "kh" to write it. For example, the words "mihail" and "mikhail" denote the same name. There are n users registered on the Polycarp's website. Each of them indicated a name represented by the Latin letters. How many distinct names are there among them, if two ambiguities described above are taken into account? Formally, we assume that two words denote the same name, if using the replacements "u" <image> "oo" and "h" <image> "kh", you can make the words equal. One can make replacements in both directions, in any of the two words an arbitrary number of times. A letter that resulted from the previous replacement can participate in the next replacements. For example, the following pairs of words denote the same name: * "koouper" and "kuooper". Making the replacements described above, you can make both words to be equal: "koouper" <image> "kuuper" and "kuooper" <image> "kuuper". * "khun" and "kkkhoon". With the replacements described above you can make both words to be equal: "khun" <image> "khoon" and "kkkhoon" <image> "kkhoon" <image> "khoon". For a given list of words, find the minimal number of groups where the words in each group denote the same name. Input The first line contains integer number n (2 ≀ n ≀ 400) β€” number of the words in the list. The following n lines contain words, one word per line. Each word consists of only lowercase Latin letters. The length of each word is between 1 and 20 letters inclusive. Output Print the minimal number of groups where the words in each group denote the same name. Examples Input 10 mihail oolyana kooooper hoon ulyana koouper mikhail khun kuooper kkkhoon Output 4 Input 9 hariton hkariton buoi kkkhariton boooi bui khariton boui boi Output 5 Input 2 alex alex Output 1 Note There are four groups of words in the first example. Words in each group denote same name: 1. "mihail", "mikhail" 2. "oolyana", "ulyana" 3. "kooooper", "koouper" 4. "hoon", "khun", "kkkhoon" There are five groups of words in the second example. Words in each group denote same name: 1. "hariton", "kkkhariton", "khariton" 2. "hkariton" 3. "buoi", "boooi", "boui" 4. "bui" 5. "boi" In the third example the words are equal, so they denote the same name. ### Response ```cpp #include <bits/stdc++.h> using namespace std; int main() { int n; scanf("%d", &n); set<string> st; string s; while (n--) { cin >> s; string tmp = ""; int idx = s.size() - 1; while (idx >= 0) { if (s[idx] == 'u') tmp += "oo"; else if (s[idx] == 'h') { tmp += 'h'; while (idx >= 1 && s[idx - 1] == 'k') idx--; } else tmp += s[idx]; idx--; } st.insert(tmp); } cout << st.size() << endl; } ```
#include <bits/stdc++.h> using namespace std; void err(istream_iterator<string> it) {} template <typename T, typename... Args> void err(istream_iterator<string> it, T a, Args... args) { cerr << *it << " = " << a << endl; err(++it, args...); } const long long mod = pow(10, 9) + 7; const long long N = 3e5, M = N; const long long inf = LLONG_MAX; const long long infn = LLONG_MIN; string convert(string s) { long long n = s.length(), i; while (true) { bool done = 0; for (auto it = s.begin(); it != s.end(); it++) { auto p = it; p++; if (p == s.end()) break; else if (*it == 'k' && *p == 'h') { s.erase(it); it--; done = 1; } } if (!done) break; } string k = ""; for (long long i = 0; i < s.length(); i++) { if (s[i] == 'u') { k += "oo"; } else k += s[i]; } { string _s = "k"; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, k); }; return k; } void iluzn() { long long n; cin >> n; long long k = n; set<string> st; while (n--) { string s; cin >> s; s = convert(s); st.insert(s); } cout << st.size() << "\n"; } signed main() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); long long t = 1; while (t--) iluzn(); return 0; }
### Prompt Please create a solution in Cpp to the following problem: There are some ambiguities when one writes Berland names with the letters of the Latin alphabet. For example, the Berland sound u can be written in the Latin alphabet as "u", and can be written as "oo". For this reason, two words "ulyana" and "oolyana" denote the same name. The second ambiguity is about the Berland sound h: one can use both "h" and "kh" to write it. For example, the words "mihail" and "mikhail" denote the same name. There are n users registered on the Polycarp's website. Each of them indicated a name represented by the Latin letters. How many distinct names are there among them, if two ambiguities described above are taken into account? Formally, we assume that two words denote the same name, if using the replacements "u" <image> "oo" and "h" <image> "kh", you can make the words equal. One can make replacements in both directions, in any of the two words an arbitrary number of times. A letter that resulted from the previous replacement can participate in the next replacements. For example, the following pairs of words denote the same name: * "koouper" and "kuooper". Making the replacements described above, you can make both words to be equal: "koouper" <image> "kuuper" and "kuooper" <image> "kuuper". * "khun" and "kkkhoon". With the replacements described above you can make both words to be equal: "khun" <image> "khoon" and "kkkhoon" <image> "kkhoon" <image> "khoon". For a given list of words, find the minimal number of groups where the words in each group denote the same name. Input The first line contains integer number n (2 ≀ n ≀ 400) β€” number of the words in the list. The following n lines contain words, one word per line. Each word consists of only lowercase Latin letters. The length of each word is between 1 and 20 letters inclusive. Output Print the minimal number of groups where the words in each group denote the same name. Examples Input 10 mihail oolyana kooooper hoon ulyana koouper mikhail khun kuooper kkkhoon Output 4 Input 9 hariton hkariton buoi kkkhariton boooi bui khariton boui boi Output 5 Input 2 alex alex Output 1 Note There are four groups of words in the first example. Words in each group denote same name: 1. "mihail", "mikhail" 2. "oolyana", "ulyana" 3. "kooooper", "koouper" 4. "hoon", "khun", "kkkhoon" There are five groups of words in the second example. Words in each group denote same name: 1. "hariton", "kkkhariton", "khariton" 2. "hkariton" 3. "buoi", "boooi", "boui" 4. "bui" 5. "boi" In the third example the words are equal, so they denote the same name. ### Response ```cpp #include <bits/stdc++.h> using namespace std; void err(istream_iterator<string> it) {} template <typename T, typename... Args> void err(istream_iterator<string> it, T a, Args... args) { cerr << *it << " = " << a << endl; err(++it, args...); } const long long mod = pow(10, 9) + 7; const long long N = 3e5, M = N; const long long inf = LLONG_MAX; const long long infn = LLONG_MIN; string convert(string s) { long long n = s.length(), i; while (true) { bool done = 0; for (auto it = s.begin(); it != s.end(); it++) { auto p = it; p++; if (p == s.end()) break; else if (*it == 'k' && *p == 'h') { s.erase(it); it--; done = 1; } } if (!done) break; } string k = ""; for (long long i = 0; i < s.length(); i++) { if (s[i] == 'u') { k += "oo"; } else k += s[i]; } { string _s = "k"; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, k); }; return k; } void iluzn() { long long n; cin >> n; long long k = n; set<string> st; while (n--) { string s; cin >> s; s = convert(s); st.insert(s); } cout << st.size() << "\n"; } signed main() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); long long t = 1; while (t--) iluzn(); return 0; } ```
#include <bits/stdc++.h> using namespace std; set<string> st; int main() { int n; cin >> n; for (int i = 0; i < n; i++) { string s; cin >> s; while (s.find("u") != -1) { int t = s.find("u"); s.erase(t, 1); s.insert(t, "oo"); } while (s.find("kh") != -1) { int t = s.find("kh"); s.erase(t, 2); s.insert(t, "h"); } st.insert(s); } cout << st.size() << endl; return 0; }
### Prompt Construct a Cpp code solution to the problem outlined: There are some ambiguities when one writes Berland names with the letters of the Latin alphabet. For example, the Berland sound u can be written in the Latin alphabet as "u", and can be written as "oo". For this reason, two words "ulyana" and "oolyana" denote the same name. The second ambiguity is about the Berland sound h: one can use both "h" and "kh" to write it. For example, the words "mihail" and "mikhail" denote the same name. There are n users registered on the Polycarp's website. Each of them indicated a name represented by the Latin letters. How many distinct names are there among them, if two ambiguities described above are taken into account? Formally, we assume that two words denote the same name, if using the replacements "u" <image> "oo" and "h" <image> "kh", you can make the words equal. One can make replacements in both directions, in any of the two words an arbitrary number of times. A letter that resulted from the previous replacement can participate in the next replacements. For example, the following pairs of words denote the same name: * "koouper" and "kuooper". Making the replacements described above, you can make both words to be equal: "koouper" <image> "kuuper" and "kuooper" <image> "kuuper". * "khun" and "kkkhoon". With the replacements described above you can make both words to be equal: "khun" <image> "khoon" and "kkkhoon" <image> "kkhoon" <image> "khoon". For a given list of words, find the minimal number of groups where the words in each group denote the same name. Input The first line contains integer number n (2 ≀ n ≀ 400) β€” number of the words in the list. The following n lines contain words, one word per line. Each word consists of only lowercase Latin letters. The length of each word is between 1 and 20 letters inclusive. Output Print the minimal number of groups where the words in each group denote the same name. Examples Input 10 mihail oolyana kooooper hoon ulyana koouper mikhail khun kuooper kkkhoon Output 4 Input 9 hariton hkariton buoi kkkhariton boooi bui khariton boui boi Output 5 Input 2 alex alex Output 1 Note There are four groups of words in the first example. Words in each group denote same name: 1. "mihail", "mikhail" 2. "oolyana", "ulyana" 3. "kooooper", "koouper" 4. "hoon", "khun", "kkkhoon" There are five groups of words in the second example. Words in each group denote same name: 1. "hariton", "kkkhariton", "khariton" 2. "hkariton" 3. "buoi", "boooi", "boui" 4. "bui" 5. "boi" In the third example the words are equal, so they denote the same name. ### Response ```cpp #include <bits/stdc++.h> using namespace std; set<string> st; int main() { int n; cin >> n; for (int i = 0; i < n; i++) { string s; cin >> s; while (s.find("u") != -1) { int t = s.find("u"); s.erase(t, 1); s.insert(t, "oo"); } while (s.find("kh") != -1) { int t = s.find("kh"); s.erase(t, 2); s.insert(t, "h"); } st.insert(s); } cout << st.size() << endl; return 0; } ```
#include <bits/stdc++.h> using namespace std; string parse_word(const string& s) { string s1; if (s[0] == 'u') { s1 = "oo"; } else { s1 = ""; s1.push_back(s[0]); } for (int i = 1; i < int(s.size()); ++i) { if (s[i] == 'u') { s1 += "oo"; } else if (s[i] == 'h') { while (s1.size() != 0 && s1.back() == 'k') s1.pop_back(); s1.push_back(s[i]); } else { s1 += s[i]; } } return s1; } int main() { int n = 0; cin >> n; set<string> ans; for (int i = 0; i < n; ++i) { string s; cin >> s; ans.insert(parse_word(s)); } cout << int(ans.size()) << endl; return 0; }
### Prompt Generate a Cpp solution to the following problem: There are some ambiguities when one writes Berland names with the letters of the Latin alphabet. For example, the Berland sound u can be written in the Latin alphabet as "u", and can be written as "oo". For this reason, two words "ulyana" and "oolyana" denote the same name. The second ambiguity is about the Berland sound h: one can use both "h" and "kh" to write it. For example, the words "mihail" and "mikhail" denote the same name. There are n users registered on the Polycarp's website. Each of them indicated a name represented by the Latin letters. How many distinct names are there among them, if two ambiguities described above are taken into account? Formally, we assume that two words denote the same name, if using the replacements "u" <image> "oo" and "h" <image> "kh", you can make the words equal. One can make replacements in both directions, in any of the two words an arbitrary number of times. A letter that resulted from the previous replacement can participate in the next replacements. For example, the following pairs of words denote the same name: * "koouper" and "kuooper". Making the replacements described above, you can make both words to be equal: "koouper" <image> "kuuper" and "kuooper" <image> "kuuper". * "khun" and "kkkhoon". With the replacements described above you can make both words to be equal: "khun" <image> "khoon" and "kkkhoon" <image> "kkhoon" <image> "khoon". For a given list of words, find the minimal number of groups where the words in each group denote the same name. Input The first line contains integer number n (2 ≀ n ≀ 400) β€” number of the words in the list. The following n lines contain words, one word per line. Each word consists of only lowercase Latin letters. The length of each word is between 1 and 20 letters inclusive. Output Print the minimal number of groups where the words in each group denote the same name. Examples Input 10 mihail oolyana kooooper hoon ulyana koouper mikhail khun kuooper kkkhoon Output 4 Input 9 hariton hkariton buoi kkkhariton boooi bui khariton boui boi Output 5 Input 2 alex alex Output 1 Note There are four groups of words in the first example. Words in each group denote same name: 1. "mihail", "mikhail" 2. "oolyana", "ulyana" 3. "kooooper", "koouper" 4. "hoon", "khun", "kkkhoon" There are five groups of words in the second example. Words in each group denote same name: 1. "hariton", "kkkhariton", "khariton" 2. "hkariton" 3. "buoi", "boooi", "boui" 4. "bui" 5. "boi" In the third example the words are equal, so they denote the same name. ### Response ```cpp #include <bits/stdc++.h> using namespace std; string parse_word(const string& s) { string s1; if (s[0] == 'u') { s1 = "oo"; } else { s1 = ""; s1.push_back(s[0]); } for (int i = 1; i < int(s.size()); ++i) { if (s[i] == 'u') { s1 += "oo"; } else if (s[i] == 'h') { while (s1.size() != 0 && s1.back() == 'k') s1.pop_back(); s1.push_back(s[i]); } else { s1 += s[i]; } } return s1; } int main() { int n = 0; cin >> n; set<string> ans; for (int i = 0; i < n; ++i) { string s; cin >> s; ans.insert(parse_word(s)); } cout << int(ans.size()) << endl; return 0; } ```
#include <bits/stdc++.h> using namespace std; int n; string s; set<string> st; void make(string a, string b) { int t; t = s.find(a); while (t != -1) { s = s.replace(t, a.size(), b); t = s.find(a); } } int main() { cin >> n; for (int i = 0; i < n; ++i) { cin >> s; make("u", "oo"); make("oo", "u"); make("kh", "h"); st.insert(s); } cout << st.size(); getchar(); getchar(); return 0; }
### Prompt Your challenge is to write a cpp solution to the following problem: There are some ambiguities when one writes Berland names with the letters of the Latin alphabet. For example, the Berland sound u can be written in the Latin alphabet as "u", and can be written as "oo". For this reason, two words "ulyana" and "oolyana" denote the same name. The second ambiguity is about the Berland sound h: one can use both "h" and "kh" to write it. For example, the words "mihail" and "mikhail" denote the same name. There are n users registered on the Polycarp's website. Each of them indicated a name represented by the Latin letters. How many distinct names are there among them, if two ambiguities described above are taken into account? Formally, we assume that two words denote the same name, if using the replacements "u" <image> "oo" and "h" <image> "kh", you can make the words equal. One can make replacements in both directions, in any of the two words an arbitrary number of times. A letter that resulted from the previous replacement can participate in the next replacements. For example, the following pairs of words denote the same name: * "koouper" and "kuooper". Making the replacements described above, you can make both words to be equal: "koouper" <image> "kuuper" and "kuooper" <image> "kuuper". * "khun" and "kkkhoon". With the replacements described above you can make both words to be equal: "khun" <image> "khoon" and "kkkhoon" <image> "kkhoon" <image> "khoon". For a given list of words, find the minimal number of groups where the words in each group denote the same name. Input The first line contains integer number n (2 ≀ n ≀ 400) β€” number of the words in the list. The following n lines contain words, one word per line. Each word consists of only lowercase Latin letters. The length of each word is between 1 and 20 letters inclusive. Output Print the minimal number of groups where the words in each group denote the same name. Examples Input 10 mihail oolyana kooooper hoon ulyana koouper mikhail khun kuooper kkkhoon Output 4 Input 9 hariton hkariton buoi kkkhariton boooi bui khariton boui boi Output 5 Input 2 alex alex Output 1 Note There are four groups of words in the first example. Words in each group denote same name: 1. "mihail", "mikhail" 2. "oolyana", "ulyana" 3. "kooooper", "koouper" 4. "hoon", "khun", "kkkhoon" There are five groups of words in the second example. Words in each group denote same name: 1. "hariton", "kkkhariton", "khariton" 2. "hkariton" 3. "buoi", "boooi", "boui" 4. "bui" 5. "boi" In the third example the words are equal, so they denote the same name. ### Response ```cpp #include <bits/stdc++.h> using namespace std; int n; string s; set<string> st; void make(string a, string b) { int t; t = s.find(a); while (t != -1) { s = s.replace(t, a.size(), b); t = s.find(a); } } int main() { cin >> n; for (int i = 0; i < n; ++i) { cin >> s; make("u", "oo"); make("oo", "u"); make("kh", "h"); st.insert(s); } cout << st.size(); getchar(); getchar(); return 0; } ```
#include <bits/stdc++.h> using namespace std; const int maxn = 400; map<string, int> mp; char str[50]; int main() { mp.clear(); int n; scanf("%d", &n); for (int k = 0; k < n; k++) { string tmp = ""; scanf("%s", str); int len = strlen(str); for (int i = len - 1; i >= 0; i--) { if (str[i] == 'h') { while (i - 1 >= 0 && str[i - 1] == 'k') { str[i - 1] = 'A'; i = i - 1; } } } for (int i = 0; i < len; i++) { if (str[i] == 'u') { tmp += 'o'; tmp += 'o'; continue; } if (str[i] != 'A') tmp += str[i]; } tmp += '\0'; mp[tmp] = 1; } printf("%d\n", mp.size()); return 0; }
### Prompt Please create a solution in Cpp to the following problem: There are some ambiguities when one writes Berland names with the letters of the Latin alphabet. For example, the Berland sound u can be written in the Latin alphabet as "u", and can be written as "oo". For this reason, two words "ulyana" and "oolyana" denote the same name. The second ambiguity is about the Berland sound h: one can use both "h" and "kh" to write it. For example, the words "mihail" and "mikhail" denote the same name. There are n users registered on the Polycarp's website. Each of them indicated a name represented by the Latin letters. How many distinct names are there among them, if two ambiguities described above are taken into account? Formally, we assume that two words denote the same name, if using the replacements "u" <image> "oo" and "h" <image> "kh", you can make the words equal. One can make replacements in both directions, in any of the two words an arbitrary number of times. A letter that resulted from the previous replacement can participate in the next replacements. For example, the following pairs of words denote the same name: * "koouper" and "kuooper". Making the replacements described above, you can make both words to be equal: "koouper" <image> "kuuper" and "kuooper" <image> "kuuper". * "khun" and "kkkhoon". With the replacements described above you can make both words to be equal: "khun" <image> "khoon" and "kkkhoon" <image> "kkhoon" <image> "khoon". For a given list of words, find the minimal number of groups where the words in each group denote the same name. Input The first line contains integer number n (2 ≀ n ≀ 400) β€” number of the words in the list. The following n lines contain words, one word per line. Each word consists of only lowercase Latin letters. The length of each word is between 1 and 20 letters inclusive. Output Print the minimal number of groups where the words in each group denote the same name. Examples Input 10 mihail oolyana kooooper hoon ulyana koouper mikhail khun kuooper kkkhoon Output 4 Input 9 hariton hkariton buoi kkkhariton boooi bui khariton boui boi Output 5 Input 2 alex alex Output 1 Note There are four groups of words in the first example. Words in each group denote same name: 1. "mihail", "mikhail" 2. "oolyana", "ulyana" 3. "kooooper", "koouper" 4. "hoon", "khun", "kkkhoon" There are five groups of words in the second example. Words in each group denote same name: 1. "hariton", "kkkhariton", "khariton" 2. "hkariton" 3. "buoi", "boooi", "boui" 4. "bui" 5. "boi" In the third example the words are equal, so they denote the same name. ### Response ```cpp #include <bits/stdc++.h> using namespace std; const int maxn = 400; map<string, int> mp; char str[50]; int main() { mp.clear(); int n; scanf("%d", &n); for (int k = 0; k < n; k++) { string tmp = ""; scanf("%s", str); int len = strlen(str); for (int i = len - 1; i >= 0; i--) { if (str[i] == 'h') { while (i - 1 >= 0 && str[i - 1] == 'k') { str[i - 1] = 'A'; i = i - 1; } } } for (int i = 0; i < len; i++) { if (str[i] == 'u') { tmp += 'o'; tmp += 'o'; continue; } if (str[i] != 'A') tmp += str[i]; } tmp += '\0'; mp[tmp] = 1; } printf("%d\n", mp.size()); return 0; } ```
#include <bits/stdc++.h> using namespace std; int main() { long long n; cin >> n; vector<string> vec(n); for (long long i = 0; i < n; i++) { cin >> vec[i]; } set<string> sec; for (long long i = 0; i < n; i++) { bool change = true; while (change) { change = false; for (long long j = 0; j < vec[i].size() - 1; j++) { if (vec[i][j] == 'o' && vec[i][j + 1] == 'o') { vec[i].erase(vec[i].begin() + j + 1); vec[i][j] = 'u'; j--; change = true; continue; } if (vec[i][j] == 'k' && vec[i][j + 1] == 'h') { vec[i].erase(vec[i].begin() + j + 1); vec[i][j] = 'h'; j--; change = true; continue; } if (vec[i][j] == 'o' && vec[i][j + 1] == 'u') { vec[i][j] = 'u'; vec[i][j + 1] = 'o'; change = true; continue; } } } sec.insert(vec[i]); } cout << sec.size() << endl; return 0; }
### Prompt Create a solution in CPP for the following problem: There are some ambiguities when one writes Berland names with the letters of the Latin alphabet. For example, the Berland sound u can be written in the Latin alphabet as "u", and can be written as "oo". For this reason, two words "ulyana" and "oolyana" denote the same name. The second ambiguity is about the Berland sound h: one can use both "h" and "kh" to write it. For example, the words "mihail" and "mikhail" denote the same name. There are n users registered on the Polycarp's website. Each of them indicated a name represented by the Latin letters. How many distinct names are there among them, if two ambiguities described above are taken into account? Formally, we assume that two words denote the same name, if using the replacements "u" <image> "oo" and "h" <image> "kh", you can make the words equal. One can make replacements in both directions, in any of the two words an arbitrary number of times. A letter that resulted from the previous replacement can participate in the next replacements. For example, the following pairs of words denote the same name: * "koouper" and "kuooper". Making the replacements described above, you can make both words to be equal: "koouper" <image> "kuuper" and "kuooper" <image> "kuuper". * "khun" and "kkkhoon". With the replacements described above you can make both words to be equal: "khun" <image> "khoon" and "kkkhoon" <image> "kkhoon" <image> "khoon". For a given list of words, find the minimal number of groups where the words in each group denote the same name. Input The first line contains integer number n (2 ≀ n ≀ 400) β€” number of the words in the list. The following n lines contain words, one word per line. Each word consists of only lowercase Latin letters. The length of each word is between 1 and 20 letters inclusive. Output Print the minimal number of groups where the words in each group denote the same name. Examples Input 10 mihail oolyana kooooper hoon ulyana koouper mikhail khun kuooper kkkhoon Output 4 Input 9 hariton hkariton buoi kkkhariton boooi bui khariton boui boi Output 5 Input 2 alex alex Output 1 Note There are four groups of words in the first example. Words in each group denote same name: 1. "mihail", "mikhail" 2. "oolyana", "ulyana" 3. "kooooper", "koouper" 4. "hoon", "khun", "kkkhoon" There are five groups of words in the second example. Words in each group denote same name: 1. "hariton", "kkkhariton", "khariton" 2. "hkariton" 3. "buoi", "boooi", "boui" 4. "bui" 5. "boi" In the third example the words are equal, so they denote the same name. ### Response ```cpp #include <bits/stdc++.h> using namespace std; int main() { long long n; cin >> n; vector<string> vec(n); for (long long i = 0; i < n; i++) { cin >> vec[i]; } set<string> sec; for (long long i = 0; i < n; i++) { bool change = true; while (change) { change = false; for (long long j = 0; j < vec[i].size() - 1; j++) { if (vec[i][j] == 'o' && vec[i][j + 1] == 'o') { vec[i].erase(vec[i].begin() + j + 1); vec[i][j] = 'u'; j--; change = true; continue; } if (vec[i][j] == 'k' && vec[i][j + 1] == 'h') { vec[i].erase(vec[i].begin() + j + 1); vec[i][j] = 'h'; j--; change = true; continue; } if (vec[i][j] == 'o' && vec[i][j + 1] == 'u') { vec[i][j] = 'u'; vec[i][j + 1] = 'o'; change = true; continue; } } } sec.insert(vec[i]); } cout << sec.size() << endl; return 0; } ```
#include <bits/stdc++.h> using namespace std; int main() { set<string> st; string str; int n; while (scanf("%d", &n) != EOF) { for (int i = 0; i < n; i++) { cin >> str; for (int j = str.size(); j >= 0; j--) { if (str[j] == 'u') str.replace(j, 1, "oo"); else if (str[j] == 'k' && str[j + 1] == 'h') { str.replace(j, 2, "h"); } } st.insert(str); } cout << st.size() << endl; } }
### Prompt Develop a solution in Cpp to the problem described below: There are some ambiguities when one writes Berland names with the letters of the Latin alphabet. For example, the Berland sound u can be written in the Latin alphabet as "u", and can be written as "oo". For this reason, two words "ulyana" and "oolyana" denote the same name. The second ambiguity is about the Berland sound h: one can use both "h" and "kh" to write it. For example, the words "mihail" and "mikhail" denote the same name. There are n users registered on the Polycarp's website. Each of them indicated a name represented by the Latin letters. How many distinct names are there among them, if two ambiguities described above are taken into account? Formally, we assume that two words denote the same name, if using the replacements "u" <image> "oo" and "h" <image> "kh", you can make the words equal. One can make replacements in both directions, in any of the two words an arbitrary number of times. A letter that resulted from the previous replacement can participate in the next replacements. For example, the following pairs of words denote the same name: * "koouper" and "kuooper". Making the replacements described above, you can make both words to be equal: "koouper" <image> "kuuper" and "kuooper" <image> "kuuper". * "khun" and "kkkhoon". With the replacements described above you can make both words to be equal: "khun" <image> "khoon" and "kkkhoon" <image> "kkhoon" <image> "khoon". For a given list of words, find the minimal number of groups where the words in each group denote the same name. Input The first line contains integer number n (2 ≀ n ≀ 400) β€” number of the words in the list. The following n lines contain words, one word per line. Each word consists of only lowercase Latin letters. The length of each word is between 1 and 20 letters inclusive. Output Print the minimal number of groups where the words in each group denote the same name. Examples Input 10 mihail oolyana kooooper hoon ulyana koouper mikhail khun kuooper kkkhoon Output 4 Input 9 hariton hkariton buoi kkkhariton boooi bui khariton boui boi Output 5 Input 2 alex alex Output 1 Note There are four groups of words in the first example. Words in each group denote same name: 1. "mihail", "mikhail" 2. "oolyana", "ulyana" 3. "kooooper", "koouper" 4. "hoon", "khun", "kkkhoon" There are five groups of words in the second example. Words in each group denote same name: 1. "hariton", "kkkhariton", "khariton" 2. "hkariton" 3. "buoi", "boooi", "boui" 4. "bui" 5. "boi" In the third example the words are equal, so they denote the same name. ### Response ```cpp #include <bits/stdc++.h> using namespace std; int main() { set<string> st; string str; int n; while (scanf("%d", &n) != EOF) { for (int i = 0; i < n; i++) { cin >> str; for (int j = str.size(); j >= 0; j--) { if (str[j] == 'u') str.replace(j, 1, "oo"); else if (str[j] == 'k' && str[j + 1] == 'h') { str.replace(j, 2, "h"); } } st.insert(str); } cout << st.size() << endl; } } ```
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; cin >> n; set<string> s; for (int i = 0; i < n; i++) { string cur; cin >> cur; while (1) { bool flg = 1; string now; for (int i = 0; i < cur.length(); i++) { if (cur[i] == 'u') { flg = 0; now.push_back('o'); now.push_back('o'); for (int j = i + 1; j < cur.length(); j++) now.push_back(cur[j]); break; } if (i + 1 < cur.length() && cur[i] == 'k' && cur[i + 1] == 'h') { flg = 0; now.push_back('h'); for (int j = i + 2; j < cur.length(); j++) now.push_back(cur[j]); break; } now.push_back(cur[i]); } if (flg) { cur = now; break; } cur = now; } s.insert(cur); } cout << s.size() << "\n"; return 0; }
### Prompt Create a solution in cpp for the following problem: There are some ambiguities when one writes Berland names with the letters of the Latin alphabet. For example, the Berland sound u can be written in the Latin alphabet as "u", and can be written as "oo". For this reason, two words "ulyana" and "oolyana" denote the same name. The second ambiguity is about the Berland sound h: one can use both "h" and "kh" to write it. For example, the words "mihail" and "mikhail" denote the same name. There are n users registered on the Polycarp's website. Each of them indicated a name represented by the Latin letters. How many distinct names are there among them, if two ambiguities described above are taken into account? Formally, we assume that two words denote the same name, if using the replacements "u" <image> "oo" and "h" <image> "kh", you can make the words equal. One can make replacements in both directions, in any of the two words an arbitrary number of times. A letter that resulted from the previous replacement can participate in the next replacements. For example, the following pairs of words denote the same name: * "koouper" and "kuooper". Making the replacements described above, you can make both words to be equal: "koouper" <image> "kuuper" and "kuooper" <image> "kuuper". * "khun" and "kkkhoon". With the replacements described above you can make both words to be equal: "khun" <image> "khoon" and "kkkhoon" <image> "kkhoon" <image> "khoon". For a given list of words, find the minimal number of groups where the words in each group denote the same name. Input The first line contains integer number n (2 ≀ n ≀ 400) β€” number of the words in the list. The following n lines contain words, one word per line. Each word consists of only lowercase Latin letters. The length of each word is between 1 and 20 letters inclusive. Output Print the minimal number of groups where the words in each group denote the same name. Examples Input 10 mihail oolyana kooooper hoon ulyana koouper mikhail khun kuooper kkkhoon Output 4 Input 9 hariton hkariton buoi kkkhariton boooi bui khariton boui boi Output 5 Input 2 alex alex Output 1 Note There are four groups of words in the first example. Words in each group denote same name: 1. "mihail", "mikhail" 2. "oolyana", "ulyana" 3. "kooooper", "koouper" 4. "hoon", "khun", "kkkhoon" There are five groups of words in the second example. Words in each group denote same name: 1. "hariton", "kkkhariton", "khariton" 2. "hkariton" 3. "buoi", "boooi", "boui" 4. "bui" 5. "boi" In the third example the words are equal, so they denote the same name. ### Response ```cpp #include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; cin >> n; set<string> s; for (int i = 0; i < n; i++) { string cur; cin >> cur; while (1) { bool flg = 1; string now; for (int i = 0; i < cur.length(); i++) { if (cur[i] == 'u') { flg = 0; now.push_back('o'); now.push_back('o'); for (int j = i + 1; j < cur.length(); j++) now.push_back(cur[j]); break; } if (i + 1 < cur.length() && cur[i] == 'k' && cur[i + 1] == 'h') { flg = 0; now.push_back('h'); for (int j = i + 2; j < cur.length(); j++) now.push_back(cur[j]); break; } now.push_back(cur[i]); } if (flg) { cur = now; break; } cur = now; } s.insert(cur); } cout << s.size() << "\n"; return 0; } ```
#include <bits/stdc++.h> using namespace std; const int MAXN = 403; int n; string words[MAXN]; vector<int> adj[MAXN]; bool vis[MAXN]; string reduce(string a) { string res; for (int i = 0; i < a.size(); i++) { if (a[i] == 'u') { res.push_back('o'); res.push_back('o'); } else if (a[i] == 'k') { int st = i; while (st + 1 < a.size() and a[st + 1] == 'k') st++; if (a[st + 1] == 'h') { i = st + 1; res.push_back('h'); } else { res.push_back(a[i]); } } else { res.push_back(a[i]); } } return res; } bool Edge(string &a, string &b) { string A = reduce(a), B = reduce(b); return A == B; } void Dfs(int r) { if (vis[r]) return; vis[r] = true; for (int c : adj[r]) { if (vis[c] == false) { Dfs(c); } } } int main() { ios_base::sync_with_stdio(false); cin >> n; for (int i = 1; i <= n; i++) { cin >> words[i]; } for (int i = 1; i <= n; i++) { for (int j = i + 1; j <= n; j++) { if (Edge(words[i], words[j])) { adj[i].push_back(j); adj[j].push_back(i); } } } int res = 0; for (int i = 1; i <= n; i++) { if (vis[i] == false) { res++; Dfs(i); } } cout << res << '\n'; return 0; }
### Prompt Your task is to create a CPP solution to the following problem: There are some ambiguities when one writes Berland names with the letters of the Latin alphabet. For example, the Berland sound u can be written in the Latin alphabet as "u", and can be written as "oo". For this reason, two words "ulyana" and "oolyana" denote the same name. The second ambiguity is about the Berland sound h: one can use both "h" and "kh" to write it. For example, the words "mihail" and "mikhail" denote the same name. There are n users registered on the Polycarp's website. Each of them indicated a name represented by the Latin letters. How many distinct names are there among them, if two ambiguities described above are taken into account? Formally, we assume that two words denote the same name, if using the replacements "u" <image> "oo" and "h" <image> "kh", you can make the words equal. One can make replacements in both directions, in any of the two words an arbitrary number of times. A letter that resulted from the previous replacement can participate in the next replacements. For example, the following pairs of words denote the same name: * "koouper" and "kuooper". Making the replacements described above, you can make both words to be equal: "koouper" <image> "kuuper" and "kuooper" <image> "kuuper". * "khun" and "kkkhoon". With the replacements described above you can make both words to be equal: "khun" <image> "khoon" and "kkkhoon" <image> "kkhoon" <image> "khoon". For a given list of words, find the minimal number of groups where the words in each group denote the same name. Input The first line contains integer number n (2 ≀ n ≀ 400) β€” number of the words in the list. The following n lines contain words, one word per line. Each word consists of only lowercase Latin letters. The length of each word is between 1 and 20 letters inclusive. Output Print the minimal number of groups where the words in each group denote the same name. Examples Input 10 mihail oolyana kooooper hoon ulyana koouper mikhail khun kuooper kkkhoon Output 4 Input 9 hariton hkariton buoi kkkhariton boooi bui khariton boui boi Output 5 Input 2 alex alex Output 1 Note There are four groups of words in the first example. Words in each group denote same name: 1. "mihail", "mikhail" 2. "oolyana", "ulyana" 3. "kooooper", "koouper" 4. "hoon", "khun", "kkkhoon" There are five groups of words in the second example. Words in each group denote same name: 1. "hariton", "kkkhariton", "khariton" 2. "hkariton" 3. "buoi", "boooi", "boui" 4. "bui" 5. "boi" In the third example the words are equal, so they denote the same name. ### Response ```cpp #include <bits/stdc++.h> using namespace std; const int MAXN = 403; int n; string words[MAXN]; vector<int> adj[MAXN]; bool vis[MAXN]; string reduce(string a) { string res; for (int i = 0; i < a.size(); i++) { if (a[i] == 'u') { res.push_back('o'); res.push_back('o'); } else if (a[i] == 'k') { int st = i; while (st + 1 < a.size() and a[st + 1] == 'k') st++; if (a[st + 1] == 'h') { i = st + 1; res.push_back('h'); } else { res.push_back(a[i]); } } else { res.push_back(a[i]); } } return res; } bool Edge(string &a, string &b) { string A = reduce(a), B = reduce(b); return A == B; } void Dfs(int r) { if (vis[r]) return; vis[r] = true; for (int c : adj[r]) { if (vis[c] == false) { Dfs(c); } } } int main() { ios_base::sync_with_stdio(false); cin >> n; for (int i = 1; i <= n; i++) { cin >> words[i]; } for (int i = 1; i <= n; i++) { for (int j = i + 1; j <= n; j++) { if (Edge(words[i], words[j])) { adj[i].push_back(j); adj[j].push_back(i); } } } int res = 0; for (int i = 1; i <= n; i++) { if (vis[i] == false) { res++; Dfs(i); } } cout << res << '\n'; return 0; } ```
#include <bits/stdc++.h> using namespace std; const int MXN = (int)4e2 + 7; string s[MXN]; bool die[MXN]; void sub(int p) { string s1 = s[p]; int l1 = s1.length(); for (int i = 0; i < l1; ++i) if (s1[i] == 'u') { s1 = s1.substr(0, i) + "oo" + s1.substr(i + 1, l1 - i - 1); l1++; } for (int i = l1 - 1; i >= 0; --i) { if (s1[i] == 'h') { if (i && s1[i - 1] == 'k') { s1 = s1.substr(0, i - 1) + s1.substr(i, l1 - i); l1--; i++; } } } s[p] = s1; return; } int main(void) { ios_base::sync_with_stdio(0); cin.tie(0); int n; cin >> n; for (int i = 1; i < n + 1; ++i) cin >> s[i]; for (int i = 1; i < n + 1; ++i) sub(i); for (int i = 1; i < n + 1; ++i) if (!die[i]) { for (int j = i + 1; j < n + 1; ++j) if (!die[j]) { if (s[i] == s[j]) die[j] = 1; } } int ans = 0; for (int i = 1; i < n + 1; ++i) if (!die[i]) ans++; cout << ans << endl; return 0; }
### Prompt Your challenge is to write a Cpp solution to the following problem: There are some ambiguities when one writes Berland names with the letters of the Latin alphabet. For example, the Berland sound u can be written in the Latin alphabet as "u", and can be written as "oo". For this reason, two words "ulyana" and "oolyana" denote the same name. The second ambiguity is about the Berland sound h: one can use both "h" and "kh" to write it. For example, the words "mihail" and "mikhail" denote the same name. There are n users registered on the Polycarp's website. Each of them indicated a name represented by the Latin letters. How many distinct names are there among them, if two ambiguities described above are taken into account? Formally, we assume that two words denote the same name, if using the replacements "u" <image> "oo" and "h" <image> "kh", you can make the words equal. One can make replacements in both directions, in any of the two words an arbitrary number of times. A letter that resulted from the previous replacement can participate in the next replacements. For example, the following pairs of words denote the same name: * "koouper" and "kuooper". Making the replacements described above, you can make both words to be equal: "koouper" <image> "kuuper" and "kuooper" <image> "kuuper". * "khun" and "kkkhoon". With the replacements described above you can make both words to be equal: "khun" <image> "khoon" and "kkkhoon" <image> "kkhoon" <image> "khoon". For a given list of words, find the minimal number of groups where the words in each group denote the same name. Input The first line contains integer number n (2 ≀ n ≀ 400) β€” number of the words in the list. The following n lines contain words, one word per line. Each word consists of only lowercase Latin letters. The length of each word is between 1 and 20 letters inclusive. Output Print the minimal number of groups where the words in each group denote the same name. Examples Input 10 mihail oolyana kooooper hoon ulyana koouper mikhail khun kuooper kkkhoon Output 4 Input 9 hariton hkariton buoi kkkhariton boooi bui khariton boui boi Output 5 Input 2 alex alex Output 1 Note There are four groups of words in the first example. Words in each group denote same name: 1. "mihail", "mikhail" 2. "oolyana", "ulyana" 3. "kooooper", "koouper" 4. "hoon", "khun", "kkkhoon" There are five groups of words in the second example. Words in each group denote same name: 1. "hariton", "kkkhariton", "khariton" 2. "hkariton" 3. "buoi", "boooi", "boui" 4. "bui" 5. "boi" In the third example the words are equal, so they denote the same name. ### Response ```cpp #include <bits/stdc++.h> using namespace std; const int MXN = (int)4e2 + 7; string s[MXN]; bool die[MXN]; void sub(int p) { string s1 = s[p]; int l1 = s1.length(); for (int i = 0; i < l1; ++i) if (s1[i] == 'u') { s1 = s1.substr(0, i) + "oo" + s1.substr(i + 1, l1 - i - 1); l1++; } for (int i = l1 - 1; i >= 0; --i) { if (s1[i] == 'h') { if (i && s1[i - 1] == 'k') { s1 = s1.substr(0, i - 1) + s1.substr(i, l1 - i); l1--; i++; } } } s[p] = s1; return; } int main(void) { ios_base::sync_with_stdio(0); cin.tie(0); int n; cin >> n; for (int i = 1; i < n + 1; ++i) cin >> s[i]; for (int i = 1; i < n + 1; ++i) sub(i); for (int i = 1; i < n + 1; ++i) if (!die[i]) { for (int j = i + 1; j < n + 1; ++j) if (!die[j]) { if (s[i] == s[j]) die[j] = 1; } } int ans = 0; for (int i = 1; i < n + 1; ++i) if (!die[i]) ans++; cout << ans << endl; return 0; } ```
#include <bits/stdc++.h> using namespace std; map<string, long long int> mp; string reduce(string str) { string tempstr; long long int i; for (i = 0; i < str.length(); i++) { if (str[i] == 'u') { tempstr += "oo"; } else { tempstr += str[i]; } } string newstr; for (i = tempstr.length() - 1; i >= 0; i--) { if (tempstr[i] == 'h' && tempstr[i - 1] == 'k') { while (tempstr[i - 1] == 'k') { i--; } newstr += 'h'; } else { newstr += tempstr[i]; } } reverse(newstr.begin(), newstr.end()); tempstr = newstr; newstr.clear(); for (i = 0; i < tempstr.length(); i++) { if (tempstr[i] == 'o' && tempstr[i + 1] == 'o') { newstr += 'u'; i++; } else { newstr += tempstr[i]; } } return newstr; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long int n, i; cin >> n; string str; for (i = 0; i < n; i++) { cin >> str; mp[reduce(str)]++; } cout << mp.size(); return 0; }
### Prompt Please create a solution in CPP to the following problem: There are some ambiguities when one writes Berland names with the letters of the Latin alphabet. For example, the Berland sound u can be written in the Latin alphabet as "u", and can be written as "oo". For this reason, two words "ulyana" and "oolyana" denote the same name. The second ambiguity is about the Berland sound h: one can use both "h" and "kh" to write it. For example, the words "mihail" and "mikhail" denote the same name. There are n users registered on the Polycarp's website. Each of them indicated a name represented by the Latin letters. How many distinct names are there among them, if two ambiguities described above are taken into account? Formally, we assume that two words denote the same name, if using the replacements "u" <image> "oo" and "h" <image> "kh", you can make the words equal. One can make replacements in both directions, in any of the two words an arbitrary number of times. A letter that resulted from the previous replacement can participate in the next replacements. For example, the following pairs of words denote the same name: * "koouper" and "kuooper". Making the replacements described above, you can make both words to be equal: "koouper" <image> "kuuper" and "kuooper" <image> "kuuper". * "khun" and "kkkhoon". With the replacements described above you can make both words to be equal: "khun" <image> "khoon" and "kkkhoon" <image> "kkhoon" <image> "khoon". For a given list of words, find the minimal number of groups where the words in each group denote the same name. Input The first line contains integer number n (2 ≀ n ≀ 400) β€” number of the words in the list. The following n lines contain words, one word per line. Each word consists of only lowercase Latin letters. The length of each word is between 1 and 20 letters inclusive. Output Print the minimal number of groups where the words in each group denote the same name. Examples Input 10 mihail oolyana kooooper hoon ulyana koouper mikhail khun kuooper kkkhoon Output 4 Input 9 hariton hkariton buoi kkkhariton boooi bui khariton boui boi Output 5 Input 2 alex alex Output 1 Note There are four groups of words in the first example. Words in each group denote same name: 1. "mihail", "mikhail" 2. "oolyana", "ulyana" 3. "kooooper", "koouper" 4. "hoon", "khun", "kkkhoon" There are five groups of words in the second example. Words in each group denote same name: 1. "hariton", "kkkhariton", "khariton" 2. "hkariton" 3. "buoi", "boooi", "boui" 4. "bui" 5. "boi" In the third example the words are equal, so they denote the same name. ### Response ```cpp #include <bits/stdc++.h> using namespace std; map<string, long long int> mp; string reduce(string str) { string tempstr; long long int i; for (i = 0; i < str.length(); i++) { if (str[i] == 'u') { tempstr += "oo"; } else { tempstr += str[i]; } } string newstr; for (i = tempstr.length() - 1; i >= 0; i--) { if (tempstr[i] == 'h' && tempstr[i - 1] == 'k') { while (tempstr[i - 1] == 'k') { i--; } newstr += 'h'; } else { newstr += tempstr[i]; } } reverse(newstr.begin(), newstr.end()); tempstr = newstr; newstr.clear(); for (i = 0; i < tempstr.length(); i++) { if (tempstr[i] == 'o' && tempstr[i + 1] == 'o') { newstr += 'u'; i++; } else { newstr += tempstr[i]; } } return newstr; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long int n, i; cin >> n; string str; for (i = 0; i < n; i++) { cin >> str; mp[reduce(str)]++; } cout << mp.size(); return 0; } ```
#include <bits/stdc++.h> using namespace std; vector<string> s(1000); bool a[500][500]; bool used[500]; long long num[500]; long long n; bool same(string a, string b) { long long i; vector<char> one, two; for (i = 0; i < a.size(); i++) { one.push_back(a[i]); long long t = one.size(); if (one[t - 1] == 'u') { one.pop_back(); one.push_back('o'); one.push_back('o'); } t = one.size(); while (one[t - 1] == 'h' && one[t - 2] == 'k' && t > 1) { one.pop_back(); one.pop_back(); one.push_back('h'); t = one.size(); } } for (i = 0; i < b.size(); i++) { two.push_back(b[i]); long long t = two.size(); if (two[t - 1] == 'u') { two.pop_back(); two.push_back('o'); two.push_back('o'); } t = two.size(); while (two[t - 1] == 'h' && two[t - 2] == 'k' && t > 1) { two.pop_back(); two.pop_back(); two.push_back('h'); t = two.size(); } } if (one == two) return true; else return false; } void dfs(long long start, long long group) { used[start] = true; num[start] = group; for (long long i = 1; i <= n; i++) { if (a[start][i] && !used[i]) { dfs(i, group); } } } int main() { cin >> n; long long i, j; for (i = 1; i <= n; i++) cin >> s[i]; for (i = 1; i <= n; i++) for (j = 1; j <= n; j++) { if (same(s[i], s[j])) { a[i][j] = true; a[i][j] = true; } else { a[i][j] = false; a[i][j] = false; } } long long ans = 0; for (i = 1; i <= n; i++) { if (num[i] == 0) { ans = ans + 1; dfs(i, ans); } } cout << ans; return 0; }
### Prompt Construct a cpp code solution to the problem outlined: There are some ambiguities when one writes Berland names with the letters of the Latin alphabet. For example, the Berland sound u can be written in the Latin alphabet as "u", and can be written as "oo". For this reason, two words "ulyana" and "oolyana" denote the same name. The second ambiguity is about the Berland sound h: one can use both "h" and "kh" to write it. For example, the words "mihail" and "mikhail" denote the same name. There are n users registered on the Polycarp's website. Each of them indicated a name represented by the Latin letters. How many distinct names are there among them, if two ambiguities described above are taken into account? Formally, we assume that two words denote the same name, if using the replacements "u" <image> "oo" and "h" <image> "kh", you can make the words equal. One can make replacements in both directions, in any of the two words an arbitrary number of times. A letter that resulted from the previous replacement can participate in the next replacements. For example, the following pairs of words denote the same name: * "koouper" and "kuooper". Making the replacements described above, you can make both words to be equal: "koouper" <image> "kuuper" and "kuooper" <image> "kuuper". * "khun" and "kkkhoon". With the replacements described above you can make both words to be equal: "khun" <image> "khoon" and "kkkhoon" <image> "kkhoon" <image> "khoon". For a given list of words, find the minimal number of groups where the words in each group denote the same name. Input The first line contains integer number n (2 ≀ n ≀ 400) β€” number of the words in the list. The following n lines contain words, one word per line. Each word consists of only lowercase Latin letters. The length of each word is between 1 and 20 letters inclusive. Output Print the minimal number of groups where the words in each group denote the same name. Examples Input 10 mihail oolyana kooooper hoon ulyana koouper mikhail khun kuooper kkkhoon Output 4 Input 9 hariton hkariton buoi kkkhariton boooi bui khariton boui boi Output 5 Input 2 alex alex Output 1 Note There are four groups of words in the first example. Words in each group denote same name: 1. "mihail", "mikhail" 2. "oolyana", "ulyana" 3. "kooooper", "koouper" 4. "hoon", "khun", "kkkhoon" There are five groups of words in the second example. Words in each group denote same name: 1. "hariton", "kkkhariton", "khariton" 2. "hkariton" 3. "buoi", "boooi", "boui" 4. "bui" 5. "boi" In the third example the words are equal, so they denote the same name. ### Response ```cpp #include <bits/stdc++.h> using namespace std; vector<string> s(1000); bool a[500][500]; bool used[500]; long long num[500]; long long n; bool same(string a, string b) { long long i; vector<char> one, two; for (i = 0; i < a.size(); i++) { one.push_back(a[i]); long long t = one.size(); if (one[t - 1] == 'u') { one.pop_back(); one.push_back('o'); one.push_back('o'); } t = one.size(); while (one[t - 1] == 'h' && one[t - 2] == 'k' && t > 1) { one.pop_back(); one.pop_back(); one.push_back('h'); t = one.size(); } } for (i = 0; i < b.size(); i++) { two.push_back(b[i]); long long t = two.size(); if (two[t - 1] == 'u') { two.pop_back(); two.push_back('o'); two.push_back('o'); } t = two.size(); while (two[t - 1] == 'h' && two[t - 2] == 'k' && t > 1) { two.pop_back(); two.pop_back(); two.push_back('h'); t = two.size(); } } if (one == two) return true; else return false; } void dfs(long long start, long long group) { used[start] = true; num[start] = group; for (long long i = 1; i <= n; i++) { if (a[start][i] && !used[i]) { dfs(i, group); } } } int main() { cin >> n; long long i, j; for (i = 1; i <= n; i++) cin >> s[i]; for (i = 1; i <= n; i++) for (j = 1; j <= n; j++) { if (same(s[i], s[j])) { a[i][j] = true; a[i][j] = true; } else { a[i][j] = false; a[i][j] = false; } } long long ans = 0; for (i = 1; i <= n; i++) { if (num[i] == 0) { ans = ans + 1; dfs(i, ans); } } cout << ans; return 0; } ```
#include <bits/stdc++.h> using namespace std; int fa[500]; char st[500][50]; int Find(int x) { return fa[x] == x ? x : fa[x] = Find(fa[x]); } bool judge(char *ss, char *tt) { int len = strlen(ss); int len2 = strlen(tt); char s[50], t[50]; for (int i = 0; i < len; i++) s[i] = ss[i]; for (int i = 0; i < len2; i++) t[i] = tt[i]; int i = 0, j = 0; while (i < len && j < len2) { if (s[i] == t[j]) i++, j++; else { if (s[i] == 'o' && t[j] == 'u') { i++; t[j] = 'o'; } else if (s[i] == 'u' && t[j] == 'o') { s[i] = 'o'; j++; } else if (s[i] == 'h' && t[j] == 'k') { int k; for (k = j + 1; k < len2; k++) { if (t[k] != 'k') break; } if (k == len2 || t[k] != 'h') return false; else { i++, j = k + 1; } } else if (t[j] == 'h' && s[i] == 'k') { int k; for (k = i + 1; k < len; k++) { if (s[k] != 'k') break; } if (k == len || s[k] != 'h') return false; else { j++; i = k + 1; } } else return false; } } if (i == len && j == len2) return true; return false; } int main() { int n; cin >> n; for (int i = 1; i <= n; i++) scanf("%s", st[i]); for (int i = 1; i <= n; i++) fa[i] = i; for (int i = 1; i <= n; i++) { if (fa[i] != i) continue; for (int j = i + 1; j <= n; j++) { if (fa[j] != j) continue; if (judge(st[i], st[j])) { fa[j] = i; } } } int ans = 0; for (int i = 1; i <= n; i++) if (fa[i] == i) ans++; cout << ans << endl; return 0; }
### Prompt Create a solution in Cpp for the following problem: There are some ambiguities when one writes Berland names with the letters of the Latin alphabet. For example, the Berland sound u can be written in the Latin alphabet as "u", and can be written as "oo". For this reason, two words "ulyana" and "oolyana" denote the same name. The second ambiguity is about the Berland sound h: one can use both "h" and "kh" to write it. For example, the words "mihail" and "mikhail" denote the same name. There are n users registered on the Polycarp's website. Each of them indicated a name represented by the Latin letters. How many distinct names are there among them, if two ambiguities described above are taken into account? Formally, we assume that two words denote the same name, if using the replacements "u" <image> "oo" and "h" <image> "kh", you can make the words equal. One can make replacements in both directions, in any of the two words an arbitrary number of times. A letter that resulted from the previous replacement can participate in the next replacements. For example, the following pairs of words denote the same name: * "koouper" and "kuooper". Making the replacements described above, you can make both words to be equal: "koouper" <image> "kuuper" and "kuooper" <image> "kuuper". * "khun" and "kkkhoon". With the replacements described above you can make both words to be equal: "khun" <image> "khoon" and "kkkhoon" <image> "kkhoon" <image> "khoon". For a given list of words, find the minimal number of groups where the words in each group denote the same name. Input The first line contains integer number n (2 ≀ n ≀ 400) β€” number of the words in the list. The following n lines contain words, one word per line. Each word consists of only lowercase Latin letters. The length of each word is between 1 and 20 letters inclusive. Output Print the minimal number of groups where the words in each group denote the same name. Examples Input 10 mihail oolyana kooooper hoon ulyana koouper mikhail khun kuooper kkkhoon Output 4 Input 9 hariton hkariton buoi kkkhariton boooi bui khariton boui boi Output 5 Input 2 alex alex Output 1 Note There are four groups of words in the first example. Words in each group denote same name: 1. "mihail", "mikhail" 2. "oolyana", "ulyana" 3. "kooooper", "koouper" 4. "hoon", "khun", "kkkhoon" There are five groups of words in the second example. Words in each group denote same name: 1. "hariton", "kkkhariton", "khariton" 2. "hkariton" 3. "buoi", "boooi", "boui" 4. "bui" 5. "boi" In the third example the words are equal, so they denote the same name. ### Response ```cpp #include <bits/stdc++.h> using namespace std; int fa[500]; char st[500][50]; int Find(int x) { return fa[x] == x ? x : fa[x] = Find(fa[x]); } bool judge(char *ss, char *tt) { int len = strlen(ss); int len2 = strlen(tt); char s[50], t[50]; for (int i = 0; i < len; i++) s[i] = ss[i]; for (int i = 0; i < len2; i++) t[i] = tt[i]; int i = 0, j = 0; while (i < len && j < len2) { if (s[i] == t[j]) i++, j++; else { if (s[i] == 'o' && t[j] == 'u') { i++; t[j] = 'o'; } else if (s[i] == 'u' && t[j] == 'o') { s[i] = 'o'; j++; } else if (s[i] == 'h' && t[j] == 'k') { int k; for (k = j + 1; k < len2; k++) { if (t[k] != 'k') break; } if (k == len2 || t[k] != 'h') return false; else { i++, j = k + 1; } } else if (t[j] == 'h' && s[i] == 'k') { int k; for (k = i + 1; k < len; k++) { if (s[k] != 'k') break; } if (k == len || s[k] != 'h') return false; else { j++; i = k + 1; } } else return false; } } if (i == len && j == len2) return true; return false; } int main() { int n; cin >> n; for (int i = 1; i <= n; i++) scanf("%s", st[i]); for (int i = 1; i <= n; i++) fa[i] = i; for (int i = 1; i <= n; i++) { if (fa[i] != i) continue; for (int j = i + 1; j <= n; j++) { if (fa[j] != j) continue; if (judge(st[i], st[j])) { fa[j] = i; } } } int ans = 0; for (int i = 1; i <= n; i++) if (fa[i] == i) ans++; cout << ans << endl; return 0; } ```
#include <bits/stdc++.h> using namespace std; string str[409]; map<string, int> mapp; int ans = 0; void check(string now) { string cc = ""; int si = now.size(); for (int i = 0; i < si; i++) { if (now[i] == 'u') { cc += "oo"; } else { cc += now[i]; } } string aa = ""; si = cc.size(); int fl = 0; for (int i = si - 1; i >= 0; i--) { if (cc[i] == 'h') { fl = 1; } if (cc[i] == 'k' && fl == 1) { continue; } if (cc[i] != 'h' && cc[i] != 'k') { fl = 0; } aa = cc[i] + aa; } if (mapp.find(aa) == mapp.end()) { ans++; mapp[aa] = 1; } } int main() { int n; cin >> n; for (int i = 1; i <= n; i++) { cin >> str[i]; } for (int i = 1; i <= n; i++) { check(str[i]); } cout << ans << endl; return 0; }
### Prompt Construct a cpp code solution to the problem outlined: There are some ambiguities when one writes Berland names with the letters of the Latin alphabet. For example, the Berland sound u can be written in the Latin alphabet as "u", and can be written as "oo". For this reason, two words "ulyana" and "oolyana" denote the same name. The second ambiguity is about the Berland sound h: one can use both "h" and "kh" to write it. For example, the words "mihail" and "mikhail" denote the same name. There are n users registered on the Polycarp's website. Each of them indicated a name represented by the Latin letters. How many distinct names are there among them, if two ambiguities described above are taken into account? Formally, we assume that two words denote the same name, if using the replacements "u" <image> "oo" and "h" <image> "kh", you can make the words equal. One can make replacements in both directions, in any of the two words an arbitrary number of times. A letter that resulted from the previous replacement can participate in the next replacements. For example, the following pairs of words denote the same name: * "koouper" and "kuooper". Making the replacements described above, you can make both words to be equal: "koouper" <image> "kuuper" and "kuooper" <image> "kuuper". * "khun" and "kkkhoon". With the replacements described above you can make both words to be equal: "khun" <image> "khoon" and "kkkhoon" <image> "kkhoon" <image> "khoon". For a given list of words, find the minimal number of groups where the words in each group denote the same name. Input The first line contains integer number n (2 ≀ n ≀ 400) β€” number of the words in the list. The following n lines contain words, one word per line. Each word consists of only lowercase Latin letters. The length of each word is between 1 and 20 letters inclusive. Output Print the minimal number of groups where the words in each group denote the same name. Examples Input 10 mihail oolyana kooooper hoon ulyana koouper mikhail khun kuooper kkkhoon Output 4 Input 9 hariton hkariton buoi kkkhariton boooi bui khariton boui boi Output 5 Input 2 alex alex Output 1 Note There are four groups of words in the first example. Words in each group denote same name: 1. "mihail", "mikhail" 2. "oolyana", "ulyana" 3. "kooooper", "koouper" 4. "hoon", "khun", "kkkhoon" There are five groups of words in the second example. Words in each group denote same name: 1. "hariton", "kkkhariton", "khariton" 2. "hkariton" 3. "buoi", "boooi", "boui" 4. "bui" 5. "boi" In the third example the words are equal, so they denote the same name. ### Response ```cpp #include <bits/stdc++.h> using namespace std; string str[409]; map<string, int> mapp; int ans = 0; void check(string now) { string cc = ""; int si = now.size(); for (int i = 0; i < si; i++) { if (now[i] == 'u') { cc += "oo"; } else { cc += now[i]; } } string aa = ""; si = cc.size(); int fl = 0; for (int i = si - 1; i >= 0; i--) { if (cc[i] == 'h') { fl = 1; } if (cc[i] == 'k' && fl == 1) { continue; } if (cc[i] != 'h' && cc[i] != 'k') { fl = 0; } aa = cc[i] + aa; } if (mapp.find(aa) == mapp.end()) { ans++; mapp[aa] = 1; } } int main() { int n; cin >> n; for (int i = 1; i <= n; i++) { cin >> str[i]; } for (int i = 1; i <= n; i++) { check(str[i]); } cout << ans << endl; return 0; } ```
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; set<string> str_set; while (t--) { string input; cin >> input; string ans = " "; while (ans != input) { ans.clear(); int i = 0; while (i < input.size()) { if (i + 1 < input.size() && input[i] == 'k' && input[i + 1] == 'h') { ans.push_back('h'); i += 2; } else if (input[i] == 'u') { ans.push_back('o'); ans.push_back('o'); i++; } else { ans.push_back(input[i]); i++; } } swap(input, ans); } str_set.insert(ans); } cout << str_set.size(); }
### Prompt Construct a Cpp code solution to the problem outlined: There are some ambiguities when one writes Berland names with the letters of the Latin alphabet. For example, the Berland sound u can be written in the Latin alphabet as "u", and can be written as "oo". For this reason, two words "ulyana" and "oolyana" denote the same name. The second ambiguity is about the Berland sound h: one can use both "h" and "kh" to write it. For example, the words "mihail" and "mikhail" denote the same name. There are n users registered on the Polycarp's website. Each of them indicated a name represented by the Latin letters. How many distinct names are there among them, if two ambiguities described above are taken into account? Formally, we assume that two words denote the same name, if using the replacements "u" <image> "oo" and "h" <image> "kh", you can make the words equal. One can make replacements in both directions, in any of the two words an arbitrary number of times. A letter that resulted from the previous replacement can participate in the next replacements. For example, the following pairs of words denote the same name: * "koouper" and "kuooper". Making the replacements described above, you can make both words to be equal: "koouper" <image> "kuuper" and "kuooper" <image> "kuuper". * "khun" and "kkkhoon". With the replacements described above you can make both words to be equal: "khun" <image> "khoon" and "kkkhoon" <image> "kkhoon" <image> "khoon". For a given list of words, find the minimal number of groups where the words in each group denote the same name. Input The first line contains integer number n (2 ≀ n ≀ 400) β€” number of the words in the list. The following n lines contain words, one word per line. Each word consists of only lowercase Latin letters. The length of each word is between 1 and 20 letters inclusive. Output Print the minimal number of groups where the words in each group denote the same name. Examples Input 10 mihail oolyana kooooper hoon ulyana koouper mikhail khun kuooper kkkhoon Output 4 Input 9 hariton hkariton buoi kkkhariton boooi bui khariton boui boi Output 5 Input 2 alex alex Output 1 Note There are four groups of words in the first example. Words in each group denote same name: 1. "mihail", "mikhail" 2. "oolyana", "ulyana" 3. "kooooper", "koouper" 4. "hoon", "khun", "kkkhoon" There are five groups of words in the second example. Words in each group denote same name: 1. "hariton", "kkkhariton", "khariton" 2. "hkariton" 3. "buoi", "boooi", "boui" 4. "bui" 5. "boi" In the third example the words are equal, so they denote the same name. ### Response ```cpp #include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; set<string> str_set; while (t--) { string input; cin >> input; string ans = " "; while (ans != input) { ans.clear(); int i = 0; while (i < input.size()) { if (i + 1 < input.size() && input[i] == 'k' && input[i + 1] == 'h') { ans.push_back('h'); i += 2; } else if (input[i] == 'u') { ans.push_back('o'); ans.push_back('o'); i++; } else { ans.push_back(input[i]); i++; } } swap(input, ans); } str_set.insert(ans); } cout << str_set.size(); } ```
#include <bits/stdc++.h> using namespace std; map<pair<char, char>, char> conversions; string shorten(string &str) { string s; for (auto &c : str) { s.push_back(c); while (s.size() >= 1) { if (s[s.size() - 1] == 'u') { s.pop_back(); s.push_back('o'); s.push_back('o'); } else if (s.size() >= 2 && s[s.size() - 2] == 'k' && s[s.size() - 1] == 'h') { s.pop_back(); s.pop_back(); s.push_back('h'); } else { break; } } } return s; } int main() { conversions[{'o', 'o'}] = 'u'; conversions[{'k', 'h'}] = 'h'; int n; set<string> all_names; cin >> n; for (int i = 0; i < n; ++i) { string cur_name; cin >> cur_name; all_names.insert(shorten(cur_name)); } cout << all_names.size() << endl; return 0; }
### Prompt In cpp, your task is to solve the following problem: There are some ambiguities when one writes Berland names with the letters of the Latin alphabet. For example, the Berland sound u can be written in the Latin alphabet as "u", and can be written as "oo". For this reason, two words "ulyana" and "oolyana" denote the same name. The second ambiguity is about the Berland sound h: one can use both "h" and "kh" to write it. For example, the words "mihail" and "mikhail" denote the same name. There are n users registered on the Polycarp's website. Each of them indicated a name represented by the Latin letters. How many distinct names are there among them, if two ambiguities described above are taken into account? Formally, we assume that two words denote the same name, if using the replacements "u" <image> "oo" and "h" <image> "kh", you can make the words equal. One can make replacements in both directions, in any of the two words an arbitrary number of times. A letter that resulted from the previous replacement can participate in the next replacements. For example, the following pairs of words denote the same name: * "koouper" and "kuooper". Making the replacements described above, you can make both words to be equal: "koouper" <image> "kuuper" and "kuooper" <image> "kuuper". * "khun" and "kkkhoon". With the replacements described above you can make both words to be equal: "khun" <image> "khoon" and "kkkhoon" <image> "kkhoon" <image> "khoon". For a given list of words, find the minimal number of groups where the words in each group denote the same name. Input The first line contains integer number n (2 ≀ n ≀ 400) β€” number of the words in the list. The following n lines contain words, one word per line. Each word consists of only lowercase Latin letters. The length of each word is between 1 and 20 letters inclusive. Output Print the minimal number of groups where the words in each group denote the same name. Examples Input 10 mihail oolyana kooooper hoon ulyana koouper mikhail khun kuooper kkkhoon Output 4 Input 9 hariton hkariton buoi kkkhariton boooi bui khariton boui boi Output 5 Input 2 alex alex Output 1 Note There are four groups of words in the first example. Words in each group denote same name: 1. "mihail", "mikhail" 2. "oolyana", "ulyana" 3. "kooooper", "koouper" 4. "hoon", "khun", "kkkhoon" There are five groups of words in the second example. Words in each group denote same name: 1. "hariton", "kkkhariton", "khariton" 2. "hkariton" 3. "buoi", "boooi", "boui" 4. "bui" 5. "boi" In the third example the words are equal, so they denote the same name. ### Response ```cpp #include <bits/stdc++.h> using namespace std; map<pair<char, char>, char> conversions; string shorten(string &str) { string s; for (auto &c : str) { s.push_back(c); while (s.size() >= 1) { if (s[s.size() - 1] == 'u') { s.pop_back(); s.push_back('o'); s.push_back('o'); } else if (s.size() >= 2 && s[s.size() - 2] == 'k' && s[s.size() - 1] == 'h') { s.pop_back(); s.pop_back(); s.push_back('h'); } else { break; } } } return s; } int main() { conversions[{'o', 'o'}] = 'u'; conversions[{'k', 'h'}] = 'h'; int n; set<string> all_names; cin >> n; for (int i = 0; i < n; ++i) { string cur_name; cin >> cur_name; all_names.insert(shorten(cur_name)); } cout << all_names.size() << endl; return 0; } ```
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; set<string> s; for (int i = 0; i < n; i++) { string t; cin >> t; t += '.'; string w = ""; int c = 0, k = 0; for (char x : t) { if (c && (x != 'o' && x != 'u')) { stringstream nm; nm << c; w += nm.str(); c = 0; } if (x == 'k') { k++; continue; } if (x == 'h') k = 0; while (k > 0) w += "k", k--; if (x == 'o' || x == 'u') c += (x == 'u' ? 2 : 1); else w += x; } s.insert(w); } cout << int(s.size()) << endl; }
### Prompt Create a solution in CPP for the following problem: There are some ambiguities when one writes Berland names with the letters of the Latin alphabet. For example, the Berland sound u can be written in the Latin alphabet as "u", and can be written as "oo". For this reason, two words "ulyana" and "oolyana" denote the same name. The second ambiguity is about the Berland sound h: one can use both "h" and "kh" to write it. For example, the words "mihail" and "mikhail" denote the same name. There are n users registered on the Polycarp's website. Each of them indicated a name represented by the Latin letters. How many distinct names are there among them, if two ambiguities described above are taken into account? Formally, we assume that two words denote the same name, if using the replacements "u" <image> "oo" and "h" <image> "kh", you can make the words equal. One can make replacements in both directions, in any of the two words an arbitrary number of times. A letter that resulted from the previous replacement can participate in the next replacements. For example, the following pairs of words denote the same name: * "koouper" and "kuooper". Making the replacements described above, you can make both words to be equal: "koouper" <image> "kuuper" and "kuooper" <image> "kuuper". * "khun" and "kkkhoon". With the replacements described above you can make both words to be equal: "khun" <image> "khoon" and "kkkhoon" <image> "kkhoon" <image> "khoon". For a given list of words, find the minimal number of groups where the words in each group denote the same name. Input The first line contains integer number n (2 ≀ n ≀ 400) β€” number of the words in the list. The following n lines contain words, one word per line. Each word consists of only lowercase Latin letters. The length of each word is between 1 and 20 letters inclusive. Output Print the minimal number of groups where the words in each group denote the same name. Examples Input 10 mihail oolyana kooooper hoon ulyana koouper mikhail khun kuooper kkkhoon Output 4 Input 9 hariton hkariton buoi kkkhariton boooi bui khariton boui boi Output 5 Input 2 alex alex Output 1 Note There are four groups of words in the first example. Words in each group denote same name: 1. "mihail", "mikhail" 2. "oolyana", "ulyana" 3. "kooooper", "koouper" 4. "hoon", "khun", "kkkhoon" There are five groups of words in the second example. Words in each group denote same name: 1. "hariton", "kkkhariton", "khariton" 2. "hkariton" 3. "buoi", "boooi", "boui" 4. "bui" 5. "boi" In the third example the words are equal, so they denote the same name. ### Response ```cpp #include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; set<string> s; for (int i = 0; i < n; i++) { string t; cin >> t; t += '.'; string w = ""; int c = 0, k = 0; for (char x : t) { if (c && (x != 'o' && x != 'u')) { stringstream nm; nm << c; w += nm.str(); c = 0; } if (x == 'k') { k++; continue; } if (x == 'h') k = 0; while (k > 0) w += "k", k--; if (x == 'o' || x == 'u') c += (x == 'u' ? 2 : 1); else w += x; } s.insert(w); } cout << int(s.size()) << endl; } ```
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; char nn[500][500] = {0}; for (int i = 0; i < n; i++) cin >> nn[i]; char x[500][500] = {0}; map<string, int> freq; for (int i = 0; i < n; i++) { int k = 0, lk = -1, j; for (j = 0; nn[i][j] != '\0'; j++) { if (nn[i][j] == 'u') { while (lk != -1 && lk != j) { x[i][k] = 'k'; k = k + 1; lk = lk + 1; } lk = -1; x[i][k] = 'o'; x[i][k + 1] = 'o'; k = k + 2; } else if (nn[i][j] == 'k') { if (nn[i][j + 1] == '\0') { while (lk != -1 && lk != j) { x[i][k] = 'k'; k = k + 1; lk = lk + 1; } lk = -1; x[i][k] = 'k'; k = k + 1; } if (lk == -1) lk = j; } else if (nn[i][j] == 'h') { x[i][k] = 'h'; lk = -1; k = k + 1; } else { while (lk != -1 && lk != j) { x[i][k] = 'k'; k = k + 1; lk = lk + 1; } lk = -1; x[i][k] = nn[i][j]; k = k + 1; } } x[i][k] = '\0'; string str(x[i]); if (freq[str] != 1) freq[str]++; } int ct = 0; for (map<string, int>::iterator it = freq.begin(); it != freq.end(); it++) { ct++; } cout << ct << endl; return 0; }
### Prompt Create a solution in Cpp for the following problem: There are some ambiguities when one writes Berland names with the letters of the Latin alphabet. For example, the Berland sound u can be written in the Latin alphabet as "u", and can be written as "oo". For this reason, two words "ulyana" and "oolyana" denote the same name. The second ambiguity is about the Berland sound h: one can use both "h" and "kh" to write it. For example, the words "mihail" and "mikhail" denote the same name. There are n users registered on the Polycarp's website. Each of them indicated a name represented by the Latin letters. How many distinct names are there among them, if two ambiguities described above are taken into account? Formally, we assume that two words denote the same name, if using the replacements "u" <image> "oo" and "h" <image> "kh", you can make the words equal. One can make replacements in both directions, in any of the two words an arbitrary number of times. A letter that resulted from the previous replacement can participate in the next replacements. For example, the following pairs of words denote the same name: * "koouper" and "kuooper". Making the replacements described above, you can make both words to be equal: "koouper" <image> "kuuper" and "kuooper" <image> "kuuper". * "khun" and "kkkhoon". With the replacements described above you can make both words to be equal: "khun" <image> "khoon" and "kkkhoon" <image> "kkhoon" <image> "khoon". For a given list of words, find the minimal number of groups where the words in each group denote the same name. Input The first line contains integer number n (2 ≀ n ≀ 400) β€” number of the words in the list. The following n lines contain words, one word per line. Each word consists of only lowercase Latin letters. The length of each word is between 1 and 20 letters inclusive. Output Print the minimal number of groups where the words in each group denote the same name. Examples Input 10 mihail oolyana kooooper hoon ulyana koouper mikhail khun kuooper kkkhoon Output 4 Input 9 hariton hkariton buoi kkkhariton boooi bui khariton boui boi Output 5 Input 2 alex alex Output 1 Note There are four groups of words in the first example. Words in each group denote same name: 1. "mihail", "mikhail" 2. "oolyana", "ulyana" 3. "kooooper", "koouper" 4. "hoon", "khun", "kkkhoon" There are five groups of words in the second example. Words in each group denote same name: 1. "hariton", "kkkhariton", "khariton" 2. "hkariton" 3. "buoi", "boooi", "boui" 4. "bui" 5. "boi" In the third example the words are equal, so they denote the same name. ### Response ```cpp #include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; char nn[500][500] = {0}; for (int i = 0; i < n; i++) cin >> nn[i]; char x[500][500] = {0}; map<string, int> freq; for (int i = 0; i < n; i++) { int k = 0, lk = -1, j; for (j = 0; nn[i][j] != '\0'; j++) { if (nn[i][j] == 'u') { while (lk != -1 && lk != j) { x[i][k] = 'k'; k = k + 1; lk = lk + 1; } lk = -1; x[i][k] = 'o'; x[i][k + 1] = 'o'; k = k + 2; } else if (nn[i][j] == 'k') { if (nn[i][j + 1] == '\0') { while (lk != -1 && lk != j) { x[i][k] = 'k'; k = k + 1; lk = lk + 1; } lk = -1; x[i][k] = 'k'; k = k + 1; } if (lk == -1) lk = j; } else if (nn[i][j] == 'h') { x[i][k] = 'h'; lk = -1; k = k + 1; } else { while (lk != -1 && lk != j) { x[i][k] = 'k'; k = k + 1; lk = lk + 1; } lk = -1; x[i][k] = nn[i][j]; k = k + 1; } } x[i][k] = '\0'; string str(x[i]); if (freq[str] != 1) freq[str]++; } int ct = 0; for (map<string, int>::iterator it = freq.begin(); it != freq.end(); it++) { ct++; } cout << ct << endl; return 0; } ```
#include <bits/stdc++.h> using namespace std; bool is_prime(int n) { for (int i = 2; i * i <= n; ++i) { if (n % i == 0) { return false; } } return true; } inline long long getPow(long long a, long long b) { long long res = 1, tp = a; while (b) { if (b & 1ll) { res *= tp; res %= 1000000007; } tp *= tp; tp %= 1000000007; b >>= 1ll; } return res; } inline long long to_ll(string s) { long long cur = 0; for (int i = 0; i < s.size(); i++) { cur = cur * 10 + s[i] - '0'; } return cur; } inline string to_str(long long x) { string s = ""; while (x) { s += char(x % 10 + '0'); x /= 10; } reverse(s.begin(), s.end()); return s; } inline long long nxt() { long long x; scanf("%lld", &x); return x; } void ok() { puts("YES"); exit(0); } void panic() { puts("NO"); exit(0); } const long long N = 1e6 + 5; int main() { long long n = nxt(); set<string> ans; vector<string> mas(n); for (int i = 0; i < n; i++) { cin >> mas[i]; } for (int i = 0; i < n; i++) { while (mas[i].find('u') != string::npos) { long long indx = mas[i].find('u'); mas[i].erase(indx, 1); mas[i].insert(indx, "oo"); } while (mas[i].find("kh") != string::npos) { long long indx = mas[i].find("kh"); mas[i].erase(indx, 2); mas[i].insert(indx, "h"); } ans.insert(mas[i]); } cout << ans.size(); return 0; }
### Prompt Your challenge is to write a Cpp solution to the following problem: There are some ambiguities when one writes Berland names with the letters of the Latin alphabet. For example, the Berland sound u can be written in the Latin alphabet as "u", and can be written as "oo". For this reason, two words "ulyana" and "oolyana" denote the same name. The second ambiguity is about the Berland sound h: one can use both "h" and "kh" to write it. For example, the words "mihail" and "mikhail" denote the same name. There are n users registered on the Polycarp's website. Each of them indicated a name represented by the Latin letters. How many distinct names are there among them, if two ambiguities described above are taken into account? Formally, we assume that two words denote the same name, if using the replacements "u" <image> "oo" and "h" <image> "kh", you can make the words equal. One can make replacements in both directions, in any of the two words an arbitrary number of times. A letter that resulted from the previous replacement can participate in the next replacements. For example, the following pairs of words denote the same name: * "koouper" and "kuooper". Making the replacements described above, you can make both words to be equal: "koouper" <image> "kuuper" and "kuooper" <image> "kuuper". * "khun" and "kkkhoon". With the replacements described above you can make both words to be equal: "khun" <image> "khoon" and "kkkhoon" <image> "kkhoon" <image> "khoon". For a given list of words, find the minimal number of groups where the words in each group denote the same name. Input The first line contains integer number n (2 ≀ n ≀ 400) β€” number of the words in the list. The following n lines contain words, one word per line. Each word consists of only lowercase Latin letters. The length of each word is between 1 and 20 letters inclusive. Output Print the minimal number of groups where the words in each group denote the same name. Examples Input 10 mihail oolyana kooooper hoon ulyana koouper mikhail khun kuooper kkkhoon Output 4 Input 9 hariton hkariton buoi kkkhariton boooi bui khariton boui boi Output 5 Input 2 alex alex Output 1 Note There are four groups of words in the first example. Words in each group denote same name: 1. "mihail", "mikhail" 2. "oolyana", "ulyana" 3. "kooooper", "koouper" 4. "hoon", "khun", "kkkhoon" There are five groups of words in the second example. Words in each group denote same name: 1. "hariton", "kkkhariton", "khariton" 2. "hkariton" 3. "buoi", "boooi", "boui" 4. "bui" 5. "boi" In the third example the words are equal, so they denote the same name. ### Response ```cpp #include <bits/stdc++.h> using namespace std; bool is_prime(int n) { for (int i = 2; i * i <= n; ++i) { if (n % i == 0) { return false; } } return true; } inline long long getPow(long long a, long long b) { long long res = 1, tp = a; while (b) { if (b & 1ll) { res *= tp; res %= 1000000007; } tp *= tp; tp %= 1000000007; b >>= 1ll; } return res; } inline long long to_ll(string s) { long long cur = 0; for (int i = 0; i < s.size(); i++) { cur = cur * 10 + s[i] - '0'; } return cur; } inline string to_str(long long x) { string s = ""; while (x) { s += char(x % 10 + '0'); x /= 10; } reverse(s.begin(), s.end()); return s; } inline long long nxt() { long long x; scanf("%lld", &x); return x; } void ok() { puts("YES"); exit(0); } void panic() { puts("NO"); exit(0); } const long long N = 1e6 + 5; int main() { long long n = nxt(); set<string> ans; vector<string> mas(n); for (int i = 0; i < n; i++) { cin >> mas[i]; } for (int i = 0; i < n; i++) { while (mas[i].find('u') != string::npos) { long long indx = mas[i].find('u'); mas[i].erase(indx, 1); mas[i].insert(indx, "oo"); } while (mas[i].find("kh") != string::npos) { long long indx = mas[i].find("kh"); mas[i].erase(indx, 2); mas[i].insert(indx, "h"); } ans.insert(mas[i]); } cout << ans.size(); return 0; } ```
#include <bits/stdc++.h> using namespace std; void convert(string& s) { int len = 0; string temp = ""; for (int i = 0; i < s.size(); i++) { if (s[i] == 'k') { int begin = i; while (i < s.size() && s[i] == 'k') i++; if (s[i] == 'h') { temp += 'h'; } else { for (int j = begin; j < i; j++) { temp += 'k'; } i--; } } else if (i < s.size() - 1 && s[i] == 'o' && s[i + 1] == 'o') { temp += 'u'; i++; } else if (i < s.size() - 1 && s[i] == 'o' && s[i + 1] == 'u') { s[i] = 'u'; s[i + 1] = 'o'; temp += 'u'; } else { temp += s[i]; } } s = temp; } int main() { int n, wasCount = 0; cin >> n; string* was = new string[n]; for (int i = 0; i < n; i++) { string temp; cin >> temp; convert(temp); bool flag = true; for (int j = 0; j < wasCount; j++) { if (was[j] == temp) { flag = false; break; } } if (flag) { was[wasCount] = temp; wasCount++; } } cout << wasCount; return 0; }
### Prompt Create a solution in CPP for the following problem: There are some ambiguities when one writes Berland names with the letters of the Latin alphabet. For example, the Berland sound u can be written in the Latin alphabet as "u", and can be written as "oo". For this reason, two words "ulyana" and "oolyana" denote the same name. The second ambiguity is about the Berland sound h: one can use both "h" and "kh" to write it. For example, the words "mihail" and "mikhail" denote the same name. There are n users registered on the Polycarp's website. Each of them indicated a name represented by the Latin letters. How many distinct names are there among them, if two ambiguities described above are taken into account? Formally, we assume that two words denote the same name, if using the replacements "u" <image> "oo" and "h" <image> "kh", you can make the words equal. One can make replacements in both directions, in any of the two words an arbitrary number of times. A letter that resulted from the previous replacement can participate in the next replacements. For example, the following pairs of words denote the same name: * "koouper" and "kuooper". Making the replacements described above, you can make both words to be equal: "koouper" <image> "kuuper" and "kuooper" <image> "kuuper". * "khun" and "kkkhoon". With the replacements described above you can make both words to be equal: "khun" <image> "khoon" and "kkkhoon" <image> "kkhoon" <image> "khoon". For a given list of words, find the minimal number of groups where the words in each group denote the same name. Input The first line contains integer number n (2 ≀ n ≀ 400) β€” number of the words in the list. The following n lines contain words, one word per line. Each word consists of only lowercase Latin letters. The length of each word is between 1 and 20 letters inclusive. Output Print the minimal number of groups where the words in each group denote the same name. Examples Input 10 mihail oolyana kooooper hoon ulyana koouper mikhail khun kuooper kkkhoon Output 4 Input 9 hariton hkariton buoi kkkhariton boooi bui khariton boui boi Output 5 Input 2 alex alex Output 1 Note There are four groups of words in the first example. Words in each group denote same name: 1. "mihail", "mikhail" 2. "oolyana", "ulyana" 3. "kooooper", "koouper" 4. "hoon", "khun", "kkkhoon" There are five groups of words in the second example. Words in each group denote same name: 1. "hariton", "kkkhariton", "khariton" 2. "hkariton" 3. "buoi", "boooi", "boui" 4. "bui" 5. "boi" In the third example the words are equal, so they denote the same name. ### Response ```cpp #include <bits/stdc++.h> using namespace std; void convert(string& s) { int len = 0; string temp = ""; for (int i = 0; i < s.size(); i++) { if (s[i] == 'k') { int begin = i; while (i < s.size() && s[i] == 'k') i++; if (s[i] == 'h') { temp += 'h'; } else { for (int j = begin; j < i; j++) { temp += 'k'; } i--; } } else if (i < s.size() - 1 && s[i] == 'o' && s[i + 1] == 'o') { temp += 'u'; i++; } else if (i < s.size() - 1 && s[i] == 'o' && s[i + 1] == 'u') { s[i] = 'u'; s[i + 1] = 'o'; temp += 'u'; } else { temp += s[i]; } } s = temp; } int main() { int n, wasCount = 0; cin >> n; string* was = new string[n]; for (int i = 0; i < n; i++) { string temp; cin >> temp; convert(temp); bool flag = true; for (int j = 0; j < wasCount; j++) { if (was[j] == temp) { flag = false; break; } } if (flag) { was[wasCount] = temp; wasCount++; } } cout << wasCount; return 0; } ```
#include <bits/stdc++.h> using namespace std; int main() { int n; while (cin >> n) { string s; set<string> st; while (n--) { cin >> s; for (int i = s.length(); i >= 0; i--) { if (s[i] == 'u') s.replace(i, 1, "oo"); else if (s[i] == 'k' && s[i + 1] == 'h') s.replace(i, 2, "h"); } st.insert(s); } cout << st.size(); } return 0; }
### Prompt Your task is to create a Cpp solution to the following problem: There are some ambiguities when one writes Berland names with the letters of the Latin alphabet. For example, the Berland sound u can be written in the Latin alphabet as "u", and can be written as "oo". For this reason, two words "ulyana" and "oolyana" denote the same name. The second ambiguity is about the Berland sound h: one can use both "h" and "kh" to write it. For example, the words "mihail" and "mikhail" denote the same name. There are n users registered on the Polycarp's website. Each of them indicated a name represented by the Latin letters. How many distinct names are there among them, if two ambiguities described above are taken into account? Formally, we assume that two words denote the same name, if using the replacements "u" <image> "oo" and "h" <image> "kh", you can make the words equal. One can make replacements in both directions, in any of the two words an arbitrary number of times. A letter that resulted from the previous replacement can participate in the next replacements. For example, the following pairs of words denote the same name: * "koouper" and "kuooper". Making the replacements described above, you can make both words to be equal: "koouper" <image> "kuuper" and "kuooper" <image> "kuuper". * "khun" and "kkkhoon". With the replacements described above you can make both words to be equal: "khun" <image> "khoon" and "kkkhoon" <image> "kkhoon" <image> "khoon". For a given list of words, find the minimal number of groups where the words in each group denote the same name. Input The first line contains integer number n (2 ≀ n ≀ 400) β€” number of the words in the list. The following n lines contain words, one word per line. Each word consists of only lowercase Latin letters. The length of each word is between 1 and 20 letters inclusive. Output Print the minimal number of groups where the words in each group denote the same name. Examples Input 10 mihail oolyana kooooper hoon ulyana koouper mikhail khun kuooper kkkhoon Output 4 Input 9 hariton hkariton buoi kkkhariton boooi bui khariton boui boi Output 5 Input 2 alex alex Output 1 Note There are four groups of words in the first example. Words in each group denote same name: 1. "mihail", "mikhail" 2. "oolyana", "ulyana" 3. "kooooper", "koouper" 4. "hoon", "khun", "kkkhoon" There are five groups of words in the second example. Words in each group denote same name: 1. "hariton", "kkkhariton", "khariton" 2. "hkariton" 3. "buoi", "boooi", "boui" 4. "bui" 5. "boi" In the third example the words are equal, so they denote the same name. ### Response ```cpp #include <bits/stdc++.h> using namespace std; int main() { int n; while (cin >> n) { string s; set<string> st; while (n--) { cin >> s; for (int i = s.length(); i >= 0; i--) { if (s[i] == 'u') s.replace(i, 1, "oo"); else if (s[i] == 'k' && s[i + 1] == 'h') s.replace(i, 2, "h"); } st.insert(s); } cout << st.size(); } return 0; } ```
#include <bits/stdc++.h> using namespace std; bool b[100100]; string s; long long cnt[100100], n; map<string, int> mp; string fun(string s) { stack<char> st; string ans = ""; for (int i = 0; i < s.size(); i++) { if (st.empty() && s[i] != 'u') { st.push(s[i]); } else if (s[i] == 'u') { st.push('o'); st.push('o'); } else if (st.top() == 'k' && s[i] == 'h') { while (!st.empty() && st.top() == 'k') { st.pop(); } st.push('h'); } else { st.push(s[i]); } } while (!st.empty()) { ans += st.top(); st.pop(); } reverse(ans.begin(), ans.end()); return ans; } long long sum; int main() { long long n; string p; cin >> n; vector<string> t; string g; for (int i = 0; i < n; i++) { cin >> s; g = fun(s); if (mp[g] == 0) { t.push_back(g); } mp[g]++; } for (int i = 0; i < t.size(); i++) { if (mp[t[i]] >= 1) { sum++; } } cout << sum; return 0; }
### Prompt Please formulate a cpp solution to the following problem: There are some ambiguities when one writes Berland names with the letters of the Latin alphabet. For example, the Berland sound u can be written in the Latin alphabet as "u", and can be written as "oo". For this reason, two words "ulyana" and "oolyana" denote the same name. The second ambiguity is about the Berland sound h: one can use both "h" and "kh" to write it. For example, the words "mihail" and "mikhail" denote the same name. There are n users registered on the Polycarp's website. Each of them indicated a name represented by the Latin letters. How many distinct names are there among them, if two ambiguities described above are taken into account? Formally, we assume that two words denote the same name, if using the replacements "u" <image> "oo" and "h" <image> "kh", you can make the words equal. One can make replacements in both directions, in any of the two words an arbitrary number of times. A letter that resulted from the previous replacement can participate in the next replacements. For example, the following pairs of words denote the same name: * "koouper" and "kuooper". Making the replacements described above, you can make both words to be equal: "koouper" <image> "kuuper" and "kuooper" <image> "kuuper". * "khun" and "kkkhoon". With the replacements described above you can make both words to be equal: "khun" <image> "khoon" and "kkkhoon" <image> "kkhoon" <image> "khoon". For a given list of words, find the minimal number of groups where the words in each group denote the same name. Input The first line contains integer number n (2 ≀ n ≀ 400) β€” number of the words in the list. The following n lines contain words, one word per line. Each word consists of only lowercase Latin letters. The length of each word is between 1 and 20 letters inclusive. Output Print the minimal number of groups where the words in each group denote the same name. Examples Input 10 mihail oolyana kooooper hoon ulyana koouper mikhail khun kuooper kkkhoon Output 4 Input 9 hariton hkariton buoi kkkhariton boooi bui khariton boui boi Output 5 Input 2 alex alex Output 1 Note There are four groups of words in the first example. Words in each group denote same name: 1. "mihail", "mikhail" 2. "oolyana", "ulyana" 3. "kooooper", "koouper" 4. "hoon", "khun", "kkkhoon" There are five groups of words in the second example. Words in each group denote same name: 1. "hariton", "kkkhariton", "khariton" 2. "hkariton" 3. "buoi", "boooi", "boui" 4. "bui" 5. "boi" In the third example the words are equal, so they denote the same name. ### Response ```cpp #include <bits/stdc++.h> using namespace std; bool b[100100]; string s; long long cnt[100100], n; map<string, int> mp; string fun(string s) { stack<char> st; string ans = ""; for (int i = 0; i < s.size(); i++) { if (st.empty() && s[i] != 'u') { st.push(s[i]); } else if (s[i] == 'u') { st.push('o'); st.push('o'); } else if (st.top() == 'k' && s[i] == 'h') { while (!st.empty() && st.top() == 'k') { st.pop(); } st.push('h'); } else { st.push(s[i]); } } while (!st.empty()) { ans += st.top(); st.pop(); } reverse(ans.begin(), ans.end()); return ans; } long long sum; int main() { long long n; string p; cin >> n; vector<string> t; string g; for (int i = 0; i < n; i++) { cin >> s; g = fun(s); if (mp[g] == 0) { t.push_back(g); } mp[g]++; } for (int i = 0; i < t.size(); i++) { if (mp[t[i]] >= 1) { sum++; } } cout << sum; return 0; } ```
#include <bits/stdc++.h> using namespace std; string uoo(string& s) { string cur = ""; for (auto i : s) { if (i == 'u') { cur += "oo"; } else { cur += i; } } return cur; } string khh(string& s) { string cur = ""; for (int i = 0; i < s.size(); i++) { if (!(i < s.size() - 1 && s[i] == 'k' && s[i + 1] == 'h')) { cur += s[i]; } } return cur; } int main() { int n; set<string> q; string cur; bool kh = false; int cnt; cin >> n; vector<string> a(n); for (int i = 0; i < n; i++) { cin >> a[i]; } for (int i = 0; i < n; i++) { cur = uoo(a[i]); for (int j = 0; j < a[i].size(); j++) { cur = khh(cur); } q.insert(cur); } cout << q.size() << endl; return 0; }
### Prompt Create a solution in CPP for the following problem: There are some ambiguities when one writes Berland names with the letters of the Latin alphabet. For example, the Berland sound u can be written in the Latin alphabet as "u", and can be written as "oo". For this reason, two words "ulyana" and "oolyana" denote the same name. The second ambiguity is about the Berland sound h: one can use both "h" and "kh" to write it. For example, the words "mihail" and "mikhail" denote the same name. There are n users registered on the Polycarp's website. Each of them indicated a name represented by the Latin letters. How many distinct names are there among them, if two ambiguities described above are taken into account? Formally, we assume that two words denote the same name, if using the replacements "u" <image> "oo" and "h" <image> "kh", you can make the words equal. One can make replacements in both directions, in any of the two words an arbitrary number of times. A letter that resulted from the previous replacement can participate in the next replacements. For example, the following pairs of words denote the same name: * "koouper" and "kuooper". Making the replacements described above, you can make both words to be equal: "koouper" <image> "kuuper" and "kuooper" <image> "kuuper". * "khun" and "kkkhoon". With the replacements described above you can make both words to be equal: "khun" <image> "khoon" and "kkkhoon" <image> "kkhoon" <image> "khoon". For a given list of words, find the minimal number of groups where the words in each group denote the same name. Input The first line contains integer number n (2 ≀ n ≀ 400) β€” number of the words in the list. The following n lines contain words, one word per line. Each word consists of only lowercase Latin letters. The length of each word is between 1 and 20 letters inclusive. Output Print the minimal number of groups where the words in each group denote the same name. Examples Input 10 mihail oolyana kooooper hoon ulyana koouper mikhail khun kuooper kkkhoon Output 4 Input 9 hariton hkariton buoi kkkhariton boooi bui khariton boui boi Output 5 Input 2 alex alex Output 1 Note There are four groups of words in the first example. Words in each group denote same name: 1. "mihail", "mikhail" 2. "oolyana", "ulyana" 3. "kooooper", "koouper" 4. "hoon", "khun", "kkkhoon" There are five groups of words in the second example. Words in each group denote same name: 1. "hariton", "kkkhariton", "khariton" 2. "hkariton" 3. "buoi", "boooi", "boui" 4. "bui" 5. "boi" In the third example the words are equal, so they denote the same name. ### Response ```cpp #include <bits/stdc++.h> using namespace std; string uoo(string& s) { string cur = ""; for (auto i : s) { if (i == 'u') { cur += "oo"; } else { cur += i; } } return cur; } string khh(string& s) { string cur = ""; for (int i = 0; i < s.size(); i++) { if (!(i < s.size() - 1 && s[i] == 'k' && s[i + 1] == 'h')) { cur += s[i]; } } return cur; } int main() { int n; set<string> q; string cur; bool kh = false; int cnt; cin >> n; vector<string> a(n); for (int i = 0; i < n; i++) { cin >> a[i]; } for (int i = 0; i < n; i++) { cur = uoo(a[i]); for (int j = 0; j < a[i].size(); j++) { cur = khh(cur); } q.insert(cur); } cout << q.size() << endl; return 0; } ```
#include <bits/stdc++.h> using namespace std; int main() { int pos1, pos2, pos3, l, T; set<string> s; string str; cin >> T; while (T--) { cin >> str; while (1) { pos3 = str.find("u"); if (pos3 != -1) str.replace(pos3, 1, "oo"); else break; } while (1) { pos1 = str.find("oo"); if (pos1 != -1) str.replace(pos1, 2, "u"); else break; } while (1) { pos2 = str.find("kh"); if (pos2 != -1) str.replace(pos2, 2, "h"); else break; } s.insert(str); } cout << s.size(); return 0; }
### Prompt Please provide a Cpp coded solution to the problem described below: There are some ambiguities when one writes Berland names with the letters of the Latin alphabet. For example, the Berland sound u can be written in the Latin alphabet as "u", and can be written as "oo". For this reason, two words "ulyana" and "oolyana" denote the same name. The second ambiguity is about the Berland sound h: one can use both "h" and "kh" to write it. For example, the words "mihail" and "mikhail" denote the same name. There are n users registered on the Polycarp's website. Each of them indicated a name represented by the Latin letters. How many distinct names are there among them, if two ambiguities described above are taken into account? Formally, we assume that two words denote the same name, if using the replacements "u" <image> "oo" and "h" <image> "kh", you can make the words equal. One can make replacements in both directions, in any of the two words an arbitrary number of times. A letter that resulted from the previous replacement can participate in the next replacements. For example, the following pairs of words denote the same name: * "koouper" and "kuooper". Making the replacements described above, you can make both words to be equal: "koouper" <image> "kuuper" and "kuooper" <image> "kuuper". * "khun" and "kkkhoon". With the replacements described above you can make both words to be equal: "khun" <image> "khoon" and "kkkhoon" <image> "kkhoon" <image> "khoon". For a given list of words, find the minimal number of groups where the words in each group denote the same name. Input The first line contains integer number n (2 ≀ n ≀ 400) β€” number of the words in the list. The following n lines contain words, one word per line. Each word consists of only lowercase Latin letters. The length of each word is between 1 and 20 letters inclusive. Output Print the minimal number of groups where the words in each group denote the same name. Examples Input 10 mihail oolyana kooooper hoon ulyana koouper mikhail khun kuooper kkkhoon Output 4 Input 9 hariton hkariton buoi kkkhariton boooi bui khariton boui boi Output 5 Input 2 alex alex Output 1 Note There are four groups of words in the first example. Words in each group denote same name: 1. "mihail", "mikhail" 2. "oolyana", "ulyana" 3. "kooooper", "koouper" 4. "hoon", "khun", "kkkhoon" There are five groups of words in the second example. Words in each group denote same name: 1. "hariton", "kkkhariton", "khariton" 2. "hkariton" 3. "buoi", "boooi", "boui" 4. "bui" 5. "boi" In the third example the words are equal, so they denote the same name. ### Response ```cpp #include <bits/stdc++.h> using namespace std; int main() { int pos1, pos2, pos3, l, T; set<string> s; string str; cin >> T; while (T--) { cin >> str; while (1) { pos3 = str.find("u"); if (pos3 != -1) str.replace(pos3, 1, "oo"); else break; } while (1) { pos1 = str.find("oo"); if (pos1 != -1) str.replace(pos1, 2, "u"); else break; } while (1) { pos2 = str.find("kh"); if (pos2 != -1) str.replace(pos2, 2, "h"); else break; } s.insert(str); } cout << s.size(); return 0; } ```
#include <bits/stdc++.h> using namespace std; void show(vector<long long>& vc) { for (auto it : vc) cout << it << " "; cout << endl; } bool p[10 + 2]; vector<long long> prime; void seive(void) { memset(p, 0, sizeof p); p[1] = 1; p[0] = 1; for (int i = 4; i <= 10; i += 2) { p[i] = 1; } for (long long i = 3; i * i <= 10; i += 2) { if (!p[i]) { for (long long j = i * i; j <= 10; j += 2 * i) { p[j] = 1; } } } prime.push_back(2); for (int i = 3; i <= 10; i += 2) prime.push_back(i); } long long dx[] = {-1, -1, 0, -1, 1, 0, 1, 1}; long long dy[] = {-1, 0, -1, 1, -1, 1, 0, 1}; pair<long long, long long> extendedEuclid(long long a, long long b) { if (b == 0) return pair<long long, long long>(1, 0); else { pair<long long, long long> d = extendedEuclid(b, a % b); return pair<long long, long long>(d.second, d.first - d.second * (a / b)); } } long long modularInverse(long long a, long long n) { pair<long long, long long> ret = extendedEuclid(a, n); return ((ret.first % n) + n) % n; } void process(string& s) { for (int i = 0; i + 2 <= s.size(); i++) { string sub = s.substr(i, 2); if (sub == "oo") { s.replace(i, 2, "u"); } else if (sub == "kh") { s.replace(i, 2, "h"); if (i - 2 >= -1) i -= 2; } else if (sub == "ou") { s.replace(i, 2, "uo"); } } } void solve(long long t) { long long n; cin >> n; vector<string> vc(n); map<string, long long> mp; for (int i = 0; i < n; i++) { cin >> vc.at(i); process(vc[i]); mp[vc[i]]++; } cout << mp.size() << endl; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long t = 1; long long T = t; while (t--) { solve(T - t); } }
### Prompt Develop a solution in CPP to the problem described below: There are some ambiguities when one writes Berland names with the letters of the Latin alphabet. For example, the Berland sound u can be written in the Latin alphabet as "u", and can be written as "oo". For this reason, two words "ulyana" and "oolyana" denote the same name. The second ambiguity is about the Berland sound h: one can use both "h" and "kh" to write it. For example, the words "mihail" and "mikhail" denote the same name. There are n users registered on the Polycarp's website. Each of them indicated a name represented by the Latin letters. How many distinct names are there among them, if two ambiguities described above are taken into account? Formally, we assume that two words denote the same name, if using the replacements "u" <image> "oo" and "h" <image> "kh", you can make the words equal. One can make replacements in both directions, in any of the two words an arbitrary number of times. A letter that resulted from the previous replacement can participate in the next replacements. For example, the following pairs of words denote the same name: * "koouper" and "kuooper". Making the replacements described above, you can make both words to be equal: "koouper" <image> "kuuper" and "kuooper" <image> "kuuper". * "khun" and "kkkhoon". With the replacements described above you can make both words to be equal: "khun" <image> "khoon" and "kkkhoon" <image> "kkhoon" <image> "khoon". For a given list of words, find the minimal number of groups where the words in each group denote the same name. Input The first line contains integer number n (2 ≀ n ≀ 400) β€” number of the words in the list. The following n lines contain words, one word per line. Each word consists of only lowercase Latin letters. The length of each word is between 1 and 20 letters inclusive. Output Print the minimal number of groups where the words in each group denote the same name. Examples Input 10 mihail oolyana kooooper hoon ulyana koouper mikhail khun kuooper kkkhoon Output 4 Input 9 hariton hkariton buoi kkkhariton boooi bui khariton boui boi Output 5 Input 2 alex alex Output 1 Note There are four groups of words in the first example. Words in each group denote same name: 1. "mihail", "mikhail" 2. "oolyana", "ulyana" 3. "kooooper", "koouper" 4. "hoon", "khun", "kkkhoon" There are five groups of words in the second example. Words in each group denote same name: 1. "hariton", "kkkhariton", "khariton" 2. "hkariton" 3. "buoi", "boooi", "boui" 4. "bui" 5. "boi" In the third example the words are equal, so they denote the same name. ### Response ```cpp #include <bits/stdc++.h> using namespace std; void show(vector<long long>& vc) { for (auto it : vc) cout << it << " "; cout << endl; } bool p[10 + 2]; vector<long long> prime; void seive(void) { memset(p, 0, sizeof p); p[1] = 1; p[0] = 1; for (int i = 4; i <= 10; i += 2) { p[i] = 1; } for (long long i = 3; i * i <= 10; i += 2) { if (!p[i]) { for (long long j = i * i; j <= 10; j += 2 * i) { p[j] = 1; } } } prime.push_back(2); for (int i = 3; i <= 10; i += 2) prime.push_back(i); } long long dx[] = {-1, -1, 0, -1, 1, 0, 1, 1}; long long dy[] = {-1, 0, -1, 1, -1, 1, 0, 1}; pair<long long, long long> extendedEuclid(long long a, long long b) { if (b == 0) return pair<long long, long long>(1, 0); else { pair<long long, long long> d = extendedEuclid(b, a % b); return pair<long long, long long>(d.second, d.first - d.second * (a / b)); } } long long modularInverse(long long a, long long n) { pair<long long, long long> ret = extendedEuclid(a, n); return ((ret.first % n) + n) % n; } void process(string& s) { for (int i = 0; i + 2 <= s.size(); i++) { string sub = s.substr(i, 2); if (sub == "oo") { s.replace(i, 2, "u"); } else if (sub == "kh") { s.replace(i, 2, "h"); if (i - 2 >= -1) i -= 2; } else if (sub == "ou") { s.replace(i, 2, "uo"); } } } void solve(long long t) { long long n; cin >> n; vector<string> vc(n); map<string, long long> mp; for (int i = 0; i < n; i++) { cin >> vc.at(i); process(vc[i]); mp[vc[i]]++; } cout << mp.size() << endl; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long t = 1; long long T = t; while (t--) { solve(T - t); } } ```
#include <bits/stdc++.h> using namespace std; void problemeA(); void problemeB(); void problemeC(); void probleme4(); void probleme5(); void probleme6(); int main() { problemeB(); return 0; } struct point { int x; int y; }; void problemeA() { point start{0, 0}, goal{0, 0}; cin >> start.x >> start.y; cin >> goal.x >> goal.y; int answer = ((abs(start.x - goal.x) + 1) + (abs(start.y - goal.y) + 1)) * 2; if (abs(start.x - goal.x) == 0 && abs(start.y - goal.y) == 0) answer = 10; else if (abs(start.x - goal.x) == 0 || abs(start.y - goal.y) == 0) answer += 2; cout << answer << endl; } void problemeB() { vector<string> tab; int nb = 0; string s; cin >> nb; tab.resize(nb); for (int i = 0; i < nb; ++i) { cin >> tab[i]; tab[i].insert(0, " "); } for (int i = 0; i < nb; ++i) { for (int j = 0; j < tab[i].size(); ++j) { if (tab[i][j] == 'u') { tab[i][j] = 'o'; tab[i].insert(j, "o"); } else if (tab[i][j] == 'k' && (j != tab[i].size() - 1) && tab[i][j + 1] == 'h') { tab[i].erase(tab[i].begin() + j); j -= 2; } } } vector<string> same; for (int i = 0; i < nb; ++i) { int k = 0; while (k < same.size() && same[k] != tab[i]) ++k; if (k == same.size()) same.push_back(tab[i]); } int rep = same.size(); cout << rep << endl; } void problemeC() {} void probleme4() {} void probleme5() {} void probleme6() {} void probleme7() {} void probleme8() {} void probleme9() {} void probleme10() {} void probleme11() {} void probleme12() {}
### Prompt Please create a solution in Cpp to the following problem: There are some ambiguities when one writes Berland names with the letters of the Latin alphabet. For example, the Berland sound u can be written in the Latin alphabet as "u", and can be written as "oo". For this reason, two words "ulyana" and "oolyana" denote the same name. The second ambiguity is about the Berland sound h: one can use both "h" and "kh" to write it. For example, the words "mihail" and "mikhail" denote the same name. There are n users registered on the Polycarp's website. Each of them indicated a name represented by the Latin letters. How many distinct names are there among them, if two ambiguities described above are taken into account? Formally, we assume that two words denote the same name, if using the replacements "u" <image> "oo" and "h" <image> "kh", you can make the words equal. One can make replacements in both directions, in any of the two words an arbitrary number of times. A letter that resulted from the previous replacement can participate in the next replacements. For example, the following pairs of words denote the same name: * "koouper" and "kuooper". Making the replacements described above, you can make both words to be equal: "koouper" <image> "kuuper" and "kuooper" <image> "kuuper". * "khun" and "kkkhoon". With the replacements described above you can make both words to be equal: "khun" <image> "khoon" and "kkkhoon" <image> "kkhoon" <image> "khoon". For a given list of words, find the minimal number of groups where the words in each group denote the same name. Input The first line contains integer number n (2 ≀ n ≀ 400) β€” number of the words in the list. The following n lines contain words, one word per line. Each word consists of only lowercase Latin letters. The length of each word is between 1 and 20 letters inclusive. Output Print the minimal number of groups where the words in each group denote the same name. Examples Input 10 mihail oolyana kooooper hoon ulyana koouper mikhail khun kuooper kkkhoon Output 4 Input 9 hariton hkariton buoi kkkhariton boooi bui khariton boui boi Output 5 Input 2 alex alex Output 1 Note There are four groups of words in the first example. Words in each group denote same name: 1. "mihail", "mikhail" 2. "oolyana", "ulyana" 3. "kooooper", "koouper" 4. "hoon", "khun", "kkkhoon" There are five groups of words in the second example. Words in each group denote same name: 1. "hariton", "kkkhariton", "khariton" 2. "hkariton" 3. "buoi", "boooi", "boui" 4. "bui" 5. "boi" In the third example the words are equal, so they denote the same name. ### Response ```cpp #include <bits/stdc++.h> using namespace std; void problemeA(); void problemeB(); void problemeC(); void probleme4(); void probleme5(); void probleme6(); int main() { problemeB(); return 0; } struct point { int x; int y; }; void problemeA() { point start{0, 0}, goal{0, 0}; cin >> start.x >> start.y; cin >> goal.x >> goal.y; int answer = ((abs(start.x - goal.x) + 1) + (abs(start.y - goal.y) + 1)) * 2; if (abs(start.x - goal.x) == 0 && abs(start.y - goal.y) == 0) answer = 10; else if (abs(start.x - goal.x) == 0 || abs(start.y - goal.y) == 0) answer += 2; cout << answer << endl; } void problemeB() { vector<string> tab; int nb = 0; string s; cin >> nb; tab.resize(nb); for (int i = 0; i < nb; ++i) { cin >> tab[i]; tab[i].insert(0, " "); } for (int i = 0; i < nb; ++i) { for (int j = 0; j < tab[i].size(); ++j) { if (tab[i][j] == 'u') { tab[i][j] = 'o'; tab[i].insert(j, "o"); } else if (tab[i][j] == 'k' && (j != tab[i].size() - 1) && tab[i][j + 1] == 'h') { tab[i].erase(tab[i].begin() + j); j -= 2; } } } vector<string> same; for (int i = 0; i < nb; ++i) { int k = 0; while (k < same.size() && same[k] != tab[i]) ++k; if (k == same.size()) same.push_back(tab[i]); } int rep = same.size(); cout << rep << endl; } void problemeC() {} void probleme4() {} void probleme5() {} void probleme6() {} void probleme7() {} void probleme8() {} void probleme9() {} void probleme10() {} void probleme11() {} void probleme12() {} ```
#include <bits/stdc++.h> using namespace std; int main() { int n, i, j; cin >> n; string p = ""; vector<string> s(n); for (i = 0; i < n; i++) cin >> s[i]; for (j = 0; j < n; j++) { p = s[j]; if (p == "u") p = "oo"; for (i = 1; i < p.length(); i++) { if (p[i - 1] == 'u') { p = p.substr(0, i - 1) + "oo" + p.substr(i, p.length()); } if (p[p.length() - 1] == 'u') p = p.substr(0, p.length() - 1) + "oo"; if (p[i - 1] == 'k' && p[i] == 'h') { p = p.substr(0, i - 1) + p.substr(i, p.length()); i = 0; } } s[j] = p; p = ""; } sort(s.begin(), s.end()); s.erase(unique(s.begin(), s.end()), s.end()); cout << s.size(); return 0; }
### Prompt Please create a solution in cpp to the following problem: There are some ambiguities when one writes Berland names with the letters of the Latin alphabet. For example, the Berland sound u can be written in the Latin alphabet as "u", and can be written as "oo". For this reason, two words "ulyana" and "oolyana" denote the same name. The second ambiguity is about the Berland sound h: one can use both "h" and "kh" to write it. For example, the words "mihail" and "mikhail" denote the same name. There are n users registered on the Polycarp's website. Each of them indicated a name represented by the Latin letters. How many distinct names are there among them, if two ambiguities described above are taken into account? Formally, we assume that two words denote the same name, if using the replacements "u" <image> "oo" and "h" <image> "kh", you can make the words equal. One can make replacements in both directions, in any of the two words an arbitrary number of times. A letter that resulted from the previous replacement can participate in the next replacements. For example, the following pairs of words denote the same name: * "koouper" and "kuooper". Making the replacements described above, you can make both words to be equal: "koouper" <image> "kuuper" and "kuooper" <image> "kuuper". * "khun" and "kkkhoon". With the replacements described above you can make both words to be equal: "khun" <image> "khoon" and "kkkhoon" <image> "kkhoon" <image> "khoon". For a given list of words, find the minimal number of groups where the words in each group denote the same name. Input The first line contains integer number n (2 ≀ n ≀ 400) β€” number of the words in the list. The following n lines contain words, one word per line. Each word consists of only lowercase Latin letters. The length of each word is between 1 and 20 letters inclusive. Output Print the minimal number of groups where the words in each group denote the same name. Examples Input 10 mihail oolyana kooooper hoon ulyana koouper mikhail khun kuooper kkkhoon Output 4 Input 9 hariton hkariton buoi kkkhariton boooi bui khariton boui boi Output 5 Input 2 alex alex Output 1 Note There are four groups of words in the first example. Words in each group denote same name: 1. "mihail", "mikhail" 2. "oolyana", "ulyana" 3. "kooooper", "koouper" 4. "hoon", "khun", "kkkhoon" There are five groups of words in the second example. Words in each group denote same name: 1. "hariton", "kkkhariton", "khariton" 2. "hkariton" 3. "buoi", "boooi", "boui" 4. "bui" 5. "boi" In the third example the words are equal, so they denote the same name. ### Response ```cpp #include <bits/stdc++.h> using namespace std; int main() { int n, i, j; cin >> n; string p = ""; vector<string> s(n); for (i = 0; i < n; i++) cin >> s[i]; for (j = 0; j < n; j++) { p = s[j]; if (p == "u") p = "oo"; for (i = 1; i < p.length(); i++) { if (p[i - 1] == 'u') { p = p.substr(0, i - 1) + "oo" + p.substr(i, p.length()); } if (p[p.length() - 1] == 'u') p = p.substr(0, p.length() - 1) + "oo"; if (p[i - 1] == 'k' && p[i] == 'h') { p = p.substr(0, i - 1) + p.substr(i, p.length()); i = 0; } } s[j] = p; p = ""; } sort(s.begin(), s.end()); s.erase(unique(s.begin(), s.end()), s.end()); cout << s.size(); return 0; } ```
#include <bits/stdc++.h> using namespace std; const int N = 420; int ans; int d[N][100], w[N], n, rk[N]; char st[100]; bool pd(int a, int b) { int yu = ((w[a] > w[b]) ? (w[a]) : (w[b])); for (int i = 1; i <= yu; i++) { if (d[a][i] < d[b][i]) return 1; if (d[a][i] > d[b][i]) return 0; } return 0; } bool same(int a, int b) { int yu = ((w[a] > w[b]) ? (w[a]) : (w[b])); for (int i = 1; i <= yu; i++) if (d[a][i] != d[b][i]) return 0; return 1; } int main() { scanf("%d", &n); for (int i = 1; i <= n; i++) { scanf("%s", st); int sl = strlen(st); w[i] = 0; for (int j = sl - 1; j >= 0; j--) { if (d[i][w[i]] == 'h' - 'a' + 1 && st[j] == 'k') continue; if (st[j] == 'u') { d[i][++w[i]] = 'o' - 'a' + 1; d[i][++w[i]] = 'o' - 'a' + 1; continue; } d[i][++w[i]] = st[j] - 'a' + 1; } rk[i] = i; } sort(rk + 1, rk + 1 + n, pd); ans = 0; for (int i = 1; i <= n; i++) if (!same(rk[i - 1], rk[i])) ans++; printf("%d\n", ans); return 0; }
### Prompt Your challenge is to write a Cpp solution to the following problem: There are some ambiguities when one writes Berland names with the letters of the Latin alphabet. For example, the Berland sound u can be written in the Latin alphabet as "u", and can be written as "oo". For this reason, two words "ulyana" and "oolyana" denote the same name. The second ambiguity is about the Berland sound h: one can use both "h" and "kh" to write it. For example, the words "mihail" and "mikhail" denote the same name. There are n users registered on the Polycarp's website. Each of them indicated a name represented by the Latin letters. How many distinct names are there among them, if two ambiguities described above are taken into account? Formally, we assume that two words denote the same name, if using the replacements "u" <image> "oo" and "h" <image> "kh", you can make the words equal. One can make replacements in both directions, in any of the two words an arbitrary number of times. A letter that resulted from the previous replacement can participate in the next replacements. For example, the following pairs of words denote the same name: * "koouper" and "kuooper". Making the replacements described above, you can make both words to be equal: "koouper" <image> "kuuper" and "kuooper" <image> "kuuper". * "khun" and "kkkhoon". With the replacements described above you can make both words to be equal: "khun" <image> "khoon" and "kkkhoon" <image> "kkhoon" <image> "khoon". For a given list of words, find the minimal number of groups where the words in each group denote the same name. Input The first line contains integer number n (2 ≀ n ≀ 400) β€” number of the words in the list. The following n lines contain words, one word per line. Each word consists of only lowercase Latin letters. The length of each word is between 1 and 20 letters inclusive. Output Print the minimal number of groups where the words in each group denote the same name. Examples Input 10 mihail oolyana kooooper hoon ulyana koouper mikhail khun kuooper kkkhoon Output 4 Input 9 hariton hkariton buoi kkkhariton boooi bui khariton boui boi Output 5 Input 2 alex alex Output 1 Note There are four groups of words in the first example. Words in each group denote same name: 1. "mihail", "mikhail" 2. "oolyana", "ulyana" 3. "kooooper", "koouper" 4. "hoon", "khun", "kkkhoon" There are five groups of words in the second example. Words in each group denote same name: 1. "hariton", "kkkhariton", "khariton" 2. "hkariton" 3. "buoi", "boooi", "boui" 4. "bui" 5. "boi" In the third example the words are equal, so they denote the same name. ### Response ```cpp #include <bits/stdc++.h> using namespace std; const int N = 420; int ans; int d[N][100], w[N], n, rk[N]; char st[100]; bool pd(int a, int b) { int yu = ((w[a] > w[b]) ? (w[a]) : (w[b])); for (int i = 1; i <= yu; i++) { if (d[a][i] < d[b][i]) return 1; if (d[a][i] > d[b][i]) return 0; } return 0; } bool same(int a, int b) { int yu = ((w[a] > w[b]) ? (w[a]) : (w[b])); for (int i = 1; i <= yu; i++) if (d[a][i] != d[b][i]) return 0; return 1; } int main() { scanf("%d", &n); for (int i = 1; i <= n; i++) { scanf("%s", st); int sl = strlen(st); w[i] = 0; for (int j = sl - 1; j >= 0; j--) { if (d[i][w[i]] == 'h' - 'a' + 1 && st[j] == 'k') continue; if (st[j] == 'u') { d[i][++w[i]] = 'o' - 'a' + 1; d[i][++w[i]] = 'o' - 'a' + 1; continue; } d[i][++w[i]] = st[j] - 'a' + 1; } rk[i] = i; } sort(rk + 1, rk + 1 + n, pd); ans = 0; for (int i = 1; i <= n; i++) if (!same(rk[i - 1], rk[i])) ans++; printf("%d\n", ans); return 0; } ```
#include <bits/stdc++.h> #pragma warning(disable : 4996) #pragma comment(linker, "/STACK:336777216") using namespace std; int IT_MAX = 1 << 19; const long long MOD = 1000000007; const int INF = 0x3f3f3f3f; const long long LL_INF = 0x1f3f3f3f3f3f3f3f; const double PI = acos(-1); const double ERR = 1e-12; char in[105]; char u[105]; set<string> Sx; int main() { int N, i, j; scanf("%d", &N); while (N--) { scanf("%s", in); int L = 0; for (i = 0; in[i] != 0; i++) { if (in[i] == 'u') { u[L] = 'o'; u[L + 1] = 'o'; L += 2; } else if (in[i] == 'h') { while (L >= 1 && u[L - 1] == 'k') L--; u[L++] = in[i]; } else u[L++] = in[i]; } u[L] = 0; Sx.emplace(u); } printf("%d\n", (int)Sx.size()); }
### Prompt Generate a Cpp solution to the following problem: There are some ambiguities when one writes Berland names with the letters of the Latin alphabet. For example, the Berland sound u can be written in the Latin alphabet as "u", and can be written as "oo". For this reason, two words "ulyana" and "oolyana" denote the same name. The second ambiguity is about the Berland sound h: one can use both "h" and "kh" to write it. For example, the words "mihail" and "mikhail" denote the same name. There are n users registered on the Polycarp's website. Each of them indicated a name represented by the Latin letters. How many distinct names are there among them, if two ambiguities described above are taken into account? Formally, we assume that two words denote the same name, if using the replacements "u" <image> "oo" and "h" <image> "kh", you can make the words equal. One can make replacements in both directions, in any of the two words an arbitrary number of times. A letter that resulted from the previous replacement can participate in the next replacements. For example, the following pairs of words denote the same name: * "koouper" and "kuooper". Making the replacements described above, you can make both words to be equal: "koouper" <image> "kuuper" and "kuooper" <image> "kuuper". * "khun" and "kkkhoon". With the replacements described above you can make both words to be equal: "khun" <image> "khoon" and "kkkhoon" <image> "kkhoon" <image> "khoon". For a given list of words, find the minimal number of groups where the words in each group denote the same name. Input The first line contains integer number n (2 ≀ n ≀ 400) β€” number of the words in the list. The following n lines contain words, one word per line. Each word consists of only lowercase Latin letters. The length of each word is between 1 and 20 letters inclusive. Output Print the minimal number of groups where the words in each group denote the same name. Examples Input 10 mihail oolyana kooooper hoon ulyana koouper mikhail khun kuooper kkkhoon Output 4 Input 9 hariton hkariton buoi kkkhariton boooi bui khariton boui boi Output 5 Input 2 alex alex Output 1 Note There are four groups of words in the first example. Words in each group denote same name: 1. "mihail", "mikhail" 2. "oolyana", "ulyana" 3. "kooooper", "koouper" 4. "hoon", "khun", "kkkhoon" There are five groups of words in the second example. Words in each group denote same name: 1. "hariton", "kkkhariton", "khariton" 2. "hkariton" 3. "buoi", "boooi", "boui" 4. "bui" 5. "boi" In the third example the words are equal, so they denote the same name. ### Response ```cpp #include <bits/stdc++.h> #pragma warning(disable : 4996) #pragma comment(linker, "/STACK:336777216") using namespace std; int IT_MAX = 1 << 19; const long long MOD = 1000000007; const int INF = 0x3f3f3f3f; const long long LL_INF = 0x1f3f3f3f3f3f3f3f; const double PI = acos(-1); const double ERR = 1e-12; char in[105]; char u[105]; set<string> Sx; int main() { int N, i, j; scanf("%d", &N); while (N--) { scanf("%s", in); int L = 0; for (i = 0; in[i] != 0; i++) { if (in[i] == 'u') { u[L] = 'o'; u[L + 1] = 'o'; L += 2; } else if (in[i] == 'h') { while (L >= 1 && u[L - 1] == 'k') L--; u[L++] = in[i]; } else u[L++] = in[i]; } u[L] = 0; Sx.emplace(u); } printf("%d\n", (int)Sx.size()); } ```
#include <bits/stdc++.h> using namespace std; set<string> s; string str; void init() { s.clear(); } int main() { int n; while (~scanf("%d", &n)) { init(); for (int i = 0; i < n; i++) { cin >> str; string tp = ""; int len = str.size(); for (int j = 0; j < len; j++) { if (str[j] == 'u') { tp += "oo"; } else if (str[j] == 'k') { bool flag = false; for (int k = j + 1; k < len; k++) { if (str[k] == 'k') continue; else if (str[k] == 'h') { tp += "h"; j = k; flag = true; break; } else { break; } } if (!flag) { tp += str[j]; } } else { tp += str[j]; } } s.insert(tp); } printf("%d\n", s.size()); } }
### Prompt Please formulate a cpp solution to the following problem: There are some ambiguities when one writes Berland names with the letters of the Latin alphabet. For example, the Berland sound u can be written in the Latin alphabet as "u", and can be written as "oo". For this reason, two words "ulyana" and "oolyana" denote the same name. The second ambiguity is about the Berland sound h: one can use both "h" and "kh" to write it. For example, the words "mihail" and "mikhail" denote the same name. There are n users registered on the Polycarp's website. Each of them indicated a name represented by the Latin letters. How many distinct names are there among them, if two ambiguities described above are taken into account? Formally, we assume that two words denote the same name, if using the replacements "u" <image> "oo" and "h" <image> "kh", you can make the words equal. One can make replacements in both directions, in any of the two words an arbitrary number of times. A letter that resulted from the previous replacement can participate in the next replacements. For example, the following pairs of words denote the same name: * "koouper" and "kuooper". Making the replacements described above, you can make both words to be equal: "koouper" <image> "kuuper" and "kuooper" <image> "kuuper". * "khun" and "kkkhoon". With the replacements described above you can make both words to be equal: "khun" <image> "khoon" and "kkkhoon" <image> "kkhoon" <image> "khoon". For a given list of words, find the minimal number of groups where the words in each group denote the same name. Input The first line contains integer number n (2 ≀ n ≀ 400) β€” number of the words in the list. The following n lines contain words, one word per line. Each word consists of only lowercase Latin letters. The length of each word is between 1 and 20 letters inclusive. Output Print the minimal number of groups where the words in each group denote the same name. Examples Input 10 mihail oolyana kooooper hoon ulyana koouper mikhail khun kuooper kkkhoon Output 4 Input 9 hariton hkariton buoi kkkhariton boooi bui khariton boui boi Output 5 Input 2 alex alex Output 1 Note There are four groups of words in the first example. Words in each group denote same name: 1. "mihail", "mikhail" 2. "oolyana", "ulyana" 3. "kooooper", "koouper" 4. "hoon", "khun", "kkkhoon" There are five groups of words in the second example. Words in each group denote same name: 1. "hariton", "kkkhariton", "khariton" 2. "hkariton" 3. "buoi", "boooi", "boui" 4. "bui" 5. "boi" In the third example the words are equal, so they denote the same name. ### Response ```cpp #include <bits/stdc++.h> using namespace std; set<string> s; string str; void init() { s.clear(); } int main() { int n; while (~scanf("%d", &n)) { init(); for (int i = 0; i < n; i++) { cin >> str; string tp = ""; int len = str.size(); for (int j = 0; j < len; j++) { if (str[j] == 'u') { tp += "oo"; } else if (str[j] == 'k') { bool flag = false; for (int k = j + 1; k < len; k++) { if (str[k] == 'k') continue; else if (str[k] == 'h') { tp += "h"; j = k; flag = true; break; } else { break; } } if (!flag) { tp += str[j]; } } else { tp += str[j]; } } s.insert(tp); } printf("%d\n", s.size()); } } ```
#include <bits/stdc++.h> using namespace std; int ans(vector<string>& str) { int n = str.size(); for (int i = 0; i < n; ++i) { string::iterator itr; for (itr = str[i].begin(); itr != str[i].end(); ++itr) { if (*itr == 'k' && *(itr + 1) == 'h') { *itr = 'h'; str[i].erase(itr + 1); itr = str[i].begin(); itr--; } if (*itr == 'u') { *itr = 'o'; int ind = itr - str[i].begin(); string temp = "o"; str[i].insert(ind, temp); itr = str[i].begin(); itr--; } } } map<string, int> count; for (int i = 0; i < n; ++i) { count[str[i]]++; } return count.size(); } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n; cin >> n; vector<string> str(n); for (int i = 0; i < n; ++i) cin >> str[i]; cout << ans(str) << endl; return 0; }
### Prompt Please formulate a cpp solution to the following problem: There are some ambiguities when one writes Berland names with the letters of the Latin alphabet. For example, the Berland sound u can be written in the Latin alphabet as "u", and can be written as "oo". For this reason, two words "ulyana" and "oolyana" denote the same name. The second ambiguity is about the Berland sound h: one can use both "h" and "kh" to write it. For example, the words "mihail" and "mikhail" denote the same name. There are n users registered on the Polycarp's website. Each of them indicated a name represented by the Latin letters. How many distinct names are there among them, if two ambiguities described above are taken into account? Formally, we assume that two words denote the same name, if using the replacements "u" <image> "oo" and "h" <image> "kh", you can make the words equal. One can make replacements in both directions, in any of the two words an arbitrary number of times. A letter that resulted from the previous replacement can participate in the next replacements. For example, the following pairs of words denote the same name: * "koouper" and "kuooper". Making the replacements described above, you can make both words to be equal: "koouper" <image> "kuuper" and "kuooper" <image> "kuuper". * "khun" and "kkkhoon". With the replacements described above you can make both words to be equal: "khun" <image> "khoon" and "kkkhoon" <image> "kkhoon" <image> "khoon". For a given list of words, find the minimal number of groups where the words in each group denote the same name. Input The first line contains integer number n (2 ≀ n ≀ 400) β€” number of the words in the list. The following n lines contain words, one word per line. Each word consists of only lowercase Latin letters. The length of each word is between 1 and 20 letters inclusive. Output Print the minimal number of groups where the words in each group denote the same name. Examples Input 10 mihail oolyana kooooper hoon ulyana koouper mikhail khun kuooper kkkhoon Output 4 Input 9 hariton hkariton buoi kkkhariton boooi bui khariton boui boi Output 5 Input 2 alex alex Output 1 Note There are four groups of words in the first example. Words in each group denote same name: 1. "mihail", "mikhail" 2. "oolyana", "ulyana" 3. "kooooper", "koouper" 4. "hoon", "khun", "kkkhoon" There are five groups of words in the second example. Words in each group denote same name: 1. "hariton", "kkkhariton", "khariton" 2. "hkariton" 3. "buoi", "boooi", "boui" 4. "bui" 5. "boi" In the third example the words are equal, so they denote the same name. ### Response ```cpp #include <bits/stdc++.h> using namespace std; int ans(vector<string>& str) { int n = str.size(); for (int i = 0; i < n; ++i) { string::iterator itr; for (itr = str[i].begin(); itr != str[i].end(); ++itr) { if (*itr == 'k' && *(itr + 1) == 'h') { *itr = 'h'; str[i].erase(itr + 1); itr = str[i].begin(); itr--; } if (*itr == 'u') { *itr = 'o'; int ind = itr - str[i].begin(); string temp = "o"; str[i].insert(ind, temp); itr = str[i].begin(); itr--; } } } map<string, int> count; for (int i = 0; i < n; ++i) { count[str[i]]++; } return count.size(); } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n; cin >> n; vector<string> str(n); for (int i = 0; i < n; ++i) cin >> str[i]; cout << ans(str) << endl; return 0; } ```
#include <bits/stdc++.h> using namespace std; const long long int N = 1e5; const long long int mod = 1e9 + 7; void solve() { long long int n, idx; string a; set<string> grps; vector<string> trans; cin >> n; for (long long int i = 0; i < n; i++) { trans.clear(); cin >> a; idx = a.size() - 1; while (idx >= 0) { if (a[idx] == 'u') { trans.push_back("oo"); idx--; } else if (a[idx] == 'h') { idx = idx - 1; while (idx >= 0 && a[idx] == 'k') idx--; trans.push_back("h"); } else { string str = ""; str += a[idx]; trans.push_back(str); idx--; } } grps.insert(accumulate(trans.rbegin(), trans.rend(), string(""))); } cout << grps.size(); } int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); clock_t t1, t2; t1 = clock(); long long int t = 1; while (t--) { solve(); } return 0; }
### Prompt Your task is to create a CPP solution to the following problem: There are some ambiguities when one writes Berland names with the letters of the Latin alphabet. For example, the Berland sound u can be written in the Latin alphabet as "u", and can be written as "oo". For this reason, two words "ulyana" and "oolyana" denote the same name. The second ambiguity is about the Berland sound h: one can use both "h" and "kh" to write it. For example, the words "mihail" and "mikhail" denote the same name. There are n users registered on the Polycarp's website. Each of them indicated a name represented by the Latin letters. How many distinct names are there among them, if two ambiguities described above are taken into account? Formally, we assume that two words denote the same name, if using the replacements "u" <image> "oo" and "h" <image> "kh", you can make the words equal. One can make replacements in both directions, in any of the two words an arbitrary number of times. A letter that resulted from the previous replacement can participate in the next replacements. For example, the following pairs of words denote the same name: * "koouper" and "kuooper". Making the replacements described above, you can make both words to be equal: "koouper" <image> "kuuper" and "kuooper" <image> "kuuper". * "khun" and "kkkhoon". With the replacements described above you can make both words to be equal: "khun" <image> "khoon" and "kkkhoon" <image> "kkhoon" <image> "khoon". For a given list of words, find the minimal number of groups where the words in each group denote the same name. Input The first line contains integer number n (2 ≀ n ≀ 400) β€” number of the words in the list. The following n lines contain words, one word per line. Each word consists of only lowercase Latin letters. The length of each word is between 1 and 20 letters inclusive. Output Print the minimal number of groups where the words in each group denote the same name. Examples Input 10 mihail oolyana kooooper hoon ulyana koouper mikhail khun kuooper kkkhoon Output 4 Input 9 hariton hkariton buoi kkkhariton boooi bui khariton boui boi Output 5 Input 2 alex alex Output 1 Note There are four groups of words in the first example. Words in each group denote same name: 1. "mihail", "mikhail" 2. "oolyana", "ulyana" 3. "kooooper", "koouper" 4. "hoon", "khun", "kkkhoon" There are five groups of words in the second example. Words in each group denote same name: 1. "hariton", "kkkhariton", "khariton" 2. "hkariton" 3. "buoi", "boooi", "boui" 4. "bui" 5. "boi" In the third example the words are equal, so they denote the same name. ### Response ```cpp #include <bits/stdc++.h> using namespace std; const long long int N = 1e5; const long long int mod = 1e9 + 7; void solve() { long long int n, idx; string a; set<string> grps; vector<string> trans; cin >> n; for (long long int i = 0; i < n; i++) { trans.clear(); cin >> a; idx = a.size() - 1; while (idx >= 0) { if (a[idx] == 'u') { trans.push_back("oo"); idx--; } else if (a[idx] == 'h') { idx = idx - 1; while (idx >= 0 && a[idx] == 'k') idx--; trans.push_back("h"); } else { string str = ""; str += a[idx]; trans.push_back(str); idx--; } } grps.insert(accumulate(trans.rbegin(), trans.rend(), string(""))); } cout << grps.size(); } int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); clock_t t1, t2; t1 = clock(); long long int t = 1; while (t--) { solve(); } return 0; } ```
#include <bits/stdc++.h> using namespace std; #pragma GCC diagnostic ignored "-Wmissing-declarations" string shorter(string s) { for (;;) { int ex = 0; auto f = s.find("oo"); string ns; int n; if (f == string::npos) { ++ex; goto lab1; } n = s.length(); ns = s.substr(0, f) + "u"; if (f + 2 < n) ns += s.substr(f + 2, n - f - 2); s.swap(ns); lab1: f = s.find("ou"); if (f == string::npos) { ++ex; goto lab2; } n = s.length(); ns = s.substr(0, f) + "uo"; if (f + 2 < n) ns += s.substr(f + 2, n - f - 2); s.swap(ns); lab2: if (ex == 2) break; } for (;;) { auto f = s.find("kh"); if (f == string::npos) break; int n = s.length(); auto ns = s.substr(0, f) + "h"; if (f + 2 < n) ns += s.substr(f + 2, n - f - 2); s.swap(ns); } return s; } int main() { ios_base::sync_with_stdio(false); int n; cin >> n; set<string> a; while (n--) { string s; cin >> s; a.insert(shorter(s)); } cout << a.size() << endl; }
### Prompt Your challenge is to write a Cpp solution to the following problem: There are some ambiguities when one writes Berland names with the letters of the Latin alphabet. For example, the Berland sound u can be written in the Latin alphabet as "u", and can be written as "oo". For this reason, two words "ulyana" and "oolyana" denote the same name. The second ambiguity is about the Berland sound h: one can use both "h" and "kh" to write it. For example, the words "mihail" and "mikhail" denote the same name. There are n users registered on the Polycarp's website. Each of them indicated a name represented by the Latin letters. How many distinct names are there among them, if two ambiguities described above are taken into account? Formally, we assume that two words denote the same name, if using the replacements "u" <image> "oo" and "h" <image> "kh", you can make the words equal. One can make replacements in both directions, in any of the two words an arbitrary number of times. A letter that resulted from the previous replacement can participate in the next replacements. For example, the following pairs of words denote the same name: * "koouper" and "kuooper". Making the replacements described above, you can make both words to be equal: "koouper" <image> "kuuper" and "kuooper" <image> "kuuper". * "khun" and "kkkhoon". With the replacements described above you can make both words to be equal: "khun" <image> "khoon" and "kkkhoon" <image> "kkhoon" <image> "khoon". For a given list of words, find the minimal number of groups where the words in each group denote the same name. Input The first line contains integer number n (2 ≀ n ≀ 400) β€” number of the words in the list. The following n lines contain words, one word per line. Each word consists of only lowercase Latin letters. The length of each word is between 1 and 20 letters inclusive. Output Print the minimal number of groups where the words in each group denote the same name. Examples Input 10 mihail oolyana kooooper hoon ulyana koouper mikhail khun kuooper kkkhoon Output 4 Input 9 hariton hkariton buoi kkkhariton boooi bui khariton boui boi Output 5 Input 2 alex alex Output 1 Note There are four groups of words in the first example. Words in each group denote same name: 1. "mihail", "mikhail" 2. "oolyana", "ulyana" 3. "kooooper", "koouper" 4. "hoon", "khun", "kkkhoon" There are five groups of words in the second example. Words in each group denote same name: 1. "hariton", "kkkhariton", "khariton" 2. "hkariton" 3. "buoi", "boooi", "boui" 4. "bui" 5. "boi" In the third example the words are equal, so they denote the same name. ### Response ```cpp #include <bits/stdc++.h> using namespace std; #pragma GCC diagnostic ignored "-Wmissing-declarations" string shorter(string s) { for (;;) { int ex = 0; auto f = s.find("oo"); string ns; int n; if (f == string::npos) { ++ex; goto lab1; } n = s.length(); ns = s.substr(0, f) + "u"; if (f + 2 < n) ns += s.substr(f + 2, n - f - 2); s.swap(ns); lab1: f = s.find("ou"); if (f == string::npos) { ++ex; goto lab2; } n = s.length(); ns = s.substr(0, f) + "uo"; if (f + 2 < n) ns += s.substr(f + 2, n - f - 2); s.swap(ns); lab2: if (ex == 2) break; } for (;;) { auto f = s.find("kh"); if (f == string::npos) break; int n = s.length(); auto ns = s.substr(0, f) + "h"; if (f + 2 < n) ns += s.substr(f + 2, n - f - 2); s.swap(ns); } return s; } int main() { ios_base::sync_with_stdio(false); int n; cin >> n; set<string> a; while (n--) { string s; cin >> s; a.insert(shorter(s)); } cout << a.size() << endl; } ```
#include <bits/stdc++.h> using namespace std; const int INF = 1 << 30; const int maxn = 2333333; const int mod = 1000000007; string str, s[maxn]; int n, ans = 0; int main() { cin >> n; for (int t = 0; t < n; t++) { cin >> str; for (int i = 0; i < str.size(); i++) { if (str[i] == 'u') s[t] = s[t] + "oo"; else if (str[i] == 'k') { int j = i; while (j < str.size() && str[j] == 'k') j++; if (str[j] != 'h') { s[t] = s[t] + str.substr(i, j - i); i = j - 1; } } else s[t] = s[t] + str[i]; } } map<string, int> mp; int cnt = 0; for (int i = 0; i < n; i++) { if (!mp.count(s[i])) { mp[s[i]] = cnt++; } } cout << cnt << endl; return 0; }
### Prompt Please create a solution in CPP to the following problem: There are some ambiguities when one writes Berland names with the letters of the Latin alphabet. For example, the Berland sound u can be written in the Latin alphabet as "u", and can be written as "oo". For this reason, two words "ulyana" and "oolyana" denote the same name. The second ambiguity is about the Berland sound h: one can use both "h" and "kh" to write it. For example, the words "mihail" and "mikhail" denote the same name. There are n users registered on the Polycarp's website. Each of them indicated a name represented by the Latin letters. How many distinct names are there among them, if two ambiguities described above are taken into account? Formally, we assume that two words denote the same name, if using the replacements "u" <image> "oo" and "h" <image> "kh", you can make the words equal. One can make replacements in both directions, in any of the two words an arbitrary number of times. A letter that resulted from the previous replacement can participate in the next replacements. For example, the following pairs of words denote the same name: * "koouper" and "kuooper". Making the replacements described above, you can make both words to be equal: "koouper" <image> "kuuper" and "kuooper" <image> "kuuper". * "khun" and "kkkhoon". With the replacements described above you can make both words to be equal: "khun" <image> "khoon" and "kkkhoon" <image> "kkhoon" <image> "khoon". For a given list of words, find the minimal number of groups where the words in each group denote the same name. Input The first line contains integer number n (2 ≀ n ≀ 400) β€” number of the words in the list. The following n lines contain words, one word per line. Each word consists of only lowercase Latin letters. The length of each word is between 1 and 20 letters inclusive. Output Print the minimal number of groups where the words in each group denote the same name. Examples Input 10 mihail oolyana kooooper hoon ulyana koouper mikhail khun kuooper kkkhoon Output 4 Input 9 hariton hkariton buoi kkkhariton boooi bui khariton boui boi Output 5 Input 2 alex alex Output 1 Note There are four groups of words in the first example. Words in each group denote same name: 1. "mihail", "mikhail" 2. "oolyana", "ulyana" 3. "kooooper", "koouper" 4. "hoon", "khun", "kkkhoon" There are five groups of words in the second example. Words in each group denote same name: 1. "hariton", "kkkhariton", "khariton" 2. "hkariton" 3. "buoi", "boooi", "boui" 4. "bui" 5. "boi" In the third example the words are equal, so they denote the same name. ### Response ```cpp #include <bits/stdc++.h> using namespace std; const int INF = 1 << 30; const int maxn = 2333333; const int mod = 1000000007; string str, s[maxn]; int n, ans = 0; int main() { cin >> n; for (int t = 0; t < n; t++) { cin >> str; for (int i = 0; i < str.size(); i++) { if (str[i] == 'u') s[t] = s[t] + "oo"; else if (str[i] == 'k') { int j = i; while (j < str.size() && str[j] == 'k') j++; if (str[j] != 'h') { s[t] = s[t] + str.substr(i, j - i); i = j - 1; } } else s[t] = s[t] + str[i]; } } map<string, int> mp; int cnt = 0; for (int i = 0; i < n; i++) { if (!mp.count(s[i])) { mp[s[i]] = cnt++; } } cout << cnt << endl; return 0; } ```
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; string s[100000]; cin.get(); int i = 0; while (n--) { getline(cin, s[i]); stack<char> sk; for (int j = 0; j < s[i].size(); j++) { if (!sk.empty() && s[i][j] == 'h' && sk.top() == 'k') { while (sk.top() == 'k' && sk.size() > 1) sk.pop(); if (sk.top() == 'k') { sk.pop(); } sk.push('h'); } else if (s[i][j] == 'u') { sk.push('o'); sk.push('o'); } else { sk.push(s[i][j]); } } s[i].resize(sk.size()); for (int j = sk.size() - 1; j >= 0; j--) { s[i][j] = sk.top(); sk.pop(); } i++; } sort(s, s + i); int count = 1; string recent = s[0]; for (int j = 1; j < (i); j++) { if (recent != s[j]) { recent = s[j]; count++; } } cout << count; return 0; }
### Prompt Construct a cpp code solution to the problem outlined: There are some ambiguities when one writes Berland names with the letters of the Latin alphabet. For example, the Berland sound u can be written in the Latin alphabet as "u", and can be written as "oo". For this reason, two words "ulyana" and "oolyana" denote the same name. The second ambiguity is about the Berland sound h: one can use both "h" and "kh" to write it. For example, the words "mihail" and "mikhail" denote the same name. There are n users registered on the Polycarp's website. Each of them indicated a name represented by the Latin letters. How many distinct names are there among them, if two ambiguities described above are taken into account? Formally, we assume that two words denote the same name, if using the replacements "u" <image> "oo" and "h" <image> "kh", you can make the words equal. One can make replacements in both directions, in any of the two words an arbitrary number of times. A letter that resulted from the previous replacement can participate in the next replacements. For example, the following pairs of words denote the same name: * "koouper" and "kuooper". Making the replacements described above, you can make both words to be equal: "koouper" <image> "kuuper" and "kuooper" <image> "kuuper". * "khun" and "kkkhoon". With the replacements described above you can make both words to be equal: "khun" <image> "khoon" and "kkkhoon" <image> "kkhoon" <image> "khoon". For a given list of words, find the minimal number of groups where the words in each group denote the same name. Input The first line contains integer number n (2 ≀ n ≀ 400) β€” number of the words in the list. The following n lines contain words, one word per line. Each word consists of only lowercase Latin letters. The length of each word is between 1 and 20 letters inclusive. Output Print the minimal number of groups where the words in each group denote the same name. Examples Input 10 mihail oolyana kooooper hoon ulyana koouper mikhail khun kuooper kkkhoon Output 4 Input 9 hariton hkariton buoi kkkhariton boooi bui khariton boui boi Output 5 Input 2 alex alex Output 1 Note There are four groups of words in the first example. Words in each group denote same name: 1. "mihail", "mikhail" 2. "oolyana", "ulyana" 3. "kooooper", "koouper" 4. "hoon", "khun", "kkkhoon" There are five groups of words in the second example. Words in each group denote same name: 1. "hariton", "kkkhariton", "khariton" 2. "hkariton" 3. "buoi", "boooi", "boui" 4. "bui" 5. "boi" In the third example the words are equal, so they denote the same name. ### Response ```cpp #include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; string s[100000]; cin.get(); int i = 0; while (n--) { getline(cin, s[i]); stack<char> sk; for (int j = 0; j < s[i].size(); j++) { if (!sk.empty() && s[i][j] == 'h' && sk.top() == 'k') { while (sk.top() == 'k' && sk.size() > 1) sk.pop(); if (sk.top() == 'k') { sk.pop(); } sk.push('h'); } else if (s[i][j] == 'u') { sk.push('o'); sk.push('o'); } else { sk.push(s[i][j]); } } s[i].resize(sk.size()); for (int j = sk.size() - 1; j >= 0; j--) { s[i][j] = sk.top(); sk.pop(); } i++; } sort(s, s + i); int count = 1; string recent = s[0]; for (int j = 1; j < (i); j++) { if (recent != s[j]) { recent = s[j]; count++; } } cout << count; return 0; } ```
#include <bits/stdc++.h> using namespace std; vector<string> res; set<string> ss; int main() { int n; cin >> n; for (int i = 1; i <= n; i++) { string d; cin >> d; int z = d.size(); string s1 = ""; for (int j = 0; j < z; j++) { if (d[j] == 'u') { s1.push_back('o'); s1.push_back('o'); continue; } s1.push_back(d[j]); } d = s1; z = d.size(); int kk = 1; string s = ""; for (int j = 0; j < z; j++) { if (d[j] != 'k') { s.push_back(d[j]); continue; } int k = 0; string o = ""; while (j < z && d[j] == 'k') { o.push_back(d[j]); j++; k++; } if (d[j] != 'h') { j--; for (int l = 0; l < k; l++) { s.push_back(o[l]); } continue; } else if (d[j] == 'h') { j--; continue; } } res.push_back(s); } for (int i = 0; i < n; i++) { ss.insert(res[i]); } cout << ss.size() << endl; }
### Prompt Your task is to create a cpp solution to the following problem: There are some ambiguities when one writes Berland names with the letters of the Latin alphabet. For example, the Berland sound u can be written in the Latin alphabet as "u", and can be written as "oo". For this reason, two words "ulyana" and "oolyana" denote the same name. The second ambiguity is about the Berland sound h: one can use both "h" and "kh" to write it. For example, the words "mihail" and "mikhail" denote the same name. There are n users registered on the Polycarp's website. Each of them indicated a name represented by the Latin letters. How many distinct names are there among them, if two ambiguities described above are taken into account? Formally, we assume that two words denote the same name, if using the replacements "u" <image> "oo" and "h" <image> "kh", you can make the words equal. One can make replacements in both directions, in any of the two words an arbitrary number of times. A letter that resulted from the previous replacement can participate in the next replacements. For example, the following pairs of words denote the same name: * "koouper" and "kuooper". Making the replacements described above, you can make both words to be equal: "koouper" <image> "kuuper" and "kuooper" <image> "kuuper". * "khun" and "kkkhoon". With the replacements described above you can make both words to be equal: "khun" <image> "khoon" and "kkkhoon" <image> "kkhoon" <image> "khoon". For a given list of words, find the minimal number of groups where the words in each group denote the same name. Input The first line contains integer number n (2 ≀ n ≀ 400) β€” number of the words in the list. The following n lines contain words, one word per line. Each word consists of only lowercase Latin letters. The length of each word is between 1 and 20 letters inclusive. Output Print the minimal number of groups where the words in each group denote the same name. Examples Input 10 mihail oolyana kooooper hoon ulyana koouper mikhail khun kuooper kkkhoon Output 4 Input 9 hariton hkariton buoi kkkhariton boooi bui khariton boui boi Output 5 Input 2 alex alex Output 1 Note There are four groups of words in the first example. Words in each group denote same name: 1. "mihail", "mikhail" 2. "oolyana", "ulyana" 3. "kooooper", "koouper" 4. "hoon", "khun", "kkkhoon" There are five groups of words in the second example. Words in each group denote same name: 1. "hariton", "kkkhariton", "khariton" 2. "hkariton" 3. "buoi", "boooi", "boui" 4. "bui" 5. "boi" In the third example the words are equal, so they denote the same name. ### Response ```cpp #include <bits/stdc++.h> using namespace std; vector<string> res; set<string> ss; int main() { int n; cin >> n; for (int i = 1; i <= n; i++) { string d; cin >> d; int z = d.size(); string s1 = ""; for (int j = 0; j < z; j++) { if (d[j] == 'u') { s1.push_back('o'); s1.push_back('o'); continue; } s1.push_back(d[j]); } d = s1; z = d.size(); int kk = 1; string s = ""; for (int j = 0; j < z; j++) { if (d[j] != 'k') { s.push_back(d[j]); continue; } int k = 0; string o = ""; while (j < z && d[j] == 'k') { o.push_back(d[j]); j++; k++; } if (d[j] != 'h') { j--; for (int l = 0; l < k; l++) { s.push_back(o[l]); } continue; } else if (d[j] == 'h') { j--; continue; } } res.push_back(s); } for (int i = 0; i < n; i++) { ss.insert(res[i]); } cout << ss.size() << endl; } ```
#include <bits/stdc++.h> int const INF = 1e9; using namespace std; const unsigned long long int mod = 1e9 + 9; int main() { int n; cin >> n; vector<string> names(n); for (int i(0); i < n; i++) { cin >> names[i]; } set<string> st; for (int i(0); i < n; i++) { string tmp; for (int j(names[i].size() - 1); j >= 0; j--) { if (names[i][j] == 'h') { tmp.push_back('h'); int l(j - 1); while (l >= 0 && names[i][l] == 'k') l--; j = l + 1; } else { if (names[i][j] == 'u') { tmp.push_back('o'); tmp.push_back('o'); } else { tmp.push_back(names[i][j]); } } } st.insert(tmp); } cout << st.size(); return 0; }
### Prompt Your task is to create a CPP solution to the following problem: There are some ambiguities when one writes Berland names with the letters of the Latin alphabet. For example, the Berland sound u can be written in the Latin alphabet as "u", and can be written as "oo". For this reason, two words "ulyana" and "oolyana" denote the same name. The second ambiguity is about the Berland sound h: one can use both "h" and "kh" to write it. For example, the words "mihail" and "mikhail" denote the same name. There are n users registered on the Polycarp's website. Each of them indicated a name represented by the Latin letters. How many distinct names are there among them, if two ambiguities described above are taken into account? Formally, we assume that two words denote the same name, if using the replacements "u" <image> "oo" and "h" <image> "kh", you can make the words equal. One can make replacements in both directions, in any of the two words an arbitrary number of times. A letter that resulted from the previous replacement can participate in the next replacements. For example, the following pairs of words denote the same name: * "koouper" and "kuooper". Making the replacements described above, you can make both words to be equal: "koouper" <image> "kuuper" and "kuooper" <image> "kuuper". * "khun" and "kkkhoon". With the replacements described above you can make both words to be equal: "khun" <image> "khoon" and "kkkhoon" <image> "kkhoon" <image> "khoon". For a given list of words, find the minimal number of groups where the words in each group denote the same name. Input The first line contains integer number n (2 ≀ n ≀ 400) β€” number of the words in the list. The following n lines contain words, one word per line. Each word consists of only lowercase Latin letters. The length of each word is between 1 and 20 letters inclusive. Output Print the minimal number of groups where the words in each group denote the same name. Examples Input 10 mihail oolyana kooooper hoon ulyana koouper mikhail khun kuooper kkkhoon Output 4 Input 9 hariton hkariton buoi kkkhariton boooi bui khariton boui boi Output 5 Input 2 alex alex Output 1 Note There are four groups of words in the first example. Words in each group denote same name: 1. "mihail", "mikhail" 2. "oolyana", "ulyana" 3. "kooooper", "koouper" 4. "hoon", "khun", "kkkhoon" There are five groups of words in the second example. Words in each group denote same name: 1. "hariton", "kkkhariton", "khariton" 2. "hkariton" 3. "buoi", "boooi", "boui" 4. "bui" 5. "boi" In the third example the words are equal, so they denote the same name. ### Response ```cpp #include <bits/stdc++.h> int const INF = 1e9; using namespace std; const unsigned long long int mod = 1e9 + 9; int main() { int n; cin >> n; vector<string> names(n); for (int i(0); i < n; i++) { cin >> names[i]; } set<string> st; for (int i(0); i < n; i++) { string tmp; for (int j(names[i].size() - 1); j >= 0; j--) { if (names[i][j] == 'h') { tmp.push_back('h'); int l(j - 1); while (l >= 0 && names[i][l] == 'k') l--; j = l + 1; } else { if (names[i][j] == 'u') { tmp.push_back('o'); tmp.push_back('o'); } else { tmp.push_back(names[i][j]); } } } st.insert(tmp); } cout << st.size(); return 0; } ```
#include <bits/stdc++.h> using namespace std; map<string, int> mp; int n, ans, len; int main() { int i, j; char s[100010]; scanf("%d", &n); for (int t = 1; t <= n; t++) { scanf("%s", s); len = strlen(s); for (i = 0; i < len; i++) if (s[i] == 'u') { for (j = len + 1; j > i; j--) s[j] = s[j - 1]; s[i] = 'o'; s[i + 1] = 'o'; len++; } for (i = 0; i < len; i++) while (i > 0 && s[i] == 'h' && s[i - 1] == 'k') { for (j = i - 1; j < len; j++) s[j] = s[j + 1]; i--; len--; } if (!mp[s]) mp[s] = 1, ans++; } printf("%d\n", ans); }
### Prompt Your task is to create a Cpp solution to the following problem: There are some ambiguities when one writes Berland names with the letters of the Latin alphabet. For example, the Berland sound u can be written in the Latin alphabet as "u", and can be written as "oo". For this reason, two words "ulyana" and "oolyana" denote the same name. The second ambiguity is about the Berland sound h: one can use both "h" and "kh" to write it. For example, the words "mihail" and "mikhail" denote the same name. There are n users registered on the Polycarp's website. Each of them indicated a name represented by the Latin letters. How many distinct names are there among them, if two ambiguities described above are taken into account? Formally, we assume that two words denote the same name, if using the replacements "u" <image> "oo" and "h" <image> "kh", you can make the words equal. One can make replacements in both directions, in any of the two words an arbitrary number of times. A letter that resulted from the previous replacement can participate in the next replacements. For example, the following pairs of words denote the same name: * "koouper" and "kuooper". Making the replacements described above, you can make both words to be equal: "koouper" <image> "kuuper" and "kuooper" <image> "kuuper". * "khun" and "kkkhoon". With the replacements described above you can make both words to be equal: "khun" <image> "khoon" and "kkkhoon" <image> "kkhoon" <image> "khoon". For a given list of words, find the minimal number of groups where the words in each group denote the same name. Input The first line contains integer number n (2 ≀ n ≀ 400) β€” number of the words in the list. The following n lines contain words, one word per line. Each word consists of only lowercase Latin letters. The length of each word is between 1 and 20 letters inclusive. Output Print the minimal number of groups where the words in each group denote the same name. Examples Input 10 mihail oolyana kooooper hoon ulyana koouper mikhail khun kuooper kkkhoon Output 4 Input 9 hariton hkariton buoi kkkhariton boooi bui khariton boui boi Output 5 Input 2 alex alex Output 1 Note There are four groups of words in the first example. Words in each group denote same name: 1. "mihail", "mikhail" 2. "oolyana", "ulyana" 3. "kooooper", "koouper" 4. "hoon", "khun", "kkkhoon" There are five groups of words in the second example. Words in each group denote same name: 1. "hariton", "kkkhariton", "khariton" 2. "hkariton" 3. "buoi", "boooi", "boui" 4. "bui" 5. "boi" In the third example the words are equal, so they denote the same name. ### Response ```cpp #include <bits/stdc++.h> using namespace std; map<string, int> mp; int n, ans, len; int main() { int i, j; char s[100010]; scanf("%d", &n); for (int t = 1; t <= n; t++) { scanf("%s", s); len = strlen(s); for (i = 0; i < len; i++) if (s[i] == 'u') { for (j = len + 1; j > i; j--) s[j] = s[j - 1]; s[i] = 'o'; s[i + 1] = 'o'; len++; } for (i = 0; i < len; i++) while (i > 0 && s[i] == 'h' && s[i - 1] == 'k') { for (j = i - 1; j < len; j++) s[j] = s[j + 1]; i--; len--; } if (!mp[s]) mp[s] = 1, ans++; } printf("%d\n", ans); } ```
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; string s[400]; for (int i(0); i < n; ++i) { cin >> s[i]; for (int j(0); j < s[i].length(); ++j) { if (s[i][j] == 'u') { s[i].replace(j, 1, "oo"); j = 0; } if (s[i][j] == 'h') { int numb = 0; if (j && s[i][j - 1] == 'k') { for (int k(j - 1); k >= 0; --k) { if (s[i][k] == 'k') numb++; else break; } s[i].replace(j - numb, numb + 1, "h"); j = 0; } } } } map<string, int> Map; for (int i(0); i < n; ++i) { Map[s[i]]; } cout << Map.size() << endl; return 0; }
### Prompt Please create a solution in Cpp to the following problem: There are some ambiguities when one writes Berland names with the letters of the Latin alphabet. For example, the Berland sound u can be written in the Latin alphabet as "u", and can be written as "oo". For this reason, two words "ulyana" and "oolyana" denote the same name. The second ambiguity is about the Berland sound h: one can use both "h" and "kh" to write it. For example, the words "mihail" and "mikhail" denote the same name. There are n users registered on the Polycarp's website. Each of them indicated a name represented by the Latin letters. How many distinct names are there among them, if two ambiguities described above are taken into account? Formally, we assume that two words denote the same name, if using the replacements "u" <image> "oo" and "h" <image> "kh", you can make the words equal. One can make replacements in both directions, in any of the two words an arbitrary number of times. A letter that resulted from the previous replacement can participate in the next replacements. For example, the following pairs of words denote the same name: * "koouper" and "kuooper". Making the replacements described above, you can make both words to be equal: "koouper" <image> "kuuper" and "kuooper" <image> "kuuper". * "khun" and "kkkhoon". With the replacements described above you can make both words to be equal: "khun" <image> "khoon" and "kkkhoon" <image> "kkhoon" <image> "khoon". For a given list of words, find the minimal number of groups where the words in each group denote the same name. Input The first line contains integer number n (2 ≀ n ≀ 400) β€” number of the words in the list. The following n lines contain words, one word per line. Each word consists of only lowercase Latin letters. The length of each word is between 1 and 20 letters inclusive. Output Print the minimal number of groups where the words in each group denote the same name. Examples Input 10 mihail oolyana kooooper hoon ulyana koouper mikhail khun kuooper kkkhoon Output 4 Input 9 hariton hkariton buoi kkkhariton boooi bui khariton boui boi Output 5 Input 2 alex alex Output 1 Note There are four groups of words in the first example. Words in each group denote same name: 1. "mihail", "mikhail" 2. "oolyana", "ulyana" 3. "kooooper", "koouper" 4. "hoon", "khun", "kkkhoon" There are five groups of words in the second example. Words in each group denote same name: 1. "hariton", "kkkhariton", "khariton" 2. "hkariton" 3. "buoi", "boooi", "boui" 4. "bui" 5. "boi" In the third example the words are equal, so they denote the same name. ### Response ```cpp #include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; string s[400]; for (int i(0); i < n; ++i) { cin >> s[i]; for (int j(0); j < s[i].length(); ++j) { if (s[i][j] == 'u') { s[i].replace(j, 1, "oo"); j = 0; } if (s[i][j] == 'h') { int numb = 0; if (j && s[i][j - 1] == 'k') { for (int k(j - 1); k >= 0; --k) { if (s[i][k] == 'k') numb++; else break; } s[i].replace(j - numb, numb + 1, "h"); j = 0; } } } } map<string, int> Map; for (int i(0); i < n; ++i) { Map[s[i]]; } cout << Map.size() << endl; return 0; } ```
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; set<string> S; for (int tk = 0; tk < n; ++tk) { string s; cin >> s; string as; for (int i = 0; i < s.size(); ++i) { if (s[i] == 'u') { as += "oo"; } else { as.push_back(s[i]); } } int j = 0; for (int i = 0; i < as.size(); ++i) { if (as[i] == 'h') { as.replace(j, i - j + 1, "h"); i -= (i - j); } if (as[i] != 'k') { j = i + 1; } } S.insert(as); } cout << S.size() << endl; return 0; }
### Prompt Construct a cpp code solution to the problem outlined: There are some ambiguities when one writes Berland names with the letters of the Latin alphabet. For example, the Berland sound u can be written in the Latin alphabet as "u", and can be written as "oo". For this reason, two words "ulyana" and "oolyana" denote the same name. The second ambiguity is about the Berland sound h: one can use both "h" and "kh" to write it. For example, the words "mihail" and "mikhail" denote the same name. There are n users registered on the Polycarp's website. Each of them indicated a name represented by the Latin letters. How many distinct names are there among them, if two ambiguities described above are taken into account? Formally, we assume that two words denote the same name, if using the replacements "u" <image> "oo" and "h" <image> "kh", you can make the words equal. One can make replacements in both directions, in any of the two words an arbitrary number of times. A letter that resulted from the previous replacement can participate in the next replacements. For example, the following pairs of words denote the same name: * "koouper" and "kuooper". Making the replacements described above, you can make both words to be equal: "koouper" <image> "kuuper" and "kuooper" <image> "kuuper". * "khun" and "kkkhoon". With the replacements described above you can make both words to be equal: "khun" <image> "khoon" and "kkkhoon" <image> "kkhoon" <image> "khoon". For a given list of words, find the minimal number of groups where the words in each group denote the same name. Input The first line contains integer number n (2 ≀ n ≀ 400) β€” number of the words in the list. The following n lines contain words, one word per line. Each word consists of only lowercase Latin letters. The length of each word is between 1 and 20 letters inclusive. Output Print the minimal number of groups where the words in each group denote the same name. Examples Input 10 mihail oolyana kooooper hoon ulyana koouper mikhail khun kuooper kkkhoon Output 4 Input 9 hariton hkariton buoi kkkhariton boooi bui khariton boui boi Output 5 Input 2 alex alex Output 1 Note There are four groups of words in the first example. Words in each group denote same name: 1. "mihail", "mikhail" 2. "oolyana", "ulyana" 3. "kooooper", "koouper" 4. "hoon", "khun", "kkkhoon" There are five groups of words in the second example. Words in each group denote same name: 1. "hariton", "kkkhariton", "khariton" 2. "hkariton" 3. "buoi", "boooi", "boui" 4. "bui" 5. "boi" In the third example the words are equal, so they denote the same name. ### Response ```cpp #include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; set<string> S; for (int tk = 0; tk < n; ++tk) { string s; cin >> s; string as; for (int i = 0; i < s.size(); ++i) { if (s[i] == 'u') { as += "oo"; } else { as.push_back(s[i]); } } int j = 0; for (int i = 0; i < as.size(); ++i) { if (as[i] == 'h') { as.replace(j, i - j + 1, "h"); i -= (i - j); } if (as[i] != 'k') { j = i + 1; } } S.insert(as); } cout << S.size() << endl; return 0; } ```
#include <bits/stdc++.h> using namespace std; int N; set<string> st; string convert(string s) { string t = s; while (!t.empty()) { s = t; int sz = (int)s.size(); t = ""; for (int i = 0; i < sz; i++) { if (i + 1 < sz && s[i] == 'k' && s[i + 1] == 'h') { if (i) t += s.substr(0, i); if (sz - i - 1 > 0) t += s.substr(i + 1, sz - i - 1); break; } if (s[i] == 'u') { if (i) t += s.substr(0, i); t += "oo"; if (sz - i - 1 > 0) t += s.substr(i + 1, sz - i - 1); break; } } } return s; } void solve() { cin >> N; string s; for (int i = 0; i < N; i++) { cin >> s; string t = convert(s); st.insert(t); } cout << (int)st.size() << endl; } signed main() { ios_base::sync_with_stdio(0); cin.tie(0); solve(); return 0; }
### Prompt Your task is to create a Cpp solution to the following problem: There are some ambiguities when one writes Berland names with the letters of the Latin alphabet. For example, the Berland sound u can be written in the Latin alphabet as "u", and can be written as "oo". For this reason, two words "ulyana" and "oolyana" denote the same name. The second ambiguity is about the Berland sound h: one can use both "h" and "kh" to write it. For example, the words "mihail" and "mikhail" denote the same name. There are n users registered on the Polycarp's website. Each of them indicated a name represented by the Latin letters. How many distinct names are there among them, if two ambiguities described above are taken into account? Formally, we assume that two words denote the same name, if using the replacements "u" <image> "oo" and "h" <image> "kh", you can make the words equal. One can make replacements in both directions, in any of the two words an arbitrary number of times. A letter that resulted from the previous replacement can participate in the next replacements. For example, the following pairs of words denote the same name: * "koouper" and "kuooper". Making the replacements described above, you can make both words to be equal: "koouper" <image> "kuuper" and "kuooper" <image> "kuuper". * "khun" and "kkkhoon". With the replacements described above you can make both words to be equal: "khun" <image> "khoon" and "kkkhoon" <image> "kkhoon" <image> "khoon". For a given list of words, find the minimal number of groups where the words in each group denote the same name. Input The first line contains integer number n (2 ≀ n ≀ 400) β€” number of the words in the list. The following n lines contain words, one word per line. Each word consists of only lowercase Latin letters. The length of each word is between 1 and 20 letters inclusive. Output Print the minimal number of groups where the words in each group denote the same name. Examples Input 10 mihail oolyana kooooper hoon ulyana koouper mikhail khun kuooper kkkhoon Output 4 Input 9 hariton hkariton buoi kkkhariton boooi bui khariton boui boi Output 5 Input 2 alex alex Output 1 Note There are four groups of words in the first example. Words in each group denote same name: 1. "mihail", "mikhail" 2. "oolyana", "ulyana" 3. "kooooper", "koouper" 4. "hoon", "khun", "kkkhoon" There are five groups of words in the second example. Words in each group denote same name: 1. "hariton", "kkkhariton", "khariton" 2. "hkariton" 3. "buoi", "boooi", "boui" 4. "bui" 5. "boi" In the third example the words are equal, so they denote the same name. ### Response ```cpp #include <bits/stdc++.h> using namespace std; int N; set<string> st; string convert(string s) { string t = s; while (!t.empty()) { s = t; int sz = (int)s.size(); t = ""; for (int i = 0; i < sz; i++) { if (i + 1 < sz && s[i] == 'k' && s[i + 1] == 'h') { if (i) t += s.substr(0, i); if (sz - i - 1 > 0) t += s.substr(i + 1, sz - i - 1); break; } if (s[i] == 'u') { if (i) t += s.substr(0, i); t += "oo"; if (sz - i - 1 > 0) t += s.substr(i + 1, sz - i - 1); break; } } } return s; } void solve() { cin >> N; string s; for (int i = 0; i < N; i++) { cin >> s; string t = convert(s); st.insert(t); } cout << (int)st.size() << endl; } signed main() { ios_base::sync_with_stdio(0); cin.tie(0); solve(); return 0; } ```
#include <bits/stdc++.h> using namespace std; int main() { set<string> s; int n; cin >> n; for (int i = 0; i < n; i++) { string k; cin >> k; while (k.find("u") != string::npos) k = k.replace(k.find("u"), 1, "oo"); while (k.find("kh") != string::npos) k = k.replace(k.find("kh"), 2, "h"); s.insert(k); } cout << s.size() << endl; }
### Prompt Generate a Cpp solution to the following problem: There are some ambiguities when one writes Berland names with the letters of the Latin alphabet. For example, the Berland sound u can be written in the Latin alphabet as "u", and can be written as "oo". For this reason, two words "ulyana" and "oolyana" denote the same name. The second ambiguity is about the Berland sound h: one can use both "h" and "kh" to write it. For example, the words "mihail" and "mikhail" denote the same name. There are n users registered on the Polycarp's website. Each of them indicated a name represented by the Latin letters. How many distinct names are there among them, if two ambiguities described above are taken into account? Formally, we assume that two words denote the same name, if using the replacements "u" <image> "oo" and "h" <image> "kh", you can make the words equal. One can make replacements in both directions, in any of the two words an arbitrary number of times. A letter that resulted from the previous replacement can participate in the next replacements. For example, the following pairs of words denote the same name: * "koouper" and "kuooper". Making the replacements described above, you can make both words to be equal: "koouper" <image> "kuuper" and "kuooper" <image> "kuuper". * "khun" and "kkkhoon". With the replacements described above you can make both words to be equal: "khun" <image> "khoon" and "kkkhoon" <image> "kkhoon" <image> "khoon". For a given list of words, find the minimal number of groups where the words in each group denote the same name. Input The first line contains integer number n (2 ≀ n ≀ 400) β€” number of the words in the list. The following n lines contain words, one word per line. Each word consists of only lowercase Latin letters. The length of each word is between 1 and 20 letters inclusive. Output Print the minimal number of groups where the words in each group denote the same name. Examples Input 10 mihail oolyana kooooper hoon ulyana koouper mikhail khun kuooper kkkhoon Output 4 Input 9 hariton hkariton buoi kkkhariton boooi bui khariton boui boi Output 5 Input 2 alex alex Output 1 Note There are four groups of words in the first example. Words in each group denote same name: 1. "mihail", "mikhail" 2. "oolyana", "ulyana" 3. "kooooper", "koouper" 4. "hoon", "khun", "kkkhoon" There are five groups of words in the second example. Words in each group denote same name: 1. "hariton", "kkkhariton", "khariton" 2. "hkariton" 3. "buoi", "boooi", "boui" 4. "bui" 5. "boi" In the third example the words are equal, so they denote the same name. ### Response ```cpp #include <bits/stdc++.h> using namespace std; int main() { set<string> s; int n; cin >> n; for (int i = 0; i < n; i++) { string k; cin >> k; while (k.find("u") != string::npos) k = k.replace(k.find("u"), 1, "oo"); while (k.find("kh") != string::npos) k = k.replace(k.find("kh"), 2, "h"); s.insert(k); } cout << s.size() << endl; } ```
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; set<string> s; while (n--) { string t; cin >> t; for (int i = 0; i < 30; i++) { for (int j = 0; j < t.length() - 1; j++) { if (t[j] == 'k' && t[j + 1] == 'h') { t.replace(j, 2, "h"); } if (t[j] == 'o' && t[j + 1] == 'o') { t.replace(j, 2, "u"); } if (t[j] == 'u' && t[j + 1] == 'o') { t.replace(j, 2, "ou"); } } } s.insert(t); } cout << s.size() << endl; return 0; }
### Prompt Construct a CPP code solution to the problem outlined: There are some ambiguities when one writes Berland names with the letters of the Latin alphabet. For example, the Berland sound u can be written in the Latin alphabet as "u", and can be written as "oo". For this reason, two words "ulyana" and "oolyana" denote the same name. The second ambiguity is about the Berland sound h: one can use both "h" and "kh" to write it. For example, the words "mihail" and "mikhail" denote the same name. There are n users registered on the Polycarp's website. Each of them indicated a name represented by the Latin letters. How many distinct names are there among them, if two ambiguities described above are taken into account? Formally, we assume that two words denote the same name, if using the replacements "u" <image> "oo" and "h" <image> "kh", you can make the words equal. One can make replacements in both directions, in any of the two words an arbitrary number of times. A letter that resulted from the previous replacement can participate in the next replacements. For example, the following pairs of words denote the same name: * "koouper" and "kuooper". Making the replacements described above, you can make both words to be equal: "koouper" <image> "kuuper" and "kuooper" <image> "kuuper". * "khun" and "kkkhoon". With the replacements described above you can make both words to be equal: "khun" <image> "khoon" and "kkkhoon" <image> "kkhoon" <image> "khoon". For a given list of words, find the minimal number of groups where the words in each group denote the same name. Input The first line contains integer number n (2 ≀ n ≀ 400) β€” number of the words in the list. The following n lines contain words, one word per line. Each word consists of only lowercase Latin letters. The length of each word is between 1 and 20 letters inclusive. Output Print the minimal number of groups where the words in each group denote the same name. Examples Input 10 mihail oolyana kooooper hoon ulyana koouper mikhail khun kuooper kkkhoon Output 4 Input 9 hariton hkariton buoi kkkhariton boooi bui khariton boui boi Output 5 Input 2 alex alex Output 1 Note There are four groups of words in the first example. Words in each group denote same name: 1. "mihail", "mikhail" 2. "oolyana", "ulyana" 3. "kooooper", "koouper" 4. "hoon", "khun", "kkkhoon" There are five groups of words in the second example. Words in each group denote same name: 1. "hariton", "kkkhariton", "khariton" 2. "hkariton" 3. "buoi", "boooi", "boui" 4. "bui" 5. "boi" In the third example the words are equal, so they denote the same name. ### Response ```cpp #include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; set<string> s; while (n--) { string t; cin >> t; for (int i = 0; i < 30; i++) { for (int j = 0; j < t.length() - 1; j++) { if (t[j] == 'k' && t[j + 1] == 'h') { t.replace(j, 2, "h"); } if (t[j] == 'o' && t[j + 1] == 'o') { t.replace(j, 2, "u"); } if (t[j] == 'u' && t[j + 1] == 'o') { t.replace(j, 2, "ou"); } } } s.insert(t); } cout << s.size() << endl; return 0; } ```
#include <bits/stdc++.h> using namespace std; string* input; string* filteru; int main(int argc, char* argv[]) { ios_base::sync_with_stdio(false); cin.tie(NULL); int n; cin >> n; input = new string[n]; filteru = new string[n]; for (int i = 0; i < n; i++) { cin >> input[i]; } for (int i = 0; i < n; i++) { string s = input[i]; vector<char> v; for (int j = 0; j < s.size(); j++) { if (s[j] == 'u') { v.push_back('o'); v.push_back('o'); } else { v.push_back(s[j]); } } string s2(v.begin(), v.end()); filteru[i] = s2; } set<string> distinct; for (int i = 0; i < n; i++) { string s = filteru[i]; vector<char> v; char prev = s[s.size() - 1]; v.push_back(prev); for (int j = s.size() - 2; j >= 0; j--) { if (prev == 'h' && s[j] == 'k') { prev = 'h'; } else { v.push_back(s[j]); prev = s[j]; } } reverse(v.begin(), v.end()); string s2(v.begin(), v.end()); distinct.insert(s2); } cout << distinct.size() << "\n"; }
### Prompt Please provide a cpp coded solution to the problem described below: There are some ambiguities when one writes Berland names with the letters of the Latin alphabet. For example, the Berland sound u can be written in the Latin alphabet as "u", and can be written as "oo". For this reason, two words "ulyana" and "oolyana" denote the same name. The second ambiguity is about the Berland sound h: one can use both "h" and "kh" to write it. For example, the words "mihail" and "mikhail" denote the same name. There are n users registered on the Polycarp's website. Each of them indicated a name represented by the Latin letters. How many distinct names are there among them, if two ambiguities described above are taken into account? Formally, we assume that two words denote the same name, if using the replacements "u" <image> "oo" and "h" <image> "kh", you can make the words equal. One can make replacements in both directions, in any of the two words an arbitrary number of times. A letter that resulted from the previous replacement can participate in the next replacements. For example, the following pairs of words denote the same name: * "koouper" and "kuooper". Making the replacements described above, you can make both words to be equal: "koouper" <image> "kuuper" and "kuooper" <image> "kuuper". * "khun" and "kkkhoon". With the replacements described above you can make both words to be equal: "khun" <image> "khoon" and "kkkhoon" <image> "kkhoon" <image> "khoon". For a given list of words, find the minimal number of groups where the words in each group denote the same name. Input The first line contains integer number n (2 ≀ n ≀ 400) β€” number of the words in the list. The following n lines contain words, one word per line. Each word consists of only lowercase Latin letters. The length of each word is between 1 and 20 letters inclusive. Output Print the minimal number of groups where the words in each group denote the same name. Examples Input 10 mihail oolyana kooooper hoon ulyana koouper mikhail khun kuooper kkkhoon Output 4 Input 9 hariton hkariton buoi kkkhariton boooi bui khariton boui boi Output 5 Input 2 alex alex Output 1 Note There are four groups of words in the first example. Words in each group denote same name: 1. "mihail", "mikhail" 2. "oolyana", "ulyana" 3. "kooooper", "koouper" 4. "hoon", "khun", "kkkhoon" There are five groups of words in the second example. Words in each group denote same name: 1. "hariton", "kkkhariton", "khariton" 2. "hkariton" 3. "buoi", "boooi", "boui" 4. "bui" 5. "boi" In the third example the words are equal, so they denote the same name. ### Response ```cpp #include <bits/stdc++.h> using namespace std; string* input; string* filteru; int main(int argc, char* argv[]) { ios_base::sync_with_stdio(false); cin.tie(NULL); int n; cin >> n; input = new string[n]; filteru = new string[n]; for (int i = 0; i < n; i++) { cin >> input[i]; } for (int i = 0; i < n; i++) { string s = input[i]; vector<char> v; for (int j = 0; j < s.size(); j++) { if (s[j] == 'u') { v.push_back('o'); v.push_back('o'); } else { v.push_back(s[j]); } } string s2(v.begin(), v.end()); filteru[i] = s2; } set<string> distinct; for (int i = 0; i < n; i++) { string s = filteru[i]; vector<char> v; char prev = s[s.size() - 1]; v.push_back(prev); for (int j = s.size() - 2; j >= 0; j--) { if (prev == 'h' && s[j] == 'k') { prev = 'h'; } else { v.push_back(s[j]); prev = s[j]; } } reverse(v.begin(), v.end()); string s2(v.begin(), v.end()); distinct.insert(s2); } cout << distinct.size() << "\n"; } ```
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 1; const int INF = 1e9 + 7; map<string, int> M; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; cin >> n; for (int i = 1; i <= n; ++i) { string s; cin >> s; while (1) { bool _find = false; for (int j = 0; j + 1 < (int)s.size(); ++j) { if (s.substr(j, 2) == "kh") { string t = s.substr(0, j) + s.substr(j + 1); s = t; _find = true; break; } } if (!_find) break; } while (1) { bool _find = false; for (int j = 0; j < (int)s.size(); ++j) { if (s[j] == 'u') { string t = s.substr(0, j) + "oo" + s.substr(j + 1); s = t; _find = true; break; } } if (!_find) break; } M[s]++; } cout << M.size(); }
### Prompt Construct a cpp code solution to the problem outlined: There are some ambiguities when one writes Berland names with the letters of the Latin alphabet. For example, the Berland sound u can be written in the Latin alphabet as "u", and can be written as "oo". For this reason, two words "ulyana" and "oolyana" denote the same name. The second ambiguity is about the Berland sound h: one can use both "h" and "kh" to write it. For example, the words "mihail" and "mikhail" denote the same name. There are n users registered on the Polycarp's website. Each of them indicated a name represented by the Latin letters. How many distinct names are there among them, if two ambiguities described above are taken into account? Formally, we assume that two words denote the same name, if using the replacements "u" <image> "oo" and "h" <image> "kh", you can make the words equal. One can make replacements in both directions, in any of the two words an arbitrary number of times. A letter that resulted from the previous replacement can participate in the next replacements. For example, the following pairs of words denote the same name: * "koouper" and "kuooper". Making the replacements described above, you can make both words to be equal: "koouper" <image> "kuuper" and "kuooper" <image> "kuuper". * "khun" and "kkkhoon". With the replacements described above you can make both words to be equal: "khun" <image> "khoon" and "kkkhoon" <image> "kkhoon" <image> "khoon". For a given list of words, find the minimal number of groups where the words in each group denote the same name. Input The first line contains integer number n (2 ≀ n ≀ 400) β€” number of the words in the list. The following n lines contain words, one word per line. Each word consists of only lowercase Latin letters. The length of each word is between 1 and 20 letters inclusive. Output Print the minimal number of groups where the words in each group denote the same name. Examples Input 10 mihail oolyana kooooper hoon ulyana koouper mikhail khun kuooper kkkhoon Output 4 Input 9 hariton hkariton buoi kkkhariton boooi bui khariton boui boi Output 5 Input 2 alex alex Output 1 Note There are four groups of words in the first example. Words in each group denote same name: 1. "mihail", "mikhail" 2. "oolyana", "ulyana" 3. "kooooper", "koouper" 4. "hoon", "khun", "kkkhoon" There are five groups of words in the second example. Words in each group denote same name: 1. "hariton", "kkkhariton", "khariton" 2. "hkariton" 3. "buoi", "boooi", "boui" 4. "bui" 5. "boi" In the third example the words are equal, so they denote the same name. ### Response ```cpp #include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 1; const int INF = 1e9 + 7; map<string, int> M; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; cin >> n; for (int i = 1; i <= n; ++i) { string s; cin >> s; while (1) { bool _find = false; for (int j = 0; j + 1 < (int)s.size(); ++j) { if (s.substr(j, 2) == "kh") { string t = s.substr(0, j) + s.substr(j + 1); s = t; _find = true; break; } } if (!_find) break; } while (1) { bool _find = false; for (int j = 0; j < (int)s.size(); ++j) { if (s[j] == 'u') { string t = s.substr(0, j) + "oo" + s.substr(j + 1); s = t; _find = true; break; } } if (!_find) break; } M[s]++; } cout << M.size(); } ```
#include <bits/stdc++.h> using namespace std; set<string> myset; int main() { int n; scanf("%d", &n); for (int i = 0; i < n; i++) { string s1, s2, scnt; cin >> s1; int sz = s1.size(); for (int j = 0; j < sz; j++) { if (s1[j] == 'k') { scnt += 'k'; continue; } if (scnt.size() > 0) { if (s1[j] == 'h') { s2 += 'h'; scnt = ""; continue; } else { s2 += scnt; } scnt = ""; } if (s1[j] == 'u') s2 += 'o', s2 += 'o'; else s2 += s1[j]; } if (scnt != "") s2 += scnt; myset.insert(s2); } int sz = myset.size(); printf("%d", sz); }
### Prompt Your challenge is to write a Cpp solution to the following problem: There are some ambiguities when one writes Berland names with the letters of the Latin alphabet. For example, the Berland sound u can be written in the Latin alphabet as "u", and can be written as "oo". For this reason, two words "ulyana" and "oolyana" denote the same name. The second ambiguity is about the Berland sound h: one can use both "h" and "kh" to write it. For example, the words "mihail" and "mikhail" denote the same name. There are n users registered on the Polycarp's website. Each of them indicated a name represented by the Latin letters. How many distinct names are there among them, if two ambiguities described above are taken into account? Formally, we assume that two words denote the same name, if using the replacements "u" <image> "oo" and "h" <image> "kh", you can make the words equal. One can make replacements in both directions, in any of the two words an arbitrary number of times. A letter that resulted from the previous replacement can participate in the next replacements. For example, the following pairs of words denote the same name: * "koouper" and "kuooper". Making the replacements described above, you can make both words to be equal: "koouper" <image> "kuuper" and "kuooper" <image> "kuuper". * "khun" and "kkkhoon". With the replacements described above you can make both words to be equal: "khun" <image> "khoon" and "kkkhoon" <image> "kkhoon" <image> "khoon". For a given list of words, find the minimal number of groups where the words in each group denote the same name. Input The first line contains integer number n (2 ≀ n ≀ 400) β€” number of the words in the list. The following n lines contain words, one word per line. Each word consists of only lowercase Latin letters. The length of each word is between 1 and 20 letters inclusive. Output Print the minimal number of groups where the words in each group denote the same name. Examples Input 10 mihail oolyana kooooper hoon ulyana koouper mikhail khun kuooper kkkhoon Output 4 Input 9 hariton hkariton buoi kkkhariton boooi bui khariton boui boi Output 5 Input 2 alex alex Output 1 Note There are four groups of words in the first example. Words in each group denote same name: 1. "mihail", "mikhail" 2. "oolyana", "ulyana" 3. "kooooper", "koouper" 4. "hoon", "khun", "kkkhoon" There are five groups of words in the second example. Words in each group denote same name: 1. "hariton", "kkkhariton", "khariton" 2. "hkariton" 3. "buoi", "boooi", "boui" 4. "bui" 5. "boi" In the third example the words are equal, so they denote the same name. ### Response ```cpp #include <bits/stdc++.h> using namespace std; set<string> myset; int main() { int n; scanf("%d", &n); for (int i = 0; i < n; i++) { string s1, s2, scnt; cin >> s1; int sz = s1.size(); for (int j = 0; j < sz; j++) { if (s1[j] == 'k') { scnt += 'k'; continue; } if (scnt.size() > 0) { if (s1[j] == 'h') { s2 += 'h'; scnt = ""; continue; } else { s2 += scnt; } scnt = ""; } if (s1[j] == 'u') s2 += 'o', s2 += 'o'; else s2 += s1[j]; } if (scnt != "") s2 += scnt; myset.insert(s2); } int sz = myset.size(); printf("%d", sz); } ```
#include <bits/stdc++.h> using namespace std; string conv(string s) { string res; for (int i = 0; i < s.size(); i++) { if (s[i] == 'u') res += "oo"; else if (s[i] == 'h') { while (res.size() && res.back() == 'k') res.pop_back(); res += s[i]; } else res += s[i]; } return res; } set<string> ss; int n; int main() { cin >> n; for (int i = 0; i < n; i++) { string s; cin >> s; ss.insert(conv(s)); } printf("%d\n", (int)ss.size()); }
### Prompt In Cpp, your task is to solve the following problem: There are some ambiguities when one writes Berland names with the letters of the Latin alphabet. For example, the Berland sound u can be written in the Latin alphabet as "u", and can be written as "oo". For this reason, two words "ulyana" and "oolyana" denote the same name. The second ambiguity is about the Berland sound h: one can use both "h" and "kh" to write it. For example, the words "mihail" and "mikhail" denote the same name. There are n users registered on the Polycarp's website. Each of them indicated a name represented by the Latin letters. How many distinct names are there among them, if two ambiguities described above are taken into account? Formally, we assume that two words denote the same name, if using the replacements "u" <image> "oo" and "h" <image> "kh", you can make the words equal. One can make replacements in both directions, in any of the two words an arbitrary number of times. A letter that resulted from the previous replacement can participate in the next replacements. For example, the following pairs of words denote the same name: * "koouper" and "kuooper". Making the replacements described above, you can make both words to be equal: "koouper" <image> "kuuper" and "kuooper" <image> "kuuper". * "khun" and "kkkhoon". With the replacements described above you can make both words to be equal: "khun" <image> "khoon" and "kkkhoon" <image> "kkhoon" <image> "khoon". For a given list of words, find the minimal number of groups where the words in each group denote the same name. Input The first line contains integer number n (2 ≀ n ≀ 400) β€” number of the words in the list. The following n lines contain words, one word per line. Each word consists of only lowercase Latin letters. The length of each word is between 1 and 20 letters inclusive. Output Print the minimal number of groups where the words in each group denote the same name. Examples Input 10 mihail oolyana kooooper hoon ulyana koouper mikhail khun kuooper kkkhoon Output 4 Input 9 hariton hkariton buoi kkkhariton boooi bui khariton boui boi Output 5 Input 2 alex alex Output 1 Note There are four groups of words in the first example. Words in each group denote same name: 1. "mihail", "mikhail" 2. "oolyana", "ulyana" 3. "kooooper", "koouper" 4. "hoon", "khun", "kkkhoon" There are five groups of words in the second example. Words in each group denote same name: 1. "hariton", "kkkhariton", "khariton" 2. "hkariton" 3. "buoi", "boooi", "boui" 4. "bui" 5. "boi" In the third example the words are equal, so they denote the same name. ### Response ```cpp #include <bits/stdc++.h> using namespace std; string conv(string s) { string res; for (int i = 0; i < s.size(); i++) { if (s[i] == 'u') res += "oo"; else if (s[i] == 'h') { while (res.size() && res.back() == 'k') res.pop_back(); res += s[i]; } else res += s[i]; } return res; } set<string> ss; int n; int main() { cin >> n; for (int i = 0; i < n; i++) { string s; cin >> s; ss.insert(conv(s)); } printf("%d\n", (int)ss.size()); } ```
#include <bits/stdc++.h> using namespace std; int main() { int n; scanf("%d", &n); string s[401]; unordered_map<string, int> umap; for (int i = 0; i < n; i++) { cin >> s[i]; } for (int i = 0; i < n; i++) { for (int j = 0; j < s[i].size(); j++) { if (s[i][j] == 'u') { s[i].replace(j, 1, "oo"); } } } for (int i = 0; i < n; i++) { int j = s[i].size() - 1; while (j >= 0) { if (s[i][j] == 'h') { if (j > 0) { if (s[i][j - 1] == 'k') { s[i].replace(j - 1, 2, "h"); } else j--; } else j--; } else j--; } } int count = 0; for (int i = 0; i < n; i++) { if (umap[s[i]] == 0) { umap[s[i]]++; count++; } } printf("%d\n", count); return 0; }
### Prompt In Cpp, your task is to solve the following problem: There are some ambiguities when one writes Berland names with the letters of the Latin alphabet. For example, the Berland sound u can be written in the Latin alphabet as "u", and can be written as "oo". For this reason, two words "ulyana" and "oolyana" denote the same name. The second ambiguity is about the Berland sound h: one can use both "h" and "kh" to write it. For example, the words "mihail" and "mikhail" denote the same name. There are n users registered on the Polycarp's website. Each of them indicated a name represented by the Latin letters. How many distinct names are there among them, if two ambiguities described above are taken into account? Formally, we assume that two words denote the same name, if using the replacements "u" <image> "oo" and "h" <image> "kh", you can make the words equal. One can make replacements in both directions, in any of the two words an arbitrary number of times. A letter that resulted from the previous replacement can participate in the next replacements. For example, the following pairs of words denote the same name: * "koouper" and "kuooper". Making the replacements described above, you can make both words to be equal: "koouper" <image> "kuuper" and "kuooper" <image> "kuuper". * "khun" and "kkkhoon". With the replacements described above you can make both words to be equal: "khun" <image> "khoon" and "kkkhoon" <image> "kkhoon" <image> "khoon". For a given list of words, find the minimal number of groups where the words in each group denote the same name. Input The first line contains integer number n (2 ≀ n ≀ 400) β€” number of the words in the list. The following n lines contain words, one word per line. Each word consists of only lowercase Latin letters. The length of each word is between 1 and 20 letters inclusive. Output Print the minimal number of groups where the words in each group denote the same name. Examples Input 10 mihail oolyana kooooper hoon ulyana koouper mikhail khun kuooper kkkhoon Output 4 Input 9 hariton hkariton buoi kkkhariton boooi bui khariton boui boi Output 5 Input 2 alex alex Output 1 Note There are four groups of words in the first example. Words in each group denote same name: 1. "mihail", "mikhail" 2. "oolyana", "ulyana" 3. "kooooper", "koouper" 4. "hoon", "khun", "kkkhoon" There are five groups of words in the second example. Words in each group denote same name: 1. "hariton", "kkkhariton", "khariton" 2. "hkariton" 3. "buoi", "boooi", "boui" 4. "bui" 5. "boi" In the third example the words are equal, so they denote the same name. ### Response ```cpp #include <bits/stdc++.h> using namespace std; int main() { int n; scanf("%d", &n); string s[401]; unordered_map<string, int> umap; for (int i = 0; i < n; i++) { cin >> s[i]; } for (int i = 0; i < n; i++) { for (int j = 0; j < s[i].size(); j++) { if (s[i][j] == 'u') { s[i].replace(j, 1, "oo"); } } } for (int i = 0; i < n; i++) { int j = s[i].size() - 1; while (j >= 0) { if (s[i][j] == 'h') { if (j > 0) { if (s[i][j - 1] == 'k') { s[i].replace(j - 1, 2, "h"); } else j--; } else j--; } else j--; } } int count = 0; for (int i = 0; i < n; i++) { if (umap[s[i]] == 0) { umap[s[i]]++; count++; } } printf("%d\n", count); return 0; } ```
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; string s[n + 1]; for (int j = 0; j < n; j++) { cin >> s[j]; for (int i = 0; i < (int)s[j].size(); i++) { if (s[j][i] == 'u') { s[j][i] = 'o'; string tmp = s[j]; s[j].erase(s[j].begin() + i, s[j].end()); tmp.erase(tmp.begin(), tmp.begin() + i); s[j] = s[j] + 'o' + tmp; } if (i + 1 != (int)s[j].size() && s[j][i] == 'k' && s[j][i + 1] == 'h') { s[j].erase(i, 1); i = -1; } } } sort(s, s + n); int ans = 0; for (int i = 0; i < n; i++) { int cnt = 0; for (int j = i + 1; j < n; j++) { if (s[i] != s[j]) break; cnt++; } i += cnt; ans++; } cout << ans << endl; }
### Prompt Develop a solution in cpp to the problem described below: There are some ambiguities when one writes Berland names with the letters of the Latin alphabet. For example, the Berland sound u can be written in the Latin alphabet as "u", and can be written as "oo". For this reason, two words "ulyana" and "oolyana" denote the same name. The second ambiguity is about the Berland sound h: one can use both "h" and "kh" to write it. For example, the words "mihail" and "mikhail" denote the same name. There are n users registered on the Polycarp's website. Each of them indicated a name represented by the Latin letters. How many distinct names are there among them, if two ambiguities described above are taken into account? Formally, we assume that two words denote the same name, if using the replacements "u" <image> "oo" and "h" <image> "kh", you can make the words equal. One can make replacements in both directions, in any of the two words an arbitrary number of times. A letter that resulted from the previous replacement can participate in the next replacements. For example, the following pairs of words denote the same name: * "koouper" and "kuooper". Making the replacements described above, you can make both words to be equal: "koouper" <image> "kuuper" and "kuooper" <image> "kuuper". * "khun" and "kkkhoon". With the replacements described above you can make both words to be equal: "khun" <image> "khoon" and "kkkhoon" <image> "kkhoon" <image> "khoon". For a given list of words, find the minimal number of groups where the words in each group denote the same name. Input The first line contains integer number n (2 ≀ n ≀ 400) β€” number of the words in the list. The following n lines contain words, one word per line. Each word consists of only lowercase Latin letters. The length of each word is between 1 and 20 letters inclusive. Output Print the minimal number of groups where the words in each group denote the same name. Examples Input 10 mihail oolyana kooooper hoon ulyana koouper mikhail khun kuooper kkkhoon Output 4 Input 9 hariton hkariton buoi kkkhariton boooi bui khariton boui boi Output 5 Input 2 alex alex Output 1 Note There are four groups of words in the first example. Words in each group denote same name: 1. "mihail", "mikhail" 2. "oolyana", "ulyana" 3. "kooooper", "koouper" 4. "hoon", "khun", "kkkhoon" There are five groups of words in the second example. Words in each group denote same name: 1. "hariton", "kkkhariton", "khariton" 2. "hkariton" 3. "buoi", "boooi", "boui" 4. "bui" 5. "boi" In the third example the words are equal, so they denote the same name. ### Response ```cpp #include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; string s[n + 1]; for (int j = 0; j < n; j++) { cin >> s[j]; for (int i = 0; i < (int)s[j].size(); i++) { if (s[j][i] == 'u') { s[j][i] = 'o'; string tmp = s[j]; s[j].erase(s[j].begin() + i, s[j].end()); tmp.erase(tmp.begin(), tmp.begin() + i); s[j] = s[j] + 'o' + tmp; } if (i + 1 != (int)s[j].size() && s[j][i] == 'k' && s[j][i + 1] == 'h') { s[j].erase(i, 1); i = -1; } } } sort(s, s + n); int ans = 0; for (int i = 0; i < n; i++) { int cnt = 0; for (int j = i + 1; j < n; j++) { if (s[i] != s[j]) break; cnt++; } i += cnt; ans++; } cout << ans << endl; } ```
#include <bits/stdc++.h> using namespace std; long long ans; int n, m, T; char a[1001], b[1001]; map<long long, bool> p; inline void init() { scanf("%s", a + 1); n = strlen(a + 1); m = 0; for (int i = 1; i <= n; i++) { while (m > 0 && b[m] == 'k' && a[i] == 'h') m--; if (a[i] == 'u') { b[++m] = 'o'; b[++m] = 'o'; } else { b[++m] = a[i]; } } ans = 0; for (int i = 1; i <= m; i++) ans = ans * 1000000007 + b[i]; p[ans] = 1; } int main() { scanf("%d", &T); for (int i = 1; i <= T; i++) init(); printf("%d\n", p.size()); return 0; }
### Prompt Please create a solution in Cpp to the following problem: There are some ambiguities when one writes Berland names with the letters of the Latin alphabet. For example, the Berland sound u can be written in the Latin alphabet as "u", and can be written as "oo". For this reason, two words "ulyana" and "oolyana" denote the same name. The second ambiguity is about the Berland sound h: one can use both "h" and "kh" to write it. For example, the words "mihail" and "mikhail" denote the same name. There are n users registered on the Polycarp's website. Each of them indicated a name represented by the Latin letters. How many distinct names are there among them, if two ambiguities described above are taken into account? Formally, we assume that two words denote the same name, if using the replacements "u" <image> "oo" and "h" <image> "kh", you can make the words equal. One can make replacements in both directions, in any of the two words an arbitrary number of times. A letter that resulted from the previous replacement can participate in the next replacements. For example, the following pairs of words denote the same name: * "koouper" and "kuooper". Making the replacements described above, you can make both words to be equal: "koouper" <image> "kuuper" and "kuooper" <image> "kuuper". * "khun" and "kkkhoon". With the replacements described above you can make both words to be equal: "khun" <image> "khoon" and "kkkhoon" <image> "kkhoon" <image> "khoon". For a given list of words, find the minimal number of groups where the words in each group denote the same name. Input The first line contains integer number n (2 ≀ n ≀ 400) β€” number of the words in the list. The following n lines contain words, one word per line. Each word consists of only lowercase Latin letters. The length of each word is between 1 and 20 letters inclusive. Output Print the minimal number of groups where the words in each group denote the same name. Examples Input 10 mihail oolyana kooooper hoon ulyana koouper mikhail khun kuooper kkkhoon Output 4 Input 9 hariton hkariton buoi kkkhariton boooi bui khariton boui boi Output 5 Input 2 alex alex Output 1 Note There are four groups of words in the first example. Words in each group denote same name: 1. "mihail", "mikhail" 2. "oolyana", "ulyana" 3. "kooooper", "koouper" 4. "hoon", "khun", "kkkhoon" There are five groups of words in the second example. Words in each group denote same name: 1. "hariton", "kkkhariton", "khariton" 2. "hkariton" 3. "buoi", "boooi", "boui" 4. "bui" 5. "boi" In the third example the words are equal, so they denote the same name. ### Response ```cpp #include <bits/stdc++.h> using namespace std; long long ans; int n, m, T; char a[1001], b[1001]; map<long long, bool> p; inline void init() { scanf("%s", a + 1); n = strlen(a + 1); m = 0; for (int i = 1; i <= n; i++) { while (m > 0 && b[m] == 'k' && a[i] == 'h') m--; if (a[i] == 'u') { b[++m] = 'o'; b[++m] = 'o'; } else { b[++m] = a[i]; } } ans = 0; for (int i = 1; i <= m; i++) ans = ans * 1000000007 + b[i]; p[ans] = 1; } int main() { scanf("%d", &T); for (int i = 1; i <= T; i++) init(); printf("%d\n", p.size()); return 0; } ```
#include <bits/stdc++.h> using namespace std; bool ifNextH(string& a, int i) { while (i < a.size() && a[i] == 'k') i++; if (i == a.size() || a[i] != 'h') return false; return true; } string normalize(string& a) { int i = 0; string result = ""; while (i < a.size()) { if (a[i] != 'k' && a[i] != 'u') { result += a[i]; i++; } else if (a[i] == 'u') { result += "oo"; i++; } else if (ifNextH(a, i)) { while (a[i] != 'h') i++; } else { result += "k"; i++; } } return result; } int main() { int nrOfNames; cin >> nrOfNames; unordered_set<string> names; for (int i = 0; i < nrOfNames; i++) { string name; cin >> name; string normalized = normalize(name); if (names.find(normalized) == names.end()) { names.insert(normalized); } } cout << names.size() << endl; return 0; }
### Prompt Please provide a Cpp coded solution to the problem described below: There are some ambiguities when one writes Berland names with the letters of the Latin alphabet. For example, the Berland sound u can be written in the Latin alphabet as "u", and can be written as "oo". For this reason, two words "ulyana" and "oolyana" denote the same name. The second ambiguity is about the Berland sound h: one can use both "h" and "kh" to write it. For example, the words "mihail" and "mikhail" denote the same name. There are n users registered on the Polycarp's website. Each of them indicated a name represented by the Latin letters. How many distinct names are there among them, if two ambiguities described above are taken into account? Formally, we assume that two words denote the same name, if using the replacements "u" <image> "oo" and "h" <image> "kh", you can make the words equal. One can make replacements in both directions, in any of the two words an arbitrary number of times. A letter that resulted from the previous replacement can participate in the next replacements. For example, the following pairs of words denote the same name: * "koouper" and "kuooper". Making the replacements described above, you can make both words to be equal: "koouper" <image> "kuuper" and "kuooper" <image> "kuuper". * "khun" and "kkkhoon". With the replacements described above you can make both words to be equal: "khun" <image> "khoon" and "kkkhoon" <image> "kkhoon" <image> "khoon". For a given list of words, find the minimal number of groups where the words in each group denote the same name. Input The first line contains integer number n (2 ≀ n ≀ 400) β€” number of the words in the list. The following n lines contain words, one word per line. Each word consists of only lowercase Latin letters. The length of each word is between 1 and 20 letters inclusive. Output Print the minimal number of groups where the words in each group denote the same name. Examples Input 10 mihail oolyana kooooper hoon ulyana koouper mikhail khun kuooper kkkhoon Output 4 Input 9 hariton hkariton buoi kkkhariton boooi bui khariton boui boi Output 5 Input 2 alex alex Output 1 Note There are four groups of words in the first example. Words in each group denote same name: 1. "mihail", "mikhail" 2. "oolyana", "ulyana" 3. "kooooper", "koouper" 4. "hoon", "khun", "kkkhoon" There are five groups of words in the second example. Words in each group denote same name: 1. "hariton", "kkkhariton", "khariton" 2. "hkariton" 3. "buoi", "boooi", "boui" 4. "bui" 5. "boi" In the third example the words are equal, so they denote the same name. ### Response ```cpp #include <bits/stdc++.h> using namespace std; bool ifNextH(string& a, int i) { while (i < a.size() && a[i] == 'k') i++; if (i == a.size() || a[i] != 'h') return false; return true; } string normalize(string& a) { int i = 0; string result = ""; while (i < a.size()) { if (a[i] != 'k' && a[i] != 'u') { result += a[i]; i++; } else if (a[i] == 'u') { result += "oo"; i++; } else if (ifNextH(a, i)) { while (a[i] != 'h') i++; } else { result += "k"; i++; } } return result; } int main() { int nrOfNames; cin >> nrOfNames; unordered_set<string> names; for (int i = 0; i < nrOfNames; i++) { string name; cin >> name; string normalized = normalize(name); if (names.find(normalized) == names.end()) { names.insert(normalized); } } cout << names.size() << endl; return 0; } ```
#include <bits/stdc++.h> using namespace std; int main() { int v1, v2, v3, vm, vc; cin >> v1 >> v2 >> v3 >> vm; vc = v3; if (2 * vm < v3) { cout << "-1"; return 0; } if (vc < vm) vc = vm; if (v3 * 2 < vc) { cout << "-1"; return 0; } if (vm * 2 >= v1 * 2 || vm * 2 >= v2 * 2) { cout << "-1"; return 0; } cout << v1 * 2 << '\n' << v2 * 2 << '\n' << vc; return 0; }
### Prompt Your task is to create a Cpp solution to the following problem: A family consisting of father bear, mother bear and son bear owns three cars. Father bear can climb into the largest car and he likes it. Also, mother bear can climb into the middle car and she likes it. Moreover, son bear can climb into the smallest car and he likes it. It's known that the largest car is strictly larger than the middle car, and the middle car is strictly larger than the smallest car. Masha came to test these cars. She could climb into all cars, but she liked only the smallest car. It's known that a character with size a can climb into some car with size b if and only if a ≀ b, he or she likes it if and only if he can climb into this car and 2a β‰₯ b. You are given sizes of bears and Masha. Find out some possible integer non-negative sizes of cars. Input You are given four integers V1, V2, V3, Vm(1 ≀ Vi ≀ 100) β€” sizes of father bear, mother bear, son bear and Masha, respectively. It's guaranteed that V1 > V2 > V3. Output Output three integers β€” sizes of father bear's car, mother bear's car and son bear's car, respectively. If there are multiple possible solutions, print any. If there is no solution, print "-1" (without quotes). Examples Input 50 30 10 10 Output 50 30 10 Input 100 50 10 21 Output -1 Note In first test case all conditions for cars' sizes are satisfied. In second test case there is no answer, because Masha should be able to climb into smallest car (so size of smallest car in not less than 21), but son bear should like it, so maximum possible size of it is 20. ### Response ```cpp #include <bits/stdc++.h> using namespace std; int main() { int v1, v2, v3, vm, vc; cin >> v1 >> v2 >> v3 >> vm; vc = v3; if (2 * vm < v3) { cout << "-1"; return 0; } if (vc < vm) vc = vm; if (v3 * 2 < vc) { cout << "-1"; return 0; } if (vm * 2 >= v1 * 2 || vm * 2 >= v2 * 2) { cout << "-1"; return 0; } cout << v1 * 2 << '\n' << v2 * 2 << '\n' << vc; return 0; } ```
#include <bits/stdc++.h> using namespace std; int main() { int v1, v2, v3, vm, flag = 0; cin >> v1 >> v2 >> v3 >> vm; int smallh = v3 * 2, medh, largeh; if (vm > smallh) flag = 1; if (2 * vm < v3) flag = 1; if (vm >= v2 || vm >= v1) flag = 1; if (vm > v3) smallh = vm; else smallh = v3; if (vm * 2 >= v2) medh = vm * 2 + 1; else medh = v2; if (medh == smallh) { if (medh + 1 <= 2 * v2) medh++; else flag = 1; } if (vm * 2 >= v1) largeh = vm * 2 + 1; else largeh = v1; if (medh == largeh) { if (largeh + 1 <= 2 * v1) largeh++; else flag = 1; } if (flag == 0) { cout << largeh << endl << medh << endl << smallh; } else { cout << -1; } }
### Prompt In cpp, your task is to solve the following problem: A family consisting of father bear, mother bear and son bear owns three cars. Father bear can climb into the largest car and he likes it. Also, mother bear can climb into the middle car and she likes it. Moreover, son bear can climb into the smallest car and he likes it. It's known that the largest car is strictly larger than the middle car, and the middle car is strictly larger than the smallest car. Masha came to test these cars. She could climb into all cars, but she liked only the smallest car. It's known that a character with size a can climb into some car with size b if and only if a ≀ b, he or she likes it if and only if he can climb into this car and 2a β‰₯ b. You are given sizes of bears and Masha. Find out some possible integer non-negative sizes of cars. Input You are given four integers V1, V2, V3, Vm(1 ≀ Vi ≀ 100) β€” sizes of father bear, mother bear, son bear and Masha, respectively. It's guaranteed that V1 > V2 > V3. Output Output three integers β€” sizes of father bear's car, mother bear's car and son bear's car, respectively. If there are multiple possible solutions, print any. If there is no solution, print "-1" (without quotes). Examples Input 50 30 10 10 Output 50 30 10 Input 100 50 10 21 Output -1 Note In first test case all conditions for cars' sizes are satisfied. In second test case there is no answer, because Masha should be able to climb into smallest car (so size of smallest car in not less than 21), but son bear should like it, so maximum possible size of it is 20. ### Response ```cpp #include <bits/stdc++.h> using namespace std; int main() { int v1, v2, v3, vm, flag = 0; cin >> v1 >> v2 >> v3 >> vm; int smallh = v3 * 2, medh, largeh; if (vm > smallh) flag = 1; if (2 * vm < v3) flag = 1; if (vm >= v2 || vm >= v1) flag = 1; if (vm > v3) smallh = vm; else smallh = v3; if (vm * 2 >= v2) medh = vm * 2 + 1; else medh = v2; if (medh == smallh) { if (medh + 1 <= 2 * v2) medh++; else flag = 1; } if (vm * 2 >= v1) largeh = vm * 2 + 1; else largeh = v1; if (medh == largeh) { if (largeh + 1 <= 2 * v1) largeh++; else flag = 1; } if (flag == 0) { cout << largeh << endl << medh << endl << smallh; } else { cout << -1; } } ```
#include <bits/stdc++.h> using namespace std; int main() { int a, b, c, d; while (cin >> a >> b >> c >> d) { for (int i = 1; i <= 200; i++) { for (int j = 1; j < i; j++) { for (int k = 1; k < i; k++) { if (a <= i && 2 * a >= i && b <= j && 2 * b >= j && c <= k && 2 * c >= k && d <= k && 2 * d >= k && 2 * d < j) { printf("%d\n%d\n%d\n", i, j, k); return 0; } } } } puts("-1"); } return 0; }
### Prompt Create a solution in CPP for the following problem: A family consisting of father bear, mother bear and son bear owns three cars. Father bear can climb into the largest car and he likes it. Also, mother bear can climb into the middle car and she likes it. Moreover, son bear can climb into the smallest car and he likes it. It's known that the largest car is strictly larger than the middle car, and the middle car is strictly larger than the smallest car. Masha came to test these cars. She could climb into all cars, but she liked only the smallest car. It's known that a character with size a can climb into some car with size b if and only if a ≀ b, he or she likes it if and only if he can climb into this car and 2a β‰₯ b. You are given sizes of bears and Masha. Find out some possible integer non-negative sizes of cars. Input You are given four integers V1, V2, V3, Vm(1 ≀ Vi ≀ 100) β€” sizes of father bear, mother bear, son bear and Masha, respectively. It's guaranteed that V1 > V2 > V3. Output Output three integers β€” sizes of father bear's car, mother bear's car and son bear's car, respectively. If there are multiple possible solutions, print any. If there is no solution, print "-1" (without quotes). Examples Input 50 30 10 10 Output 50 30 10 Input 100 50 10 21 Output -1 Note In first test case all conditions for cars' sizes are satisfied. In second test case there is no answer, because Masha should be able to climb into smallest car (so size of smallest car in not less than 21), but son bear should like it, so maximum possible size of it is 20. ### Response ```cpp #include <bits/stdc++.h> using namespace std; int main() { int a, b, c, d; while (cin >> a >> b >> c >> d) { for (int i = 1; i <= 200; i++) { for (int j = 1; j < i; j++) { for (int k = 1; k < i; k++) { if (a <= i && 2 * a >= i && b <= j && 2 * b >= j && c <= k && 2 * c >= k && d <= k && 2 * d >= k && 2 * d < j) { printf("%d\n%d\n%d\n", i, j, k); return 0; } } } } puts("-1"); } return 0; } ```
#include <bits/stdc++.h> using namespace std; int main() { int a, b, c, d; while (scanf("%d%d%d%d", &a, &b, &c, &d) != EOF) { if (d > 2 * c || d >= b || c > 2 * d) printf("-1\n"); else { printf("%d\n%d\n%d\n", 2 * a, 2 * b, max(c, d)); } } return 0; }
### Prompt Your challenge is to write a cpp solution to the following problem: A family consisting of father bear, mother bear and son bear owns three cars. Father bear can climb into the largest car and he likes it. Also, mother bear can climb into the middle car and she likes it. Moreover, son bear can climb into the smallest car and he likes it. It's known that the largest car is strictly larger than the middle car, and the middle car is strictly larger than the smallest car. Masha came to test these cars. She could climb into all cars, but she liked only the smallest car. It's known that a character with size a can climb into some car with size b if and only if a ≀ b, he or she likes it if and only if he can climb into this car and 2a β‰₯ b. You are given sizes of bears and Masha. Find out some possible integer non-negative sizes of cars. Input You are given four integers V1, V2, V3, Vm(1 ≀ Vi ≀ 100) β€” sizes of father bear, mother bear, son bear and Masha, respectively. It's guaranteed that V1 > V2 > V3. Output Output three integers β€” sizes of father bear's car, mother bear's car and son bear's car, respectively. If there are multiple possible solutions, print any. If there is no solution, print "-1" (without quotes). Examples Input 50 30 10 10 Output 50 30 10 Input 100 50 10 21 Output -1 Note In first test case all conditions for cars' sizes are satisfied. In second test case there is no answer, because Masha should be able to climb into smallest car (so size of smallest car in not less than 21), but son bear should like it, so maximum possible size of it is 20. ### Response ```cpp #include <bits/stdc++.h> using namespace std; int main() { int a, b, c, d; while (scanf("%d%d%d%d", &a, &b, &c, &d) != EOF) { if (d > 2 * c || d >= b || c > 2 * d) printf("-1\n"); else { printf("%d\n%d\n%d\n", 2 * a, 2 * b, max(c, d)); } } return 0; } ```
#include <bits/stdc++.h> using namespace std; bool z[26]; bool z2[26]; int main() { cin.sync_with_stdio(false); cin.tie(0); int v1, v2, v3, v4; cin >> v1 >> v2 >> v3 >> v4; int x1 = v1 * 2; int x2 = v2 * 2; if (x2 <= v4 * 2) { cout << -1; return 0; } for (int x3 = 1; x3 <= 200; x3++) { bool z = true; if (x3 >= x2) z = false; if (x3 < v3) z = false; if (x3 < v4) z = false; if (x3 > 2 * v3) z = false; if (x3 > 2 * v4) z = false; if (z) { cout << x1 << " " << x2 << " " << x3; return 0; } } cout << -1; return 0; }
### Prompt Create a solution in cpp for the following problem: A family consisting of father bear, mother bear and son bear owns three cars. Father bear can climb into the largest car and he likes it. Also, mother bear can climb into the middle car and she likes it. Moreover, son bear can climb into the smallest car and he likes it. It's known that the largest car is strictly larger than the middle car, and the middle car is strictly larger than the smallest car. Masha came to test these cars. She could climb into all cars, but she liked only the smallest car. It's known that a character with size a can climb into some car with size b if and only if a ≀ b, he or she likes it if and only if he can climb into this car and 2a β‰₯ b. You are given sizes of bears and Masha. Find out some possible integer non-negative sizes of cars. Input You are given four integers V1, V2, V3, Vm(1 ≀ Vi ≀ 100) β€” sizes of father bear, mother bear, son bear and Masha, respectively. It's guaranteed that V1 > V2 > V3. Output Output three integers β€” sizes of father bear's car, mother bear's car and son bear's car, respectively. If there are multiple possible solutions, print any. If there is no solution, print "-1" (without quotes). Examples Input 50 30 10 10 Output 50 30 10 Input 100 50 10 21 Output -1 Note In first test case all conditions for cars' sizes are satisfied. In second test case there is no answer, because Masha should be able to climb into smallest car (so size of smallest car in not less than 21), but son bear should like it, so maximum possible size of it is 20. ### Response ```cpp #include <bits/stdc++.h> using namespace std; bool z[26]; bool z2[26]; int main() { cin.sync_with_stdio(false); cin.tie(0); int v1, v2, v3, v4; cin >> v1 >> v2 >> v3 >> v4; int x1 = v1 * 2; int x2 = v2 * 2; if (x2 <= v4 * 2) { cout << -1; return 0; } for (int x3 = 1; x3 <= 200; x3++) { bool z = true; if (x3 >= x2) z = false; if (x3 < v3) z = false; if (x3 < v4) z = false; if (x3 > 2 * v3) z = false; if (x3 > 2 * v4) z = false; if (z) { cout << x1 << " " << x2 << " " << x3; return 0; } } cout << -1; return 0; } ```
#include <bits/stdc++.h> using namespace std; int main() { int v1, v2, v3, vm, v; cin >> v1 >> v2 >> v3 >> vm; v1 *= 2; v2 *= 2; v = v3 * 2; if (v > 2 * vm) { v = 2 * vm; } if (vm <= v && v3 <= v && 2 * vm < v2) { cout << v1 << endl; cout << v2 << endl; cout << v << endl; } else { cout << "-1" << endl; } }
### Prompt Please formulate a Cpp solution to the following problem: A family consisting of father bear, mother bear and son bear owns three cars. Father bear can climb into the largest car and he likes it. Also, mother bear can climb into the middle car and she likes it. Moreover, son bear can climb into the smallest car and he likes it. It's known that the largest car is strictly larger than the middle car, and the middle car is strictly larger than the smallest car. Masha came to test these cars. She could climb into all cars, but she liked only the smallest car. It's known that a character with size a can climb into some car with size b if and only if a ≀ b, he or she likes it if and only if he can climb into this car and 2a β‰₯ b. You are given sizes of bears and Masha. Find out some possible integer non-negative sizes of cars. Input You are given four integers V1, V2, V3, Vm(1 ≀ Vi ≀ 100) β€” sizes of father bear, mother bear, son bear and Masha, respectively. It's guaranteed that V1 > V2 > V3. Output Output three integers β€” sizes of father bear's car, mother bear's car and son bear's car, respectively. If there are multiple possible solutions, print any. If there is no solution, print "-1" (without quotes). Examples Input 50 30 10 10 Output 50 30 10 Input 100 50 10 21 Output -1 Note In first test case all conditions for cars' sizes are satisfied. In second test case there is no answer, because Masha should be able to climb into smallest car (so size of smallest car in not less than 21), but son bear should like it, so maximum possible size of it is 20. ### Response ```cpp #include <bits/stdc++.h> using namespace std; int main() { int v1, v2, v3, vm, v; cin >> v1 >> v2 >> v3 >> vm; v1 *= 2; v2 *= 2; v = v3 * 2; if (v > 2 * vm) { v = 2 * vm; } if (vm <= v && v3 <= v && 2 * vm < v2) { cout << v1 << endl; cout << v2 << endl; cout << v << endl; } else { cout << "-1" << endl; } } ```
#include <bits/stdc++.h> using namespace std; int n, m, nm, p, t, ans; int main() { int a, b, c, d; cin >> a >> b >> c >> d; if (max(c, d) > min(c, d) * 2) { cout << "-1"; return 0; } int aa, bb, cc; cc = max(c, d); bb = max(cc + 1, b); bb = max(d * 2 + 1, bb); aa = max(bb + 1, a); if (bb > b * 2 || aa > a * 2) { cout << "-1"; return 0; } cout << aa << " " << bb << " " << cc; return 0; }
### Prompt Please formulate a CPP solution to the following problem: A family consisting of father bear, mother bear and son bear owns three cars. Father bear can climb into the largest car and he likes it. Also, mother bear can climb into the middle car and she likes it. Moreover, son bear can climb into the smallest car and he likes it. It's known that the largest car is strictly larger than the middle car, and the middle car is strictly larger than the smallest car. Masha came to test these cars. She could climb into all cars, but she liked only the smallest car. It's known that a character with size a can climb into some car with size b if and only if a ≀ b, he or she likes it if and only if he can climb into this car and 2a β‰₯ b. You are given sizes of bears and Masha. Find out some possible integer non-negative sizes of cars. Input You are given four integers V1, V2, V3, Vm(1 ≀ Vi ≀ 100) β€” sizes of father bear, mother bear, son bear and Masha, respectively. It's guaranteed that V1 > V2 > V3. Output Output three integers β€” sizes of father bear's car, mother bear's car and son bear's car, respectively. If there are multiple possible solutions, print any. If there is no solution, print "-1" (without quotes). Examples Input 50 30 10 10 Output 50 30 10 Input 100 50 10 21 Output -1 Note In first test case all conditions for cars' sizes are satisfied. In second test case there is no answer, because Masha should be able to climb into smallest car (so size of smallest car in not less than 21), but son bear should like it, so maximum possible size of it is 20. ### Response ```cpp #include <bits/stdc++.h> using namespace std; int n, m, nm, p, t, ans; int main() { int a, b, c, d; cin >> a >> b >> c >> d; if (max(c, d) > min(c, d) * 2) { cout << "-1"; return 0; } int aa, bb, cc; cc = max(c, d); bb = max(cc + 1, b); bb = max(d * 2 + 1, bb); aa = max(bb + 1, a); if (bb > b * 2 || aa > a * 2) { cout << "-1"; return 0; } cout << aa << " " << bb << " " << cc; return 0; } ```
#include <bits/stdc++.h> using namespace std; int main() { int a, b, c, d; cin >> a >> b >> c >> d; if (d > 2 * c || d >= b || d >= a || 2 * d < c) { cout << "-1"; return 0; } cout << max(2 * a, 2 * d + 2) << endl; cout << max(2 * b, 2 * d + 1) << endl; cout << max(c, d) << endl; return 0; }
### Prompt Please provide a CPP coded solution to the problem described below: A family consisting of father bear, mother bear and son bear owns three cars. Father bear can climb into the largest car and he likes it. Also, mother bear can climb into the middle car and she likes it. Moreover, son bear can climb into the smallest car and he likes it. It's known that the largest car is strictly larger than the middle car, and the middle car is strictly larger than the smallest car. Masha came to test these cars. She could climb into all cars, but she liked only the smallest car. It's known that a character with size a can climb into some car with size b if and only if a ≀ b, he or she likes it if and only if he can climb into this car and 2a β‰₯ b. You are given sizes of bears and Masha. Find out some possible integer non-negative sizes of cars. Input You are given four integers V1, V2, V3, Vm(1 ≀ Vi ≀ 100) β€” sizes of father bear, mother bear, son bear and Masha, respectively. It's guaranteed that V1 > V2 > V3. Output Output three integers β€” sizes of father bear's car, mother bear's car and son bear's car, respectively. If there are multiple possible solutions, print any. If there is no solution, print "-1" (without quotes). Examples Input 50 30 10 10 Output 50 30 10 Input 100 50 10 21 Output -1 Note In first test case all conditions for cars' sizes are satisfied. In second test case there is no answer, because Masha should be able to climb into smallest car (so size of smallest car in not less than 21), but son bear should like it, so maximum possible size of it is 20. ### Response ```cpp #include <bits/stdc++.h> using namespace std; int main() { int a, b, c, d; cin >> a >> b >> c >> d; if (d > 2 * c || d >= b || d >= a || 2 * d < c) { cout << "-1"; return 0; } cout << max(2 * a, 2 * d + 2) << endl; cout << max(2 * b, 2 * d + 1) << endl; cout << max(c, d) << endl; return 0; } ```
#include <bits/stdc++.h> using namespace std; const int MaxN = 1e6 + 1; bool ok = 0, good; char w; int ans = 0; int main() { int a, b, c, d; cin >> a >> b >> c >> d; for (int i = a; i <= a * 2; i++) if (d * 2 < i) for (int j = b; j <= b * 2; j++) if (d * 2 < j) for (int k = c; k <= c * 2; k++) if (d <= k && d * 2 >= k && i > j && j > k) { cout << i << endl; cout << j << endl; cout << k << endl; return 0; } cout << -1 << endl; }
### Prompt Please formulate a CPP solution to the following problem: A family consisting of father bear, mother bear and son bear owns three cars. Father bear can climb into the largest car and he likes it. Also, mother bear can climb into the middle car and she likes it. Moreover, son bear can climb into the smallest car and he likes it. It's known that the largest car is strictly larger than the middle car, and the middle car is strictly larger than the smallest car. Masha came to test these cars. She could climb into all cars, but she liked only the smallest car. It's known that a character with size a can climb into some car with size b if and only if a ≀ b, he or she likes it if and only if he can climb into this car and 2a β‰₯ b. You are given sizes of bears and Masha. Find out some possible integer non-negative sizes of cars. Input You are given four integers V1, V2, V3, Vm(1 ≀ Vi ≀ 100) β€” sizes of father bear, mother bear, son bear and Masha, respectively. It's guaranteed that V1 > V2 > V3. Output Output three integers β€” sizes of father bear's car, mother bear's car and son bear's car, respectively. If there are multiple possible solutions, print any. If there is no solution, print "-1" (without quotes). Examples Input 50 30 10 10 Output 50 30 10 Input 100 50 10 21 Output -1 Note In first test case all conditions for cars' sizes are satisfied. In second test case there is no answer, because Masha should be able to climb into smallest car (so size of smallest car in not less than 21), but son bear should like it, so maximum possible size of it is 20. ### Response ```cpp #include <bits/stdc++.h> using namespace std; const int MaxN = 1e6 + 1; bool ok = 0, good; char w; int ans = 0; int main() { int a, b, c, d; cin >> a >> b >> c >> d; for (int i = a; i <= a * 2; i++) if (d * 2 < i) for (int j = b; j <= b * 2; j++) if (d * 2 < j) for (int k = c; k <= c * 2; k++) if (d <= k && d * 2 >= k && i > j && j > k) { cout << i << endl; cout << j << endl; cout << k << endl; return 0; } cout << -1 << endl; } ```
#include <bits/stdc++.h> const int INF = 1e9 + 7; const int MAXN = 3e5 + 10; using namespace std; int main() { int a, b, c, d; cin >> a >> b >> c >> d; for (int i = a; i <= 2 * a; i++) { for (int j = b; j <= 2 * b; j++) { for (int k = c; k <= 2 * c; k++) { if (i > j && j > k && d <= i && d <= j && d <= k) { if (k <= d + d && j > d + d && i > d + d) { cout << i << '\n' << j << '\n' << k; return 0; } } } } } cout << -1; return 0; }
### Prompt Please formulate a Cpp solution to the following problem: A family consisting of father bear, mother bear and son bear owns three cars. Father bear can climb into the largest car and he likes it. Also, mother bear can climb into the middle car and she likes it. Moreover, son bear can climb into the smallest car and he likes it. It's known that the largest car is strictly larger than the middle car, and the middle car is strictly larger than the smallest car. Masha came to test these cars. She could climb into all cars, but she liked only the smallest car. It's known that a character with size a can climb into some car with size b if and only if a ≀ b, he or she likes it if and only if he can climb into this car and 2a β‰₯ b. You are given sizes of bears and Masha. Find out some possible integer non-negative sizes of cars. Input You are given four integers V1, V2, V3, Vm(1 ≀ Vi ≀ 100) β€” sizes of father bear, mother bear, son bear and Masha, respectively. It's guaranteed that V1 > V2 > V3. Output Output three integers β€” sizes of father bear's car, mother bear's car and son bear's car, respectively. If there are multiple possible solutions, print any. If there is no solution, print "-1" (without quotes). Examples Input 50 30 10 10 Output 50 30 10 Input 100 50 10 21 Output -1 Note In first test case all conditions for cars' sizes are satisfied. In second test case there is no answer, because Masha should be able to climb into smallest car (so size of smallest car in not less than 21), but son bear should like it, so maximum possible size of it is 20. ### Response ```cpp #include <bits/stdc++.h> const int INF = 1e9 + 7; const int MAXN = 3e5 + 10; using namespace std; int main() { int a, b, c, d; cin >> a >> b >> c >> d; for (int i = a; i <= 2 * a; i++) { for (int j = b; j <= 2 * b; j++) { for (int k = c; k <= 2 * c; k++) { if (i > j && j > k && d <= i && d <= j && d <= k) { if (k <= d + d && j > d + d && i > d + d) { cout << i << '\n' << j << '\n' << k; return 0; } } } } } cout << -1; return 0; } ```
#include <bits/stdc++.h> using namespace std; int main() { int v1, v2, v3, v; cin >> v1 >> v2 >> v3 >> v; for (int i = 250; i >= 1; --i) for (int j = i - 1; j >= 1; --j) for (int k = j - 1; k >= 1; --k) if (v1 <= i && 2 * v1 >= i && v2 <= j && 2 * v2 >= j && v3 <= k && 2 * v3 >= k && v <= k && 2 * v >= k && 2 * v < j && 2 * v < i) return cout << i << " " << j << " " << k << endl, 0; cout << -1 << endl; }
### Prompt Please create a solution in cpp to the following problem: A family consisting of father bear, mother bear and son bear owns three cars. Father bear can climb into the largest car and he likes it. Also, mother bear can climb into the middle car and she likes it. Moreover, son bear can climb into the smallest car and he likes it. It's known that the largest car is strictly larger than the middle car, and the middle car is strictly larger than the smallest car. Masha came to test these cars. She could climb into all cars, but she liked only the smallest car. It's known that a character with size a can climb into some car with size b if and only if a ≀ b, he or she likes it if and only if he can climb into this car and 2a β‰₯ b. You are given sizes of bears and Masha. Find out some possible integer non-negative sizes of cars. Input You are given four integers V1, V2, V3, Vm(1 ≀ Vi ≀ 100) β€” sizes of father bear, mother bear, son bear and Masha, respectively. It's guaranteed that V1 > V2 > V3. Output Output three integers β€” sizes of father bear's car, mother bear's car and son bear's car, respectively. If there are multiple possible solutions, print any. If there is no solution, print "-1" (without quotes). Examples Input 50 30 10 10 Output 50 30 10 Input 100 50 10 21 Output -1 Note In first test case all conditions for cars' sizes are satisfied. In second test case there is no answer, because Masha should be able to climb into smallest car (so size of smallest car in not less than 21), but son bear should like it, so maximum possible size of it is 20. ### Response ```cpp #include <bits/stdc++.h> using namespace std; int main() { int v1, v2, v3, v; cin >> v1 >> v2 >> v3 >> v; for (int i = 250; i >= 1; --i) for (int j = i - 1; j >= 1; --j) for (int k = j - 1; k >= 1; --k) if (v1 <= i && 2 * v1 >= i && v2 <= j && 2 * v2 >= j && v3 <= k && 2 * v3 >= k && v <= k && 2 * v >= k && 2 * v < j && 2 * v < i) return cout << i << " " << j << " " << k << endl, 0; cout << -1 << endl; } ```
#include <bits/stdc++.h> using namespace std; char s[10][10]; int main() { std::ios_base::sync_with_stdio(false); int mb, tb, cb, m; cin >> tb >> mb >> cb >> m; if (m > 2 * cb || m >= mb || 2 * m < cb) cout << "-1"; else { if (2 * m >= mb && 2 * m + 1 >= tb) { if (mb * 2 >= 2 * m + 1) cout << 2 * m + 2 << "\n"; } else cout << tb << "\n"; if (2 * m >= mb) cout << 2 * m + 1 << "\n"; else cout << mb << "\n"; if (2 * cb > 2 * m) cout << cb; else cout << m; } return 0; }
### Prompt Please create a solution in cpp to the following problem: A family consisting of father bear, mother bear and son bear owns three cars. Father bear can climb into the largest car and he likes it. Also, mother bear can climb into the middle car and she likes it. Moreover, son bear can climb into the smallest car and he likes it. It's known that the largest car is strictly larger than the middle car, and the middle car is strictly larger than the smallest car. Masha came to test these cars. She could climb into all cars, but she liked only the smallest car. It's known that a character with size a can climb into some car with size b if and only if a ≀ b, he or she likes it if and only if he can climb into this car and 2a β‰₯ b. You are given sizes of bears and Masha. Find out some possible integer non-negative sizes of cars. Input You are given four integers V1, V2, V3, Vm(1 ≀ Vi ≀ 100) β€” sizes of father bear, mother bear, son bear and Masha, respectively. It's guaranteed that V1 > V2 > V3. Output Output three integers β€” sizes of father bear's car, mother bear's car and son bear's car, respectively. If there are multiple possible solutions, print any. If there is no solution, print "-1" (without quotes). Examples Input 50 30 10 10 Output 50 30 10 Input 100 50 10 21 Output -1 Note In first test case all conditions for cars' sizes are satisfied. In second test case there is no answer, because Masha should be able to climb into smallest car (so size of smallest car in not less than 21), but son bear should like it, so maximum possible size of it is 20. ### Response ```cpp #include <bits/stdc++.h> using namespace std; char s[10][10]; int main() { std::ios_base::sync_with_stdio(false); int mb, tb, cb, m; cin >> tb >> mb >> cb >> m; if (m > 2 * cb || m >= mb || 2 * m < cb) cout << "-1"; else { if (2 * m >= mb && 2 * m + 1 >= tb) { if (mb * 2 >= 2 * m + 1) cout << 2 * m + 2 << "\n"; } else cout << tb << "\n"; if (2 * m >= mb) cout << 2 * m + 1 << "\n"; else cout << mb << "\n"; if (2 * cb > 2 * m) cout << cb; else cout << m; } return 0; } ```
#include <bits/stdc++.h> int main() { int v1, v2, v3, vm; scanf("%d%d%d%d", &v1, &v2, &v3, &vm); int c1 = v1, c3 = (v3 > vm) ? v3 : vm, c2 = c3 * 2 + 1; if (c3 > 2 * vm) printf("-1\n"); else if (c3 > 2 * v3) printf("-1\n"); else if (c2 > 2 * v2) printf("-1\n"); else { if (c2 < v2) c2 = v2; if (c2 >= c1) c1 = c2 + 1; if (c1 > 2 * v1) printf("-1\n"); else printf("%d\n%d\n%d\n", c1, c2, c3); } }
### Prompt In Cpp, your task is to solve the following problem: A family consisting of father bear, mother bear and son bear owns three cars. Father bear can climb into the largest car and he likes it. Also, mother bear can climb into the middle car and she likes it. Moreover, son bear can climb into the smallest car and he likes it. It's known that the largest car is strictly larger than the middle car, and the middle car is strictly larger than the smallest car. Masha came to test these cars. She could climb into all cars, but she liked only the smallest car. It's known that a character with size a can climb into some car with size b if and only if a ≀ b, he or she likes it if and only if he can climb into this car and 2a β‰₯ b. You are given sizes of bears and Masha. Find out some possible integer non-negative sizes of cars. Input You are given four integers V1, V2, V3, Vm(1 ≀ Vi ≀ 100) β€” sizes of father bear, mother bear, son bear and Masha, respectively. It's guaranteed that V1 > V2 > V3. Output Output three integers β€” sizes of father bear's car, mother bear's car and son bear's car, respectively. If there are multiple possible solutions, print any. If there is no solution, print "-1" (without quotes). Examples Input 50 30 10 10 Output 50 30 10 Input 100 50 10 21 Output -1 Note In first test case all conditions for cars' sizes are satisfied. In second test case there is no answer, because Masha should be able to climb into smallest car (so size of smallest car in not less than 21), but son bear should like it, so maximum possible size of it is 20. ### Response ```cpp #include <bits/stdc++.h> int main() { int v1, v2, v3, vm; scanf("%d%d%d%d", &v1, &v2, &v3, &vm); int c1 = v1, c3 = (v3 > vm) ? v3 : vm, c2 = c3 * 2 + 1; if (c3 > 2 * vm) printf("-1\n"); else if (c3 > 2 * v3) printf("-1\n"); else if (c2 > 2 * v2) printf("-1\n"); else { if (c2 < v2) c2 = v2; if (c2 >= c1) c1 = c2 + 1; if (c1 > 2 * v1) printf("-1\n"); else printf("%d\n%d\n%d\n", c1, c2, c3); } } ```
#include <bits/stdc++.h> using namespace std; const int MAXN = 200005; int main() { int v1, v2, v3, v4; cin >> v1 >> v2 >> v3 >> v4; v1 *= 2; v2 *= 2; v3 *= 2; if (v4 * 2 < v3 / 2 || v4 * 2 >= v2 || v4 > v3) cout << -1 << endl; else { cout << v1 << endl << v2 << endl << min(v3, v4 * 2) << endl; } }
### Prompt Please create a solution in Cpp to the following problem: A family consisting of father bear, mother bear and son bear owns three cars. Father bear can climb into the largest car and he likes it. Also, mother bear can climb into the middle car and she likes it. Moreover, son bear can climb into the smallest car and he likes it. It's known that the largest car is strictly larger than the middle car, and the middle car is strictly larger than the smallest car. Masha came to test these cars. She could climb into all cars, but she liked only the smallest car. It's known that a character with size a can climb into some car with size b if and only if a ≀ b, he or she likes it if and only if he can climb into this car and 2a β‰₯ b. You are given sizes of bears and Masha. Find out some possible integer non-negative sizes of cars. Input You are given four integers V1, V2, V3, Vm(1 ≀ Vi ≀ 100) β€” sizes of father bear, mother bear, son bear and Masha, respectively. It's guaranteed that V1 > V2 > V3. Output Output three integers β€” sizes of father bear's car, mother bear's car and son bear's car, respectively. If there are multiple possible solutions, print any. If there is no solution, print "-1" (without quotes). Examples Input 50 30 10 10 Output 50 30 10 Input 100 50 10 21 Output -1 Note In first test case all conditions for cars' sizes are satisfied. In second test case there is no answer, because Masha should be able to climb into smallest car (so size of smallest car in not less than 21), but son bear should like it, so maximum possible size of it is 20. ### Response ```cpp #include <bits/stdc++.h> using namespace std; const int MAXN = 200005; int main() { int v1, v2, v3, v4; cin >> v1 >> v2 >> v3 >> v4; v1 *= 2; v2 *= 2; v3 *= 2; if (v4 * 2 < v3 / 2 || v4 * 2 >= v2 || v4 > v3) cout << -1 << endl; else { cout << v1 << endl << v2 << endl << min(v3, v4 * 2) << endl; } } ```
#include <bits/stdc++.h> using namespace std; int main() { int v1, v2, v3, v; scanf("%d%d%d%d", &v1, &v2, &v3, &v); for (int i = 300; i >= 0; i--) { for (int j = i - 1; j >= 0; j--) { for (int k = j - 1; k >= 0; k--) { if (i >= v1 && j >= v2 && k >= v3 && k >= v && 2 * v >= k && 2 * v < j && 2 * v < i && 2 * v1 >= i && 2 * v2 >= j && 2 * v3 >= k) { printf("%d\n%d\n%d\n", i, j, k); return 0; } } } } printf("-1"); return 0; }
### Prompt Please formulate a cpp solution to the following problem: A family consisting of father bear, mother bear and son bear owns three cars. Father bear can climb into the largest car and he likes it. Also, mother bear can climb into the middle car and she likes it. Moreover, son bear can climb into the smallest car and he likes it. It's known that the largest car is strictly larger than the middle car, and the middle car is strictly larger than the smallest car. Masha came to test these cars. She could climb into all cars, but she liked only the smallest car. It's known that a character with size a can climb into some car with size b if and only if a ≀ b, he or she likes it if and only if he can climb into this car and 2a β‰₯ b. You are given sizes of bears and Masha. Find out some possible integer non-negative sizes of cars. Input You are given four integers V1, V2, V3, Vm(1 ≀ Vi ≀ 100) β€” sizes of father bear, mother bear, son bear and Masha, respectively. It's guaranteed that V1 > V2 > V3. Output Output three integers β€” sizes of father bear's car, mother bear's car and son bear's car, respectively. If there are multiple possible solutions, print any. If there is no solution, print "-1" (without quotes). Examples Input 50 30 10 10 Output 50 30 10 Input 100 50 10 21 Output -1 Note In first test case all conditions for cars' sizes are satisfied. In second test case there is no answer, because Masha should be able to climb into smallest car (so size of smallest car in not less than 21), but son bear should like it, so maximum possible size of it is 20. ### Response ```cpp #include <bits/stdc++.h> using namespace std; int main() { int v1, v2, v3, v; scanf("%d%d%d%d", &v1, &v2, &v3, &v); for (int i = 300; i >= 0; i--) { for (int j = i - 1; j >= 0; j--) { for (int k = j - 1; k >= 0; k--) { if (i >= v1 && j >= v2 && k >= v3 && k >= v && 2 * v >= k && 2 * v < j && 2 * v < i && 2 * v1 >= i && 2 * v2 >= j && 2 * v3 >= k) { printf("%d\n%d\n%d\n", i, j, k); return 0; } } } } printf("-1"); return 0; } ```
#include <bits/stdc++.h> using namespace std; int main() { int k, l, m, n; cin >> k >> l >> m >> n; if (n >= k || n >= l || m * 2 < n || 2 * n < m) { cout << "-1" << endl; return 0; } k *= 2; l *= 2; if (n > m) m *= 2; cout << k << "\n" << l << "\n" << m << endl; return 0; }
### Prompt Your challenge is to write a Cpp solution to the following problem: A family consisting of father bear, mother bear and son bear owns three cars. Father bear can climb into the largest car and he likes it. Also, mother bear can climb into the middle car and she likes it. Moreover, son bear can climb into the smallest car and he likes it. It's known that the largest car is strictly larger than the middle car, and the middle car is strictly larger than the smallest car. Masha came to test these cars. She could climb into all cars, but she liked only the smallest car. It's known that a character with size a can climb into some car with size b if and only if a ≀ b, he or she likes it if and only if he can climb into this car and 2a β‰₯ b. You are given sizes of bears and Masha. Find out some possible integer non-negative sizes of cars. Input You are given four integers V1, V2, V3, Vm(1 ≀ Vi ≀ 100) β€” sizes of father bear, mother bear, son bear and Masha, respectively. It's guaranteed that V1 > V2 > V3. Output Output three integers β€” sizes of father bear's car, mother bear's car and son bear's car, respectively. If there are multiple possible solutions, print any. If there is no solution, print "-1" (without quotes). Examples Input 50 30 10 10 Output 50 30 10 Input 100 50 10 21 Output -1 Note In first test case all conditions for cars' sizes are satisfied. In second test case there is no answer, because Masha should be able to climb into smallest car (so size of smallest car in not less than 21), but son bear should like it, so maximum possible size of it is 20. ### Response ```cpp #include <bits/stdc++.h> using namespace std; int main() { int k, l, m, n; cin >> k >> l >> m >> n; if (n >= k || n >= l || m * 2 < n || 2 * n < m) { cout << "-1" << endl; return 0; } k *= 2; l *= 2; if (n > m) m *= 2; cout << k << "\n" << l << "\n" << m << endl; return 0; } ```
#include <bits/stdc++.h> using namespace std; int main() { int v1, v2, v3, vm; cin >> v1 >> v2 >> v3 >> vm; for (int i = 1; i <= 200; i++) { for (int j = 1; j <= 200; j++) { for (int k = 1; k <= 200; k++) { if (i > j && j > k && v1 <= i && i <= 2 * v1 && j >= v2 && j <= 2 * v2 && k >= v3 && k <= 2 * v3 && 2 * vm >= k && vm <= k && j > 2 * vm) { cout << i << endl; cout << j << endl; cout << k << endl; return 0; } } } } cout << -1; return 0; }
### Prompt Generate a cpp solution to the following problem: A family consisting of father bear, mother bear and son bear owns three cars. Father bear can climb into the largest car and he likes it. Also, mother bear can climb into the middle car and she likes it. Moreover, son bear can climb into the smallest car and he likes it. It's known that the largest car is strictly larger than the middle car, and the middle car is strictly larger than the smallest car. Masha came to test these cars. She could climb into all cars, but she liked only the smallest car. It's known that a character with size a can climb into some car with size b if and only if a ≀ b, he or she likes it if and only if he can climb into this car and 2a β‰₯ b. You are given sizes of bears and Masha. Find out some possible integer non-negative sizes of cars. Input You are given four integers V1, V2, V3, Vm(1 ≀ Vi ≀ 100) β€” sizes of father bear, mother bear, son bear and Masha, respectively. It's guaranteed that V1 > V2 > V3. Output Output three integers β€” sizes of father bear's car, mother bear's car and son bear's car, respectively. If there are multiple possible solutions, print any. If there is no solution, print "-1" (without quotes). Examples Input 50 30 10 10 Output 50 30 10 Input 100 50 10 21 Output -1 Note In first test case all conditions for cars' sizes are satisfied. In second test case there is no answer, because Masha should be able to climb into smallest car (so size of smallest car in not less than 21), but son bear should like it, so maximum possible size of it is 20. ### Response ```cpp #include <bits/stdc++.h> using namespace std; int main() { int v1, v2, v3, vm; cin >> v1 >> v2 >> v3 >> vm; for (int i = 1; i <= 200; i++) { for (int j = 1; j <= 200; j++) { for (int k = 1; k <= 200; k++) { if (i > j && j > k && v1 <= i && i <= 2 * v1 && j >= v2 && j <= 2 * v2 && k >= v3 && k <= 2 * v3 && 2 * vm >= k && vm <= k && j > 2 * vm) { cout << i << endl; cout << j << endl; cout << k << endl; return 0; } } } } cout << -1; return 0; } ```
#include <bits/stdc++.h> using namespace std; int main() { int v1, v2, v3, vm; cin >> v1 >> v2 >> v3 >> vm; for (int i = v1; i <= 2 * v1; ++i) { for (int j = v2; j <= 2 * v2; ++j) { for (int k = v3; k <= 2 * v3; ++k) { if (i > j && j > k && vm <= k && 2 * vm >= k && 2 * vm < j && 2 * vm < i) { cout << i << "\n" << j << "\n" << k; return 0; } } } } cout << -1; return 0; }
### Prompt Your task is to create a CPP solution to the following problem: A family consisting of father bear, mother bear and son bear owns three cars. Father bear can climb into the largest car and he likes it. Also, mother bear can climb into the middle car and she likes it. Moreover, son bear can climb into the smallest car and he likes it. It's known that the largest car is strictly larger than the middle car, and the middle car is strictly larger than the smallest car. Masha came to test these cars. She could climb into all cars, but she liked only the smallest car. It's known that a character with size a can climb into some car with size b if and only if a ≀ b, he or she likes it if and only if he can climb into this car and 2a β‰₯ b. You are given sizes of bears and Masha. Find out some possible integer non-negative sizes of cars. Input You are given four integers V1, V2, V3, Vm(1 ≀ Vi ≀ 100) β€” sizes of father bear, mother bear, son bear and Masha, respectively. It's guaranteed that V1 > V2 > V3. Output Output three integers β€” sizes of father bear's car, mother bear's car and son bear's car, respectively. If there are multiple possible solutions, print any. If there is no solution, print "-1" (without quotes). Examples Input 50 30 10 10 Output 50 30 10 Input 100 50 10 21 Output -1 Note In first test case all conditions for cars' sizes are satisfied. In second test case there is no answer, because Masha should be able to climb into smallest car (so size of smallest car in not less than 21), but son bear should like it, so maximum possible size of it is 20. ### Response ```cpp #include <bits/stdc++.h> using namespace std; int main() { int v1, v2, v3, vm; cin >> v1 >> v2 >> v3 >> vm; for (int i = v1; i <= 2 * v1; ++i) { for (int j = v2; j <= 2 * v2; ++j) { for (int k = v3; k <= 2 * v3; ++k) { if (i > j && j > k && vm <= k && 2 * vm >= k && 2 * vm < j && 2 * vm < i) { cout << i << "\n" << j << "\n" << k; return 0; } } } } cout << -1; return 0; } ```
#include <bits/stdc++.h> using namespace std; int main() { int a, b, c, d; cin >> a >> b >> c >> d; for (int i = a; i <= 2 * a; ++i) { for (int z = b; z <= 2 * b; ++z) { for (int k = c; k <= 2 * c; ++k) { if (d <= i && d <= z && d <= k && d * 2 < i && 2 * d < z && 2 * d >= k && i > z && z > k) { cout << i << '\n' << z << '\n' << k; return 0; } } } } cout << -1; return 0; }
### Prompt In Cpp, your task is to solve the following problem: A family consisting of father bear, mother bear and son bear owns three cars. Father bear can climb into the largest car and he likes it. Also, mother bear can climb into the middle car and she likes it. Moreover, son bear can climb into the smallest car and he likes it. It's known that the largest car is strictly larger than the middle car, and the middle car is strictly larger than the smallest car. Masha came to test these cars. She could climb into all cars, but she liked only the smallest car. It's known that a character with size a can climb into some car with size b if and only if a ≀ b, he or she likes it if and only if he can climb into this car and 2a β‰₯ b. You are given sizes of bears and Masha. Find out some possible integer non-negative sizes of cars. Input You are given four integers V1, V2, V3, Vm(1 ≀ Vi ≀ 100) β€” sizes of father bear, mother bear, son bear and Masha, respectively. It's guaranteed that V1 > V2 > V3. Output Output three integers β€” sizes of father bear's car, mother bear's car and son bear's car, respectively. If there are multiple possible solutions, print any. If there is no solution, print "-1" (without quotes). Examples Input 50 30 10 10 Output 50 30 10 Input 100 50 10 21 Output -1 Note In first test case all conditions for cars' sizes are satisfied. In second test case there is no answer, because Masha should be able to climb into smallest car (so size of smallest car in not less than 21), but son bear should like it, so maximum possible size of it is 20. ### Response ```cpp #include <bits/stdc++.h> using namespace std; int main() { int a, b, c, d; cin >> a >> b >> c >> d; for (int i = a; i <= 2 * a; ++i) { for (int z = b; z <= 2 * b; ++z) { for (int k = c; k <= 2 * c; ++k) { if (d <= i && d <= z && d <= k && d * 2 < i && 2 * d < z && 2 * d >= k && i > z && z > k) { cout << i << '\n' << z << '\n' << k; return 0; } } } } cout << -1; return 0; } ```
#include <bits/stdc++.h> using namespace std; int main() { int a, b, c, d; cin >> a >> b >> c >> d; if ((a > b && a > c) && (b < a || b > c) && (c < a && c < b)) { if (d > 2 * c || d >= b || c > 2 * d) cout << -1; else { cout << 2 * a << endl; cout << 2 * b << endl; cout << max(c, d); } } else cout << -1; return 0; }
### Prompt Please provide a cpp coded solution to the problem described below: A family consisting of father bear, mother bear and son bear owns three cars. Father bear can climb into the largest car and he likes it. Also, mother bear can climb into the middle car and she likes it. Moreover, son bear can climb into the smallest car and he likes it. It's known that the largest car is strictly larger than the middle car, and the middle car is strictly larger than the smallest car. Masha came to test these cars. She could climb into all cars, but she liked only the smallest car. It's known that a character with size a can climb into some car with size b if and only if a ≀ b, he or she likes it if and only if he can climb into this car and 2a β‰₯ b. You are given sizes of bears and Masha. Find out some possible integer non-negative sizes of cars. Input You are given four integers V1, V2, V3, Vm(1 ≀ Vi ≀ 100) β€” sizes of father bear, mother bear, son bear and Masha, respectively. It's guaranteed that V1 > V2 > V3. Output Output three integers β€” sizes of father bear's car, mother bear's car and son bear's car, respectively. If there are multiple possible solutions, print any. If there is no solution, print "-1" (without quotes). Examples Input 50 30 10 10 Output 50 30 10 Input 100 50 10 21 Output -1 Note In first test case all conditions for cars' sizes are satisfied. In second test case there is no answer, because Masha should be able to climb into smallest car (so size of smallest car in not less than 21), but son bear should like it, so maximum possible size of it is 20. ### Response ```cpp #include <bits/stdc++.h> using namespace std; int main() { int a, b, c, d; cin >> a >> b >> c >> d; if ((a > b && a > c) && (b < a || b > c) && (c < a && c < b)) { if (d > 2 * c || d >= b || c > 2 * d) cout << -1; else { cout << 2 * a << endl; cout << 2 * b << endl; cout << max(c, d); } } else cout << -1; return 0; } ```
#include <bits/stdc++.h> using namespace std; int main() { int a, b, c, d; scanf("%d %d %d %d", &a, &b, &c, &d); for (int i = 1; i <= 200; i++) { for (int j = 1; j < i; j++) { for (int k = 1; k < j; k++) { if (a <= i && 2 * a >= i && b <= j && 2 * b >= j && c <= k && 2 * c >= k && d <= k && 2 * d >= k && 2 * d < j) { printf("%d\n%d\n%d\n", i, j, k); return 0; } } } } puts("-1"); return 0; }
### Prompt Please formulate a Cpp solution to the following problem: A family consisting of father bear, mother bear and son bear owns three cars. Father bear can climb into the largest car and he likes it. Also, mother bear can climb into the middle car and she likes it. Moreover, son bear can climb into the smallest car and he likes it. It's known that the largest car is strictly larger than the middle car, and the middle car is strictly larger than the smallest car. Masha came to test these cars. She could climb into all cars, but she liked only the smallest car. It's known that a character with size a can climb into some car with size b if and only if a ≀ b, he or she likes it if and only if he can climb into this car and 2a β‰₯ b. You are given sizes of bears and Masha. Find out some possible integer non-negative sizes of cars. Input You are given four integers V1, V2, V3, Vm(1 ≀ Vi ≀ 100) β€” sizes of father bear, mother bear, son bear and Masha, respectively. It's guaranteed that V1 > V2 > V3. Output Output three integers β€” sizes of father bear's car, mother bear's car and son bear's car, respectively. If there are multiple possible solutions, print any. If there is no solution, print "-1" (without quotes). Examples Input 50 30 10 10 Output 50 30 10 Input 100 50 10 21 Output -1 Note In first test case all conditions for cars' sizes are satisfied. In second test case there is no answer, because Masha should be able to climb into smallest car (so size of smallest car in not less than 21), but son bear should like it, so maximum possible size of it is 20. ### Response ```cpp #include <bits/stdc++.h> using namespace std; int main() { int a, b, c, d; scanf("%d %d %d %d", &a, &b, &c, &d); for (int i = 1; i <= 200; i++) { for (int j = 1; j < i; j++) { for (int k = 1; k < j; k++) { if (a <= i && 2 * a >= i && b <= j && 2 * b >= j && c <= k && 2 * c >= k && d <= k && 2 * d >= k && 2 * d < j) { printf("%d\n%d\n%d\n", i, j, k); return 0; } } } } puts("-1"); return 0; } ```
#include <bits/stdc++.h> using namespace std; template <typename T, typename U> inline ostream &operator<<(ostream &_out, const pair<T, U> &_p) { _out << _p.first << ' ' << _p.second; return _out; } template <typename T, typename U> inline istream &operator>>(istream &_in, pair<T, U> &_p) { _in >> _p.first >> _p.second; return _in; } template <typename T> inline ostream &operator<<(ostream &_out, const vector<T> &_v) { if (_v.empty()) { return _out; } _out << _v.front(); for (auto _it = ++_v.begin(); _it != _v.end(); ++_it) { _out << ' ' << *_it; } return _out; } template <typename T> inline istream &operator>>(istream &_in, vector<T> &_v) { for (auto &_i : _v) { _in >> _i; } return _in; } const long long MAXN = 3e5; const long long INF = 1e9; const long long MOD = 1e9 + 7; class AMashaIMedvedi { public: void solve(std::istream &in, std::ostream &out) { vector<long long> v(3); long long vv; in >> v >> vv; vector<long long> minob(3); for (long long i = 0; i < 3; i++) { minob[i] = max(minob[i], v[i]); } minob[0] = max(minob[0], 2 * vv + 1); minob[1] = max(minob[1], 2 * vv + 1); minob[2] = max(minob[2], vv); for (long long i = 0; i < 3; i++) { if (minob[i] < v[i] || 2 * v[i] < minob[i]) { out << -1; return; } if ((minob[i] >= vv && 2 * vv >= minob[i]) ^ (i >= 2)) { out << -1; return; } } for (long long i = 2; i >= 1; i--) { minob[i - 1] = max(minob[i - 1], minob[i] + 1); } for (auto v : minob) { out << v << '\n'; } } }; signed main() { ios_base::sync_with_stdio(0); cin.tie(0); AMashaIMedvedi solver; std::istream &in(std::cin); std::ostream &out(std::cout); solver.solve(in, out); return 0; }
### Prompt Develop a solution in Cpp to the problem described below: A family consisting of father bear, mother bear and son bear owns three cars. Father bear can climb into the largest car and he likes it. Also, mother bear can climb into the middle car and she likes it. Moreover, son bear can climb into the smallest car and he likes it. It's known that the largest car is strictly larger than the middle car, and the middle car is strictly larger than the smallest car. Masha came to test these cars. She could climb into all cars, but she liked only the smallest car. It's known that a character with size a can climb into some car with size b if and only if a ≀ b, he or she likes it if and only if he can climb into this car and 2a β‰₯ b. You are given sizes of bears and Masha. Find out some possible integer non-negative sizes of cars. Input You are given four integers V1, V2, V3, Vm(1 ≀ Vi ≀ 100) β€” sizes of father bear, mother bear, son bear and Masha, respectively. It's guaranteed that V1 > V2 > V3. Output Output three integers β€” sizes of father bear's car, mother bear's car and son bear's car, respectively. If there are multiple possible solutions, print any. If there is no solution, print "-1" (without quotes). Examples Input 50 30 10 10 Output 50 30 10 Input 100 50 10 21 Output -1 Note In first test case all conditions for cars' sizes are satisfied. In second test case there is no answer, because Masha should be able to climb into smallest car (so size of smallest car in not less than 21), but son bear should like it, so maximum possible size of it is 20. ### Response ```cpp #include <bits/stdc++.h> using namespace std; template <typename T, typename U> inline ostream &operator<<(ostream &_out, const pair<T, U> &_p) { _out << _p.first << ' ' << _p.second; return _out; } template <typename T, typename U> inline istream &operator>>(istream &_in, pair<T, U> &_p) { _in >> _p.first >> _p.second; return _in; } template <typename T> inline ostream &operator<<(ostream &_out, const vector<T> &_v) { if (_v.empty()) { return _out; } _out << _v.front(); for (auto _it = ++_v.begin(); _it != _v.end(); ++_it) { _out << ' ' << *_it; } return _out; } template <typename T> inline istream &operator>>(istream &_in, vector<T> &_v) { for (auto &_i : _v) { _in >> _i; } return _in; } const long long MAXN = 3e5; const long long INF = 1e9; const long long MOD = 1e9 + 7; class AMashaIMedvedi { public: void solve(std::istream &in, std::ostream &out) { vector<long long> v(3); long long vv; in >> v >> vv; vector<long long> minob(3); for (long long i = 0; i < 3; i++) { minob[i] = max(minob[i], v[i]); } minob[0] = max(minob[0], 2 * vv + 1); minob[1] = max(minob[1], 2 * vv + 1); minob[2] = max(minob[2], vv); for (long long i = 0; i < 3; i++) { if (minob[i] < v[i] || 2 * v[i] < minob[i]) { out << -1; return; } if ((minob[i] >= vv && 2 * vv >= minob[i]) ^ (i >= 2)) { out << -1; return; } } for (long long i = 2; i >= 1; i--) { minob[i - 1] = max(minob[i - 1], minob[i] + 1); } for (auto v : minob) { out << v << '\n'; } } }; signed main() { ios_base::sync_with_stdio(0); cin.tie(0); AMashaIMedvedi solver; std::istream &in(std::cin); std::ostream &out(std::cout); solver.solve(in, out); return 0; } ```
#include <bits/stdc++.h> using namespace std; int main() { int v1, v2, v3, vm, c1, c2, c3; cin >> v1 >> v2 >> v3 >> vm; c1 = v1 * 2; c2 = v2 * 2; c3 = max(v3, vm); if (!(c3 <= 2 * min(v3, vm) && c2 >= 2 * vm && vm < v2)) cout << -1; else cout << c1 << '\n' << c2 << '\n' << c3; return 0; }
### Prompt Construct a CPP code solution to the problem outlined: A family consisting of father bear, mother bear and son bear owns three cars. Father bear can climb into the largest car and he likes it. Also, mother bear can climb into the middle car and she likes it. Moreover, son bear can climb into the smallest car and he likes it. It's known that the largest car is strictly larger than the middle car, and the middle car is strictly larger than the smallest car. Masha came to test these cars. She could climb into all cars, but she liked only the smallest car. It's known that a character with size a can climb into some car with size b if and only if a ≀ b, he or she likes it if and only if he can climb into this car and 2a β‰₯ b. You are given sizes of bears and Masha. Find out some possible integer non-negative sizes of cars. Input You are given four integers V1, V2, V3, Vm(1 ≀ Vi ≀ 100) β€” sizes of father bear, mother bear, son bear and Masha, respectively. It's guaranteed that V1 > V2 > V3. Output Output three integers β€” sizes of father bear's car, mother bear's car and son bear's car, respectively. If there are multiple possible solutions, print any. If there is no solution, print "-1" (without quotes). Examples Input 50 30 10 10 Output 50 30 10 Input 100 50 10 21 Output -1 Note In first test case all conditions for cars' sizes are satisfied. In second test case there is no answer, because Masha should be able to climb into smallest car (so size of smallest car in not less than 21), but son bear should like it, so maximum possible size of it is 20. ### Response ```cpp #include <bits/stdc++.h> using namespace std; int main() { int v1, v2, v3, vm, c1, c2, c3; cin >> v1 >> v2 >> v3 >> vm; c1 = v1 * 2; c2 = v2 * 2; c3 = max(v3, vm); if (!(c3 <= 2 * min(v3, vm) && c2 >= 2 * vm && vm < v2)) cout << -1; else cout << c1 << '\n' << c2 << '\n' << c3; return 0; } ```
#include <bits/stdc++.h> using namespace std; int main() { int a, b, c, m; cin >> a >> b >> c >> m; if (b > m && (c << 1) >= m && (m << 1) >= c) { cout << (a << 1) << endl; cout << (b << 1) << endl; cout << max(c, m) << endl; } else cout << -1 << endl; return 0; }
### Prompt Generate a Cpp solution to the following problem: A family consisting of father bear, mother bear and son bear owns three cars. Father bear can climb into the largest car and he likes it. Also, mother bear can climb into the middle car and she likes it. Moreover, son bear can climb into the smallest car and he likes it. It's known that the largest car is strictly larger than the middle car, and the middle car is strictly larger than the smallest car. Masha came to test these cars. She could climb into all cars, but she liked only the smallest car. It's known that a character with size a can climb into some car with size b if and only if a ≀ b, he or she likes it if and only if he can climb into this car and 2a β‰₯ b. You are given sizes of bears and Masha. Find out some possible integer non-negative sizes of cars. Input You are given four integers V1, V2, V3, Vm(1 ≀ Vi ≀ 100) β€” sizes of father bear, mother bear, son bear and Masha, respectively. It's guaranteed that V1 > V2 > V3. Output Output three integers β€” sizes of father bear's car, mother bear's car and son bear's car, respectively. If there are multiple possible solutions, print any. If there is no solution, print "-1" (without quotes). Examples Input 50 30 10 10 Output 50 30 10 Input 100 50 10 21 Output -1 Note In first test case all conditions for cars' sizes are satisfied. In second test case there is no answer, because Masha should be able to climb into smallest car (so size of smallest car in not less than 21), but son bear should like it, so maximum possible size of it is 20. ### Response ```cpp #include <bits/stdc++.h> using namespace std; int main() { int a, b, c, m; cin >> a >> b >> c >> m; if (b > m && (c << 1) >= m && (m << 1) >= c) { cout << (a << 1) << endl; cout << (b << 1) << endl; cout << max(c, m) << endl; } else cout << -1 << endl; return 0; } ```
#include <bits/stdc++.h> using namespace std; int main() { int v1, v2, v3, v4; cin >> v1 >> v2 >> v3 >> v4; int v11 = 2 * v1; int v22 = 2 * v2; int v33 = 2 * v3; int v44 = 2 * v4; int sc, mc, bc; bool flag = false; for (int i = v3; i <= v33; i++) { if (i >= v4 && i <= v44) { flag = true; sc = i; break; } } if (!flag) { cout << -1; return 0; } flag = false; for (int i = v2; i <= v22; i++) { if (i > sc) { if (i > v44) { flag = true; mc = i; break; } } } if (!flag) { cout << -1; return 0; } flag = false; for (int i = v1; i <= v11; i++) { if (i > mc) { if (i > v44) { flag = true; bc = i; break; } } } if (!flag) { cout << -1; return 0; } cout << bc << endl; cout << mc << endl; cout << sc << endl; return 0; }
### Prompt Construct a Cpp code solution to the problem outlined: A family consisting of father bear, mother bear and son bear owns three cars. Father bear can climb into the largest car and he likes it. Also, mother bear can climb into the middle car and she likes it. Moreover, son bear can climb into the smallest car and he likes it. It's known that the largest car is strictly larger than the middle car, and the middle car is strictly larger than the smallest car. Masha came to test these cars. She could climb into all cars, but she liked only the smallest car. It's known that a character with size a can climb into some car with size b if and only if a ≀ b, he or she likes it if and only if he can climb into this car and 2a β‰₯ b. You are given sizes of bears and Masha. Find out some possible integer non-negative sizes of cars. Input You are given four integers V1, V2, V3, Vm(1 ≀ Vi ≀ 100) β€” sizes of father bear, mother bear, son bear and Masha, respectively. It's guaranteed that V1 > V2 > V3. Output Output three integers β€” sizes of father bear's car, mother bear's car and son bear's car, respectively. If there are multiple possible solutions, print any. If there is no solution, print "-1" (without quotes). Examples Input 50 30 10 10 Output 50 30 10 Input 100 50 10 21 Output -1 Note In first test case all conditions for cars' sizes are satisfied. In second test case there is no answer, because Masha should be able to climb into smallest car (so size of smallest car in not less than 21), but son bear should like it, so maximum possible size of it is 20. ### Response ```cpp #include <bits/stdc++.h> using namespace std; int main() { int v1, v2, v3, v4; cin >> v1 >> v2 >> v3 >> v4; int v11 = 2 * v1; int v22 = 2 * v2; int v33 = 2 * v3; int v44 = 2 * v4; int sc, mc, bc; bool flag = false; for (int i = v3; i <= v33; i++) { if (i >= v4 && i <= v44) { flag = true; sc = i; break; } } if (!flag) { cout << -1; return 0; } flag = false; for (int i = v2; i <= v22; i++) { if (i > sc) { if (i > v44) { flag = true; mc = i; break; } } } if (!flag) { cout << -1; return 0; } flag = false; for (int i = v1; i <= v11; i++) { if (i > mc) { if (i > v44) { flag = true; bc = i; break; } } } if (!flag) { cout << -1; return 0; } cout << bc << endl; cout << mc << endl; cout << sc << endl; return 0; } ```
#include <bits/stdc++.h> using namespace std; using ll = long long; enum {}; int main() { ios::sync_with_stdio(false); cin.tie(0); int v[3], vm; cin >> v[0] >> v[1] >> v[2] >> vm; int c[3], ans[3]; for (int i = 0; i < 3; ++i) { ans[i] = -1; } for (c[0] = 1; c[0] <= 300; ++c[0]) { for (c[1] = 1; c[1] <= 300; ++c[1]) { for (c[2] = 1; c[2] <= 300; ++c[2]) { bool flag = true; for (int i = 0; i < 3; ++i) { flag &= v[i] <= c[i]; flag &= vm <= c[i]; flag &= 2 * v[i] >= c[i]; } flag &= 2 * vm < c[0]; flag &= 2 * vm < c[1]; flag &= 2 * vm >= c[2]; flag &= c[0] > c[1]; flag &= c[1] > c[2]; if (flag) { for (int i = 0; i < 3; ++i) { ans[i] = c[i]; } } } } } for (int i = 0; i < 3; ++i) { cout << ans[i] << '\n'; if (ans[i] == -1) { break; } } return 0; }
### Prompt Generate a Cpp solution to the following problem: A family consisting of father bear, mother bear and son bear owns three cars. Father bear can climb into the largest car and he likes it. Also, mother bear can climb into the middle car and she likes it. Moreover, son bear can climb into the smallest car and he likes it. It's known that the largest car is strictly larger than the middle car, and the middle car is strictly larger than the smallest car. Masha came to test these cars. She could climb into all cars, but she liked only the smallest car. It's known that a character with size a can climb into some car with size b if and only if a ≀ b, he or she likes it if and only if he can climb into this car and 2a β‰₯ b. You are given sizes of bears and Masha. Find out some possible integer non-negative sizes of cars. Input You are given four integers V1, V2, V3, Vm(1 ≀ Vi ≀ 100) β€” sizes of father bear, mother bear, son bear and Masha, respectively. It's guaranteed that V1 > V2 > V3. Output Output three integers β€” sizes of father bear's car, mother bear's car and son bear's car, respectively. If there are multiple possible solutions, print any. If there is no solution, print "-1" (without quotes). Examples Input 50 30 10 10 Output 50 30 10 Input 100 50 10 21 Output -1 Note In first test case all conditions for cars' sizes are satisfied. In second test case there is no answer, because Masha should be able to climb into smallest car (so size of smallest car in not less than 21), but son bear should like it, so maximum possible size of it is 20. ### Response ```cpp #include <bits/stdc++.h> using namespace std; using ll = long long; enum {}; int main() { ios::sync_with_stdio(false); cin.tie(0); int v[3], vm; cin >> v[0] >> v[1] >> v[2] >> vm; int c[3], ans[3]; for (int i = 0; i < 3; ++i) { ans[i] = -1; } for (c[0] = 1; c[0] <= 300; ++c[0]) { for (c[1] = 1; c[1] <= 300; ++c[1]) { for (c[2] = 1; c[2] <= 300; ++c[2]) { bool flag = true; for (int i = 0; i < 3; ++i) { flag &= v[i] <= c[i]; flag &= vm <= c[i]; flag &= 2 * v[i] >= c[i]; } flag &= 2 * vm < c[0]; flag &= 2 * vm < c[1]; flag &= 2 * vm >= c[2]; flag &= c[0] > c[1]; flag &= c[1] > c[2]; if (flag) { for (int i = 0; i < 3; ++i) { ans[i] = c[i]; } } } } } for (int i = 0; i < 3; ++i) { cout << ans[i] << '\n'; if (ans[i] == -1) { break; } } return 0; } ```
#include <bits/stdc++.h> using namespace std; template <typename T> void $readvec(const vector<T>& vec, int cnt) { vec.resize(cnt); for (int i = 0; i < cnt; ++i) { cin >> vec[i]; } } void $main(); int main() { if (0) { freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); } $main(); } void $main() { int V1, V2, V3, VM; cin >> V1 >> V2 >> V3 >> VM; for (int a = 0; a <= 200; ++a) { for (int b = a + 1; b <= 200; ++b) { for (int c = b + 1; c <= 200; ++c) { if (c < V1 || b < V2 || a < V3) continue; if (c > 2 * V1 || b > 2 * V2 || a > 2 * V3) continue; if (a < VM) continue; if (b <= 2 * VM) continue; if (a > 2 * VM) continue; cout << c << endl << b << endl << a << endl; return; } } } cout << -1; }
### Prompt In cpp, your task is to solve the following problem: A family consisting of father bear, mother bear and son bear owns three cars. Father bear can climb into the largest car and he likes it. Also, mother bear can climb into the middle car and she likes it. Moreover, son bear can climb into the smallest car and he likes it. It's known that the largest car is strictly larger than the middle car, and the middle car is strictly larger than the smallest car. Masha came to test these cars. She could climb into all cars, but she liked only the smallest car. It's known that a character with size a can climb into some car with size b if and only if a ≀ b, he or she likes it if and only if he can climb into this car and 2a β‰₯ b. You are given sizes of bears and Masha. Find out some possible integer non-negative sizes of cars. Input You are given four integers V1, V2, V3, Vm(1 ≀ Vi ≀ 100) β€” sizes of father bear, mother bear, son bear and Masha, respectively. It's guaranteed that V1 > V2 > V3. Output Output three integers β€” sizes of father bear's car, mother bear's car and son bear's car, respectively. If there are multiple possible solutions, print any. If there is no solution, print "-1" (without quotes). Examples Input 50 30 10 10 Output 50 30 10 Input 100 50 10 21 Output -1 Note In first test case all conditions for cars' sizes are satisfied. In second test case there is no answer, because Masha should be able to climb into smallest car (so size of smallest car in not less than 21), but son bear should like it, so maximum possible size of it is 20. ### Response ```cpp #include <bits/stdc++.h> using namespace std; template <typename T> void $readvec(const vector<T>& vec, int cnt) { vec.resize(cnt); for (int i = 0; i < cnt; ++i) { cin >> vec[i]; } } void $main(); int main() { if (0) { freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); } $main(); } void $main() { int V1, V2, V3, VM; cin >> V1 >> V2 >> V3 >> VM; for (int a = 0; a <= 200; ++a) { for (int b = a + 1; b <= 200; ++b) { for (int c = b + 1; c <= 200; ++c) { if (c < V1 || b < V2 || a < V3) continue; if (c > 2 * V1 || b > 2 * V2 || a > 2 * V3) continue; if (a < VM) continue; if (b <= 2 * VM) continue; if (a > 2 * VM) continue; cout << c << endl << b << endl << a << endl; return; } } } cout << -1; } ```
#include <bits/stdc++.h> int main() { int a, b, c, d; scanf("%d%d%d%d", &a, &b, &c, &d); if (d > 2 * c) printf("-1"); else if (d >= b) printf("-1"); else if (2 * d < c) printf("-1"); else if (2 * d >= c && d <= c) printf("%d\n%d\n%d\n", 2 * a, 2 * b, c); else if (d > c && d <= 2 * c) printf("%d\n%d\n%d\n", 2 * a, 2 * b, 2 * c); }
### Prompt Please create a solution in CPP to the following problem: A family consisting of father bear, mother bear and son bear owns three cars. Father bear can climb into the largest car and he likes it. Also, mother bear can climb into the middle car and she likes it. Moreover, son bear can climb into the smallest car and he likes it. It's known that the largest car is strictly larger than the middle car, and the middle car is strictly larger than the smallest car. Masha came to test these cars. She could climb into all cars, but she liked only the smallest car. It's known that a character with size a can climb into some car with size b if and only if a ≀ b, he or she likes it if and only if he can climb into this car and 2a β‰₯ b. You are given sizes of bears and Masha. Find out some possible integer non-negative sizes of cars. Input You are given four integers V1, V2, V3, Vm(1 ≀ Vi ≀ 100) β€” sizes of father bear, mother bear, son bear and Masha, respectively. It's guaranteed that V1 > V2 > V3. Output Output three integers β€” sizes of father bear's car, mother bear's car and son bear's car, respectively. If there are multiple possible solutions, print any. If there is no solution, print "-1" (without quotes). Examples Input 50 30 10 10 Output 50 30 10 Input 100 50 10 21 Output -1 Note In first test case all conditions for cars' sizes are satisfied. In second test case there is no answer, because Masha should be able to climb into smallest car (so size of smallest car in not less than 21), but son bear should like it, so maximum possible size of it is 20. ### Response ```cpp #include <bits/stdc++.h> int main() { int a, b, c, d; scanf("%d%d%d%d", &a, &b, &c, &d); if (d > 2 * c) printf("-1"); else if (d >= b) printf("-1"); else if (2 * d < c) printf("-1"); else if (2 * d >= c && d <= c) printf("%d\n%d\n%d\n", 2 * a, 2 * b, c); else if (d > c && d <= 2 * c) printf("%d\n%d\n%d\n", 2 * a, 2 * b, 2 * c); } ```
#include <bits/stdc++.h> using namespace std; const long long int mod = 1000000007; void func() { long long int v1, v2, v3, vm; cin >> v1 >> v2 >> v3 >> vm; for (long long int c3 = v3; c3 <= 2 * v3; c3++) { for (long long int c2 = v2; c2 <= 2 * v2; c2++) { for (long long int c1 = v1; c1 <= 2 * v1; c1++) { if (2 * vm >= c3 and 2 * vm < c2 and vm <= c3 and c3 < c2 and c2 < c1) { cout << c1 << '\n' << c2 << '\n' << c3 << '\n'; return; } } } } cout << -1; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ; long long int t = 1; while (t--) func(); }
### Prompt Construct a Cpp code solution to the problem outlined: A family consisting of father bear, mother bear and son bear owns three cars. Father bear can climb into the largest car and he likes it. Also, mother bear can climb into the middle car and she likes it. Moreover, son bear can climb into the smallest car and he likes it. It's known that the largest car is strictly larger than the middle car, and the middle car is strictly larger than the smallest car. Masha came to test these cars. She could climb into all cars, but she liked only the smallest car. It's known that a character with size a can climb into some car with size b if and only if a ≀ b, he or she likes it if and only if he can climb into this car and 2a β‰₯ b. You are given sizes of bears and Masha. Find out some possible integer non-negative sizes of cars. Input You are given four integers V1, V2, V3, Vm(1 ≀ Vi ≀ 100) β€” sizes of father bear, mother bear, son bear and Masha, respectively. It's guaranteed that V1 > V2 > V3. Output Output three integers β€” sizes of father bear's car, mother bear's car and son bear's car, respectively. If there are multiple possible solutions, print any. If there is no solution, print "-1" (without quotes). Examples Input 50 30 10 10 Output 50 30 10 Input 100 50 10 21 Output -1 Note In first test case all conditions for cars' sizes are satisfied. In second test case there is no answer, because Masha should be able to climb into smallest car (so size of smallest car in not less than 21), but son bear should like it, so maximum possible size of it is 20. ### Response ```cpp #include <bits/stdc++.h> using namespace std; const long long int mod = 1000000007; void func() { long long int v1, v2, v3, vm; cin >> v1 >> v2 >> v3 >> vm; for (long long int c3 = v3; c3 <= 2 * v3; c3++) { for (long long int c2 = v2; c2 <= 2 * v2; c2++) { for (long long int c1 = v1; c1 <= 2 * v1; c1++) { if (2 * vm >= c3 and 2 * vm < c2 and vm <= c3 and c3 < c2 and c2 < c1) { cout << c1 << '\n' << c2 << '\n' << c3 << '\n'; return; } } } } cout << -1; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ; long long int t = 1; while (t--) func(); } ```
#include <bits/stdc++.h> using namespace std; int main() { std::ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int m, n, k, s, flag = 0, ss, b; cin >> m >> n >> k >> s; for (int i = k; i <= 2 * k; i++) { for (int j = k + 1; j <= 2 * n; j++) { for (int b = j + 1; b <= 2 * m; b++) { if (s <= i && 2 * s >= i && 2 * s < j && 2 * s < b && j >= n && b >= m) { flag = 1; cout << b << " " << j << " " << i << endl; break; } } if (flag) break; } if (flag) break; } if (!flag) cout << "-1" << endl; return 0; }
### Prompt Please formulate a CPP solution to the following problem: A family consisting of father bear, mother bear and son bear owns three cars. Father bear can climb into the largest car and he likes it. Also, mother bear can climb into the middle car and she likes it. Moreover, son bear can climb into the smallest car and he likes it. It's known that the largest car is strictly larger than the middle car, and the middle car is strictly larger than the smallest car. Masha came to test these cars. She could climb into all cars, but she liked only the smallest car. It's known that a character with size a can climb into some car with size b if and only if a ≀ b, he or she likes it if and only if he can climb into this car and 2a β‰₯ b. You are given sizes of bears and Masha. Find out some possible integer non-negative sizes of cars. Input You are given four integers V1, V2, V3, Vm(1 ≀ Vi ≀ 100) β€” sizes of father bear, mother bear, son bear and Masha, respectively. It's guaranteed that V1 > V2 > V3. Output Output three integers β€” sizes of father bear's car, mother bear's car and son bear's car, respectively. If there are multiple possible solutions, print any. If there is no solution, print "-1" (without quotes). Examples Input 50 30 10 10 Output 50 30 10 Input 100 50 10 21 Output -1 Note In first test case all conditions for cars' sizes are satisfied. In second test case there is no answer, because Masha should be able to climb into smallest car (so size of smallest car in not less than 21), but son bear should like it, so maximum possible size of it is 20. ### Response ```cpp #include <bits/stdc++.h> using namespace std; int main() { std::ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int m, n, k, s, flag = 0, ss, b; cin >> m >> n >> k >> s; for (int i = k; i <= 2 * k; i++) { for (int j = k + 1; j <= 2 * n; j++) { for (int b = j + 1; b <= 2 * m; b++) { if (s <= i && 2 * s >= i && 2 * s < j && 2 * s < b && j >= n && b >= m) { flag = 1; cout << b << " " << j << " " << i << endl; break; } } if (flag) break; } if (flag) break; } if (!flag) cout << "-1" << endl; return 0; } ```
#include <bits/stdc++.h> using namespace std; int v1, v2, v3, vm; int c1, c2, c3; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> v1 >> v2 >> v3 >> vm; for (c1 = v1; c1 <= 2 * v1; c1++) { for (c2 = v2; c2 <= 2 * v2; c2++) for (c3 = v3; c3 <= 2 * v3; c3++) { if (c2 >= c1 || c3 >= c2) continue; if (vm > c3 || 2 * vm < c3 || 2 * vm >= c2) continue; cout << c1 << endl << c2 << endl << c3 << endl; return 0; } } cout << -1 << endl; return 0; }
### Prompt Develop a solution in cpp to the problem described below: A family consisting of father bear, mother bear and son bear owns three cars. Father bear can climb into the largest car and he likes it. Also, mother bear can climb into the middle car and she likes it. Moreover, son bear can climb into the smallest car and he likes it. It's known that the largest car is strictly larger than the middle car, and the middle car is strictly larger than the smallest car. Masha came to test these cars. She could climb into all cars, but she liked only the smallest car. It's known that a character with size a can climb into some car with size b if and only if a ≀ b, he or she likes it if and only if he can climb into this car and 2a β‰₯ b. You are given sizes of bears and Masha. Find out some possible integer non-negative sizes of cars. Input You are given four integers V1, V2, V3, Vm(1 ≀ Vi ≀ 100) β€” sizes of father bear, mother bear, son bear and Masha, respectively. It's guaranteed that V1 > V2 > V3. Output Output three integers β€” sizes of father bear's car, mother bear's car and son bear's car, respectively. If there are multiple possible solutions, print any. If there is no solution, print "-1" (without quotes). Examples Input 50 30 10 10 Output 50 30 10 Input 100 50 10 21 Output -1 Note In first test case all conditions for cars' sizes are satisfied. In second test case there is no answer, because Masha should be able to climb into smallest car (so size of smallest car in not less than 21), but son bear should like it, so maximum possible size of it is 20. ### Response ```cpp #include <bits/stdc++.h> using namespace std; int v1, v2, v3, vm; int c1, c2, c3; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> v1 >> v2 >> v3 >> vm; for (c1 = v1; c1 <= 2 * v1; c1++) { for (c2 = v2; c2 <= 2 * v2; c2++) for (c3 = v3; c3 <= 2 * v3; c3++) { if (c2 >= c1 || c3 >= c2) continue; if (vm > c3 || 2 * vm < c3 || 2 * vm >= c2) continue; cout << c1 << endl << c2 << endl << c3 << endl; return 0; } } cout << -1 << endl; return 0; } ```
#include <bits/stdc++.h> using namespace std; const int maxn = 2e2 + 5; int v[5]; bool check(int a, int b) { if (a <= b) { return (2 * a >= b); } return false; } int main() { for (int i = 1; i <= 4; ++i) { cin >> v[i]; } for (int i = 1; i <= maxn; ++i) { if (check(v[1], i)) { for (int j = 1; j < i; ++j) { if (check(v[2], j)) { for (int k = 1; k < j; ++k) { if (check(v[3], k) && v[4] <= min(i, min(j, k))) { if (check(v[4], k) && !check(v[4], i) && !check(v[4], j)) { cout << i << "\n" << j << "\n" << k; return 0; } } } } } } } cout << -1; return 0; }
### Prompt Develop a solution in cpp to the problem described below: A family consisting of father bear, mother bear and son bear owns three cars. Father bear can climb into the largest car and he likes it. Also, mother bear can climb into the middle car and she likes it. Moreover, son bear can climb into the smallest car and he likes it. It's known that the largest car is strictly larger than the middle car, and the middle car is strictly larger than the smallest car. Masha came to test these cars. She could climb into all cars, but she liked only the smallest car. It's known that a character with size a can climb into some car with size b if and only if a ≀ b, he or she likes it if and only if he can climb into this car and 2a β‰₯ b. You are given sizes of bears and Masha. Find out some possible integer non-negative sizes of cars. Input You are given four integers V1, V2, V3, Vm(1 ≀ Vi ≀ 100) β€” sizes of father bear, mother bear, son bear and Masha, respectively. It's guaranteed that V1 > V2 > V3. Output Output three integers β€” sizes of father bear's car, mother bear's car and son bear's car, respectively. If there are multiple possible solutions, print any. If there is no solution, print "-1" (without quotes). Examples Input 50 30 10 10 Output 50 30 10 Input 100 50 10 21 Output -1 Note In first test case all conditions for cars' sizes are satisfied. In second test case there is no answer, because Masha should be able to climb into smallest car (so size of smallest car in not less than 21), but son bear should like it, so maximum possible size of it is 20. ### Response ```cpp #include <bits/stdc++.h> using namespace std; const int maxn = 2e2 + 5; int v[5]; bool check(int a, int b) { if (a <= b) { return (2 * a >= b); } return false; } int main() { for (int i = 1; i <= 4; ++i) { cin >> v[i]; } for (int i = 1; i <= maxn; ++i) { if (check(v[1], i)) { for (int j = 1; j < i; ++j) { if (check(v[2], j)) { for (int k = 1; k < j; ++k) { if (check(v[3], k) && v[4] <= min(i, min(j, k))) { if (check(v[4], k) && !check(v[4], i) && !check(v[4], j)) { cout << i << "\n" << j << "\n" << k; return 0; } } } } } } } cout << -1; return 0; } ```
#include <bits/stdc++.h> using namespace std; int const N = 202000; int main() { int a, b, c, d; cin >> a >> b >> c >> d; if (d >= b) { cout << -1; return 0; } for (int i = c; i <= c * 2; i++) { if (i >= d && i <= d * 2) { cout << a * 2 << endl << b * 2 << endl << i; return 0; } } cout << -1; return 0; }
### Prompt Develop a solution in cpp to the problem described below: A family consisting of father bear, mother bear and son bear owns three cars. Father bear can climb into the largest car and he likes it. Also, mother bear can climb into the middle car and she likes it. Moreover, son bear can climb into the smallest car and he likes it. It's known that the largest car is strictly larger than the middle car, and the middle car is strictly larger than the smallest car. Masha came to test these cars. She could climb into all cars, but she liked only the smallest car. It's known that a character with size a can climb into some car with size b if and only if a ≀ b, he or she likes it if and only if he can climb into this car and 2a β‰₯ b. You are given sizes of bears and Masha. Find out some possible integer non-negative sizes of cars. Input You are given four integers V1, V2, V3, Vm(1 ≀ Vi ≀ 100) β€” sizes of father bear, mother bear, son bear and Masha, respectively. It's guaranteed that V1 > V2 > V3. Output Output three integers β€” sizes of father bear's car, mother bear's car and son bear's car, respectively. If there are multiple possible solutions, print any. If there is no solution, print "-1" (without quotes). Examples Input 50 30 10 10 Output 50 30 10 Input 100 50 10 21 Output -1 Note In first test case all conditions for cars' sizes are satisfied. In second test case there is no answer, because Masha should be able to climb into smallest car (so size of smallest car in not less than 21), but son bear should like it, so maximum possible size of it is 20. ### Response ```cpp #include <bits/stdc++.h> using namespace std; int const N = 202000; int main() { int a, b, c, d; cin >> a >> b >> c >> d; if (d >= b) { cout << -1; return 0; } for (int i = c; i <= c * 2; i++) { if (i >= d && i <= d * 2) { cout << a * 2 << endl << b * 2 << endl << i; return 0; } } cout << -1; return 0; } ```
#include <bits/stdc++.h> using namespace std; int a, b, c, d; int main() { scanf("%d%d%d%d", &a, &b, &c, &d); for (int i = a; i <= 200; i++) for (int j = b; j < i; j++) for (int k = c; k < j; k++) { if (2 * a >= i && 2 * b >= j && 2 * c >= k && d <= i && d <= j && d <= k && 2 * d >= k && 2 * d < i && 2 * d < j) { printf("%d\n%d\n%d\n", i, j, k); return 0; } } puts("-1"); return 0; }
### Prompt Please formulate a cpp solution to the following problem: A family consisting of father bear, mother bear and son bear owns three cars. Father bear can climb into the largest car and he likes it. Also, mother bear can climb into the middle car and she likes it. Moreover, son bear can climb into the smallest car and he likes it. It's known that the largest car is strictly larger than the middle car, and the middle car is strictly larger than the smallest car. Masha came to test these cars. She could climb into all cars, but she liked only the smallest car. It's known that a character with size a can climb into some car with size b if and only if a ≀ b, he or she likes it if and only if he can climb into this car and 2a β‰₯ b. You are given sizes of bears and Masha. Find out some possible integer non-negative sizes of cars. Input You are given four integers V1, V2, V3, Vm(1 ≀ Vi ≀ 100) β€” sizes of father bear, mother bear, son bear and Masha, respectively. It's guaranteed that V1 > V2 > V3. Output Output three integers β€” sizes of father bear's car, mother bear's car and son bear's car, respectively. If there are multiple possible solutions, print any. If there is no solution, print "-1" (without quotes). Examples Input 50 30 10 10 Output 50 30 10 Input 100 50 10 21 Output -1 Note In first test case all conditions for cars' sizes are satisfied. In second test case there is no answer, because Masha should be able to climb into smallest car (so size of smallest car in not less than 21), but son bear should like it, so maximum possible size of it is 20. ### Response ```cpp #include <bits/stdc++.h> using namespace std; int a, b, c, d; int main() { scanf("%d%d%d%d", &a, &b, &c, &d); for (int i = a; i <= 200; i++) for (int j = b; j < i; j++) for (int k = c; k < j; k++) { if (2 * a >= i && 2 * b >= j && 2 * c >= k && d <= i && d <= j && d <= k && 2 * d >= k && 2 * d < i && 2 * d < j) { printf("%d\n%d\n%d\n", i, j, k); return 0; } } puts("-1"); return 0; } ```
#include <bits/stdc++.h> using namespace std; int main() { int a1, a2, a3, a4; cin >> a1 >> a2 >> a3 >> a4; int mnS = max(a4, a3); int mxS = min(a4, a3) * 2; int mnM = max(2 * a4 + 1, a2); int mxM = 2 * a2; int mnL = max(2 * a4 + 1, a1); int mxL = 2 * a1; if (mxM >= mnS + 1 && mxL >= mnM + 1 && mnS <= mxS && mnM <= mxM && mnL <= mxL) { cout << mxL << '\n' << mnM << '\n' << mnS; } else cout << -1; return 0; }
### Prompt In cpp, your task is to solve the following problem: A family consisting of father bear, mother bear and son bear owns three cars. Father bear can climb into the largest car and he likes it. Also, mother bear can climb into the middle car and she likes it. Moreover, son bear can climb into the smallest car and he likes it. It's known that the largest car is strictly larger than the middle car, and the middle car is strictly larger than the smallest car. Masha came to test these cars. She could climb into all cars, but she liked only the smallest car. It's known that a character with size a can climb into some car with size b if and only if a ≀ b, he or she likes it if and only if he can climb into this car and 2a β‰₯ b. You are given sizes of bears and Masha. Find out some possible integer non-negative sizes of cars. Input You are given four integers V1, V2, V3, Vm(1 ≀ Vi ≀ 100) β€” sizes of father bear, mother bear, son bear and Masha, respectively. It's guaranteed that V1 > V2 > V3. Output Output three integers β€” sizes of father bear's car, mother bear's car and son bear's car, respectively. If there are multiple possible solutions, print any. If there is no solution, print "-1" (without quotes). Examples Input 50 30 10 10 Output 50 30 10 Input 100 50 10 21 Output -1 Note In first test case all conditions for cars' sizes are satisfied. In second test case there is no answer, because Masha should be able to climb into smallest car (so size of smallest car in not less than 21), but son bear should like it, so maximum possible size of it is 20. ### Response ```cpp #include <bits/stdc++.h> using namespace std; int main() { int a1, a2, a3, a4; cin >> a1 >> a2 >> a3 >> a4; int mnS = max(a4, a3); int mxS = min(a4, a3) * 2; int mnM = max(2 * a4 + 1, a2); int mxM = 2 * a2; int mnL = max(2 * a4 + 1, a1); int mxL = 2 * a1; if (mxM >= mnS + 1 && mxL >= mnM + 1 && mnS <= mxS && mnM <= mxM && mnL <= mxL) { cout << mxL << '\n' << mnM << '\n' << mnS; } else cout << -1; return 0; } ```
#include <bits/stdc++.h> using namespace std; int main() { int v1, v2, v3, vm; cin >> v1 >> v2 >> v3 >> vm; int c1 = 0, c2 = 0, c3 = 0; bool pos = false; for (int i = max(2 * v2 + 1, v1); i <= 2 * v1; i++) { for (int j = max(2 * v3 + 1, v2); j <= 2 * v2; j++) { for (int k = v3; k <= 2 * v3; k++) { if (i > 2 * vm && j > 2 * vm && k <= 2 * vm && k >= vm) { pos = true; c1 = i; c2 = j; c3 = k; break; } } if (pos) break; } if (pos) break; } if (pos) { cout << c1 << " " << c2 << " " << c3 << endl; } else { cout << -1 << endl; } return 0; }
### Prompt Please provide a cpp coded solution to the problem described below: A family consisting of father bear, mother bear and son bear owns three cars. Father bear can climb into the largest car and he likes it. Also, mother bear can climb into the middle car and she likes it. Moreover, son bear can climb into the smallest car and he likes it. It's known that the largest car is strictly larger than the middle car, and the middle car is strictly larger than the smallest car. Masha came to test these cars. She could climb into all cars, but she liked only the smallest car. It's known that a character with size a can climb into some car with size b if and only if a ≀ b, he or she likes it if and only if he can climb into this car and 2a β‰₯ b. You are given sizes of bears and Masha. Find out some possible integer non-negative sizes of cars. Input You are given four integers V1, V2, V3, Vm(1 ≀ Vi ≀ 100) β€” sizes of father bear, mother bear, son bear and Masha, respectively. It's guaranteed that V1 > V2 > V3. Output Output three integers β€” sizes of father bear's car, mother bear's car and son bear's car, respectively. If there are multiple possible solutions, print any. If there is no solution, print "-1" (without quotes). Examples Input 50 30 10 10 Output 50 30 10 Input 100 50 10 21 Output -1 Note In first test case all conditions for cars' sizes are satisfied. In second test case there is no answer, because Masha should be able to climb into smallest car (so size of smallest car in not less than 21), but son bear should like it, so maximum possible size of it is 20. ### Response ```cpp #include <bits/stdc++.h> using namespace std; int main() { int v1, v2, v3, vm; cin >> v1 >> v2 >> v3 >> vm; int c1 = 0, c2 = 0, c3 = 0; bool pos = false; for (int i = max(2 * v2 + 1, v1); i <= 2 * v1; i++) { for (int j = max(2 * v3 + 1, v2); j <= 2 * v2; j++) { for (int k = v3; k <= 2 * v3; k++) { if (i > 2 * vm && j > 2 * vm && k <= 2 * vm && k >= vm) { pos = true; c1 = i; c2 = j; c3 = k; break; } } if (pos) break; } if (pos) break; } if (pos) { cout << c1 << " " << c2 << " " << c3 << endl; } else { cout << -1 << endl; } return 0; } ```
#include <bits/stdc++.h> using namespace std; vector<int> v[1000010]; vector<pair<int, int> > w; int main() { int a, b, c, d; scanf("%d%d%d%d", &a, &b, &c, &d); for (int i = c; i <= 2 * c; i++) { for (int j = b; j <= 2 * b; j++) { for (int k = a; k <= 2 * a; k++) { if (k > i && k > j && j > i && k >= d && j >= d && i >= d && 2 * d < k && 2 * d < j && 2 * d >= i) { printf("%d\n", k); printf("%d\n", j); printf("%d\n", i); return 0; } } } } printf("-1\n"); }
### Prompt Create a solution in cpp for the following problem: A family consisting of father bear, mother bear and son bear owns three cars. Father bear can climb into the largest car and he likes it. Also, mother bear can climb into the middle car and she likes it. Moreover, son bear can climb into the smallest car and he likes it. It's known that the largest car is strictly larger than the middle car, and the middle car is strictly larger than the smallest car. Masha came to test these cars. She could climb into all cars, but she liked only the smallest car. It's known that a character with size a can climb into some car with size b if and only if a ≀ b, he or she likes it if and only if he can climb into this car and 2a β‰₯ b. You are given sizes of bears and Masha. Find out some possible integer non-negative sizes of cars. Input You are given four integers V1, V2, V3, Vm(1 ≀ Vi ≀ 100) β€” sizes of father bear, mother bear, son bear and Masha, respectively. It's guaranteed that V1 > V2 > V3. Output Output three integers β€” sizes of father bear's car, mother bear's car and son bear's car, respectively. If there are multiple possible solutions, print any. If there is no solution, print "-1" (without quotes). Examples Input 50 30 10 10 Output 50 30 10 Input 100 50 10 21 Output -1 Note In first test case all conditions for cars' sizes are satisfied. In second test case there is no answer, because Masha should be able to climb into smallest car (so size of smallest car in not less than 21), but son bear should like it, so maximum possible size of it is 20. ### Response ```cpp #include <bits/stdc++.h> using namespace std; vector<int> v[1000010]; vector<pair<int, int> > w; int main() { int a, b, c, d; scanf("%d%d%d%d", &a, &b, &c, &d); for (int i = c; i <= 2 * c; i++) { for (int j = b; j <= 2 * b; j++) { for (int k = a; k <= 2 * a; k++) { if (k > i && k > j && j > i && k >= d && j >= d && i >= d && 2 * d < k && 2 * d < j && 2 * d >= i) { printf("%d\n", k); printf("%d\n", j); printf("%d\n", i); return 0; } } } } printf("-1\n"); } ```
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:1024000000,1024000000") using namespace std; int main() { long long a, b, c, d; cin >> a >> b >> c >> d; if (2 * c < d || d >= b || c > 2 * d) { cout << "-1" << endl; } else { cout << a * 2 << endl << b * 2 << endl << max(c, d) << endl; } return 0; }
### Prompt In CPP, your task is to solve the following problem: A family consisting of father bear, mother bear and son bear owns three cars. Father bear can climb into the largest car and he likes it. Also, mother bear can climb into the middle car and she likes it. Moreover, son bear can climb into the smallest car and he likes it. It's known that the largest car is strictly larger than the middle car, and the middle car is strictly larger than the smallest car. Masha came to test these cars. She could climb into all cars, but she liked only the smallest car. It's known that a character with size a can climb into some car with size b if and only if a ≀ b, he or she likes it if and only if he can climb into this car and 2a β‰₯ b. You are given sizes of bears and Masha. Find out some possible integer non-negative sizes of cars. Input You are given four integers V1, V2, V3, Vm(1 ≀ Vi ≀ 100) β€” sizes of father bear, mother bear, son bear and Masha, respectively. It's guaranteed that V1 > V2 > V3. Output Output three integers β€” sizes of father bear's car, mother bear's car and son bear's car, respectively. If there are multiple possible solutions, print any. If there is no solution, print "-1" (without quotes). Examples Input 50 30 10 10 Output 50 30 10 Input 100 50 10 21 Output -1 Note In first test case all conditions for cars' sizes are satisfied. In second test case there is no answer, because Masha should be able to climb into smallest car (so size of smallest car in not less than 21), but son bear should like it, so maximum possible size of it is 20. ### Response ```cpp #include <bits/stdc++.h> #pragma comment(linker, "/STACK:1024000000,1024000000") using namespace std; int main() { long long a, b, c, d; cin >> a >> b >> c >> d; if (2 * c < d || d >= b || c > 2 * d) { cout << "-1" << endl; } else { cout << a * 2 << endl << b * 2 << endl << max(c, d) << endl; } return 0; } ```
#include <bits/stdc++.h> using namespace std; string s, s1; long long int n, m, a, b, i, j, t, c = 0, counT = 0, k, l = 0, temp = 0, sum = 0, Max, Min, num, a1, b1, c1; long long int arr[10000000]; vector<long long int> vc; map<long long int, long long int> mp; int main() { cin >> a >> b >> c >> m; a1 = a * 2; b1 = b * 2; c1 = c * 2; if (2 * m >= a1 or 2 * m >= b1 or c1 < m) cout << -1 << '\n'; else { if (2 * m < c1) { if (2 * m < c) return cout << -1 << '\n', 0; else cout << a1 << '\n' << b1 << '\n' << max(c, m) << '\n'; } else cout << a1 << '\n' << b1 << '\n' << max(c, m) << '\n'; } }
### Prompt Generate a CPP solution to the following problem: A family consisting of father bear, mother bear and son bear owns three cars. Father bear can climb into the largest car and he likes it. Also, mother bear can climb into the middle car and she likes it. Moreover, son bear can climb into the smallest car and he likes it. It's known that the largest car is strictly larger than the middle car, and the middle car is strictly larger than the smallest car. Masha came to test these cars. She could climb into all cars, but she liked only the smallest car. It's known that a character with size a can climb into some car with size b if and only if a ≀ b, he or she likes it if and only if he can climb into this car and 2a β‰₯ b. You are given sizes of bears and Masha. Find out some possible integer non-negative sizes of cars. Input You are given four integers V1, V2, V3, Vm(1 ≀ Vi ≀ 100) β€” sizes of father bear, mother bear, son bear and Masha, respectively. It's guaranteed that V1 > V2 > V3. Output Output three integers β€” sizes of father bear's car, mother bear's car and son bear's car, respectively. If there are multiple possible solutions, print any. If there is no solution, print "-1" (without quotes). Examples Input 50 30 10 10 Output 50 30 10 Input 100 50 10 21 Output -1 Note In first test case all conditions for cars' sizes are satisfied. In second test case there is no answer, because Masha should be able to climb into smallest car (so size of smallest car in not less than 21), but son bear should like it, so maximum possible size of it is 20. ### Response ```cpp #include <bits/stdc++.h> using namespace std; string s, s1; long long int n, m, a, b, i, j, t, c = 0, counT = 0, k, l = 0, temp = 0, sum = 0, Max, Min, num, a1, b1, c1; long long int arr[10000000]; vector<long long int> vc; map<long long int, long long int> mp; int main() { cin >> a >> b >> c >> m; a1 = a * 2; b1 = b * 2; c1 = c * 2; if (2 * m >= a1 or 2 * m >= b1 or c1 < m) cout << -1 << '\n'; else { if (2 * m < c1) { if (2 * m < c) return cout << -1 << '\n', 0; else cout << a1 << '\n' << b1 << '\n' << max(c, m) << '\n'; } else cout << a1 << '\n' << b1 << '\n' << max(c, m) << '\n'; } } ```
#include <bits/stdc++.h> using namespace std; int main() { int a[4]; for (int i = 0; i < 4; ++i) cin >> a[i]; if (a[3] < a[0] && a[3] < a[1]) { int m = max(a[2], a[3]); int s = min(a[2], a[3]); if (s * 2 >= m) { cout << a[0] * 2 << endl; cout << a[1] * 2 << endl; cout << m << endl; } else { cout << -1 << endl; } } else { cout << -1 << endl; } return 0; }
### Prompt Create a solution in Cpp for the following problem: A family consisting of father bear, mother bear and son bear owns three cars. Father bear can climb into the largest car and he likes it. Also, mother bear can climb into the middle car and she likes it. Moreover, son bear can climb into the smallest car and he likes it. It's known that the largest car is strictly larger than the middle car, and the middle car is strictly larger than the smallest car. Masha came to test these cars. She could climb into all cars, but she liked only the smallest car. It's known that a character with size a can climb into some car with size b if and only if a ≀ b, he or she likes it if and only if he can climb into this car and 2a β‰₯ b. You are given sizes of bears and Masha. Find out some possible integer non-negative sizes of cars. Input You are given four integers V1, V2, V3, Vm(1 ≀ Vi ≀ 100) β€” sizes of father bear, mother bear, son bear and Masha, respectively. It's guaranteed that V1 > V2 > V3. Output Output three integers β€” sizes of father bear's car, mother bear's car and son bear's car, respectively. If there are multiple possible solutions, print any. If there is no solution, print "-1" (without quotes). Examples Input 50 30 10 10 Output 50 30 10 Input 100 50 10 21 Output -1 Note In first test case all conditions for cars' sizes are satisfied. In second test case there is no answer, because Masha should be able to climb into smallest car (so size of smallest car in not less than 21), but son bear should like it, so maximum possible size of it is 20. ### Response ```cpp #include <bits/stdc++.h> using namespace std; int main() { int a[4]; for (int i = 0; i < 4; ++i) cin >> a[i]; if (a[3] < a[0] && a[3] < a[1]) { int m = max(a[2], a[3]); int s = min(a[2], a[3]); if (s * 2 >= m) { cout << a[0] * 2 << endl; cout << a[1] * 2 << endl; cout << m << endl; } else { cout << -1 << endl; } } else { cout << -1 << endl; } return 0; } ```
#include <bits/stdc++.h> int main() { int v[4]; scanf("%d %d %d %d", &v[0], &v[1], &v[2], &v[3]); if (v[3] > 2 * v[2] || 2 * v[3] < v[2] || v[3] >= v[1]) printf("%d", -1); else { if (2 * v[3] + 1 >= v[1]) v[1] = 2 * v[3] + 1; if (2 * v[3] + 2 >= v[0]) v[0] = 2 * v[3] + 2; if (v[3] >= v[2] && v[3] <= 2 * v[2]) v[2] = v[3]; else v[2] = 2 * v[3]; printf("%d\n%d\n%d", v[0], v[1], v[2]); } return 0; }
### Prompt In Cpp, your task is to solve the following problem: A family consisting of father bear, mother bear and son bear owns three cars. Father bear can climb into the largest car and he likes it. Also, mother bear can climb into the middle car and she likes it. Moreover, son bear can climb into the smallest car and he likes it. It's known that the largest car is strictly larger than the middle car, and the middle car is strictly larger than the smallest car. Masha came to test these cars. She could climb into all cars, but she liked only the smallest car. It's known that a character with size a can climb into some car with size b if and only if a ≀ b, he or she likes it if and only if he can climb into this car and 2a β‰₯ b. You are given sizes of bears and Masha. Find out some possible integer non-negative sizes of cars. Input You are given four integers V1, V2, V3, Vm(1 ≀ Vi ≀ 100) β€” sizes of father bear, mother bear, son bear and Masha, respectively. It's guaranteed that V1 > V2 > V3. Output Output three integers β€” sizes of father bear's car, mother bear's car and son bear's car, respectively. If there are multiple possible solutions, print any. If there is no solution, print "-1" (without quotes). Examples Input 50 30 10 10 Output 50 30 10 Input 100 50 10 21 Output -1 Note In first test case all conditions for cars' sizes are satisfied. In second test case there is no answer, because Masha should be able to climb into smallest car (so size of smallest car in not less than 21), but son bear should like it, so maximum possible size of it is 20. ### Response ```cpp #include <bits/stdc++.h> int main() { int v[4]; scanf("%d %d %d %d", &v[0], &v[1], &v[2], &v[3]); if (v[3] > 2 * v[2] || 2 * v[3] < v[2] || v[3] >= v[1]) printf("%d", -1); else { if (2 * v[3] + 1 >= v[1]) v[1] = 2 * v[3] + 1; if (2 * v[3] + 2 >= v[0]) v[0] = 2 * v[3] + 2; if (v[3] >= v[2] && v[3] <= 2 * v[2]) v[2] = v[3]; else v[2] = 2 * v[3]; printf("%d\n%d\n%d", v[0], v[1], v[2]); } return 0; } ```
#include <bits/stdc++.h> using namespace std; bool cmpf(float a, float b, float epsilon) { return (fabs(a - b) <= epsilon * max(fabs(a), fabs(b))); } long long int fpow(long long int n, long long int k, long long int p) { long long int r = 1; for (; k; k >>= 1) { if (k & 1) r = r * n % p; n = n * n % p; } return r; } long long int inv(long long int a, long long int p) { return fpow(a, p - 2, p); } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long int t, n, m, k, d, di, ti, si, cnt, temp, i, j; long long int v1, v2, v3, vm; cin >> v1 >> v2 >> v3 >> vm; bool tevmp = 0; for (i = v1; i < 2 * v1 + 1; i++) { for (j = v2; j < 2 * v2 + 1; j++) { for (k = v3; k < 2 * v3 + 1; k++) { if (i > j and j > k and i > k and vm <= i and vm <= j and vm <= k and 2 * vm >= k and 2 * vm < j and 2 * vm < i) { tevmp = 1; break; } } if (tevmp) break; } if (tevmp) break; } if (tevmp) cout << i << endl << j << endl << k; else cout << "-1"; return 0; }
### Prompt Create a solution in Cpp for the following problem: A family consisting of father bear, mother bear and son bear owns three cars. Father bear can climb into the largest car and he likes it. Also, mother bear can climb into the middle car and she likes it. Moreover, son bear can climb into the smallest car and he likes it. It's known that the largest car is strictly larger than the middle car, and the middle car is strictly larger than the smallest car. Masha came to test these cars. She could climb into all cars, but she liked only the smallest car. It's known that a character with size a can climb into some car with size b if and only if a ≀ b, he or she likes it if and only if he can climb into this car and 2a β‰₯ b. You are given sizes of bears and Masha. Find out some possible integer non-negative sizes of cars. Input You are given four integers V1, V2, V3, Vm(1 ≀ Vi ≀ 100) β€” sizes of father bear, mother bear, son bear and Masha, respectively. It's guaranteed that V1 > V2 > V3. Output Output three integers β€” sizes of father bear's car, mother bear's car and son bear's car, respectively. If there are multiple possible solutions, print any. If there is no solution, print "-1" (without quotes). Examples Input 50 30 10 10 Output 50 30 10 Input 100 50 10 21 Output -1 Note In first test case all conditions for cars' sizes are satisfied. In second test case there is no answer, because Masha should be able to climb into smallest car (so size of smallest car in not less than 21), but son bear should like it, so maximum possible size of it is 20. ### Response ```cpp #include <bits/stdc++.h> using namespace std; bool cmpf(float a, float b, float epsilon) { return (fabs(a - b) <= epsilon * max(fabs(a), fabs(b))); } long long int fpow(long long int n, long long int k, long long int p) { long long int r = 1; for (; k; k >>= 1) { if (k & 1) r = r * n % p; n = n * n % p; } return r; } long long int inv(long long int a, long long int p) { return fpow(a, p - 2, p); } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long int t, n, m, k, d, di, ti, si, cnt, temp, i, j; long long int v1, v2, v3, vm; cin >> v1 >> v2 >> v3 >> vm; bool tevmp = 0; for (i = v1; i < 2 * v1 + 1; i++) { for (j = v2; j < 2 * v2 + 1; j++) { for (k = v3; k < 2 * v3 + 1; k++) { if (i > j and j > k and i > k and vm <= i and vm <= j and vm <= k and 2 * vm >= k and 2 * vm < j and 2 * vm < i) { tevmp = 1; break; } } if (tevmp) break; } if (tevmp) break; } if (tevmp) cout << i << endl << j << endl << k; else cout << "-1"; return 0; } ```
#include <bits/stdc++.h> using namespace std; int main() { int mother, father, little, masha; cin >> father >> mother >> little >> masha; if (masha > 2 * little) cout << -1 << "\n"; else if (2 * masha < little) cout << -1 << "\n"; else if (masha >= mother) cout << -1 << "\n"; else if (masha >= little) cout << father * 2 << "\n" << mother * 2 << "\n" << masha; else cout << father * 2 << "\n" << mother * 2 << "\n" << little; return 0; }
### Prompt Construct a Cpp code solution to the problem outlined: A family consisting of father bear, mother bear and son bear owns three cars. Father bear can climb into the largest car and he likes it. Also, mother bear can climb into the middle car and she likes it. Moreover, son bear can climb into the smallest car and he likes it. It's known that the largest car is strictly larger than the middle car, and the middle car is strictly larger than the smallest car. Masha came to test these cars. She could climb into all cars, but she liked only the smallest car. It's known that a character with size a can climb into some car with size b if and only if a ≀ b, he or she likes it if and only if he can climb into this car and 2a β‰₯ b. You are given sizes of bears and Masha. Find out some possible integer non-negative sizes of cars. Input You are given four integers V1, V2, V3, Vm(1 ≀ Vi ≀ 100) β€” sizes of father bear, mother bear, son bear and Masha, respectively. It's guaranteed that V1 > V2 > V3. Output Output three integers β€” sizes of father bear's car, mother bear's car and son bear's car, respectively. If there are multiple possible solutions, print any. If there is no solution, print "-1" (without quotes). Examples Input 50 30 10 10 Output 50 30 10 Input 100 50 10 21 Output -1 Note In first test case all conditions for cars' sizes are satisfied. In second test case there is no answer, because Masha should be able to climb into smallest car (so size of smallest car in not less than 21), but son bear should like it, so maximum possible size of it is 20. ### Response ```cpp #include <bits/stdc++.h> using namespace std; int main() { int mother, father, little, masha; cin >> father >> mother >> little >> masha; if (masha > 2 * little) cout << -1 << "\n"; else if (2 * masha < little) cout << -1 << "\n"; else if (masha >= mother) cout << -1 << "\n"; else if (masha >= little) cout << father * 2 << "\n" << mother * 2 << "\n" << masha; else cout << father * 2 << "\n" << mother * 2 << "\n" << little; return 0; } ```
#include <bits/stdc++.h> using namespace std; int dy[] = {0, 0, 1, -1}; int dx[] = {1, -1, 0, 0}; int a, b, c, d; int main() { scanf("%d%d%d%d", &a, &b, &c, &d); for (int n = a; n <= a * 2; n++) { for (int m = b; m <= b * 2; m++) { for (int k = c; k <= c * 2; k++) { if (n > m && m > k) { if (d <= k && d <= m && d <= n && 2 * d >= k && 2 * d < m && 2 * d < n) { printf("%d\n%d\n%d\n", n, m, k); return 0; } } } } } printf("-1\n"); return 0; }
### Prompt Please formulate a Cpp solution to the following problem: A family consisting of father bear, mother bear and son bear owns three cars. Father bear can climb into the largest car and he likes it. Also, mother bear can climb into the middle car and she likes it. Moreover, son bear can climb into the smallest car and he likes it. It's known that the largest car is strictly larger than the middle car, and the middle car is strictly larger than the smallest car. Masha came to test these cars. She could climb into all cars, but she liked only the smallest car. It's known that a character with size a can climb into some car with size b if and only if a ≀ b, he or she likes it if and only if he can climb into this car and 2a β‰₯ b. You are given sizes of bears and Masha. Find out some possible integer non-negative sizes of cars. Input You are given four integers V1, V2, V3, Vm(1 ≀ Vi ≀ 100) β€” sizes of father bear, mother bear, son bear and Masha, respectively. It's guaranteed that V1 > V2 > V3. Output Output three integers β€” sizes of father bear's car, mother bear's car and son bear's car, respectively. If there are multiple possible solutions, print any. If there is no solution, print "-1" (without quotes). Examples Input 50 30 10 10 Output 50 30 10 Input 100 50 10 21 Output -1 Note In first test case all conditions for cars' sizes are satisfied. In second test case there is no answer, because Masha should be able to climb into smallest car (so size of smallest car in not less than 21), but son bear should like it, so maximum possible size of it is 20. ### Response ```cpp #include <bits/stdc++.h> using namespace std; int dy[] = {0, 0, 1, -1}; int dx[] = {1, -1, 0, 0}; int a, b, c, d; int main() { scanf("%d%d%d%d", &a, &b, &c, &d); for (int n = a; n <= a * 2; n++) { for (int m = b; m <= b * 2; m++) { for (int k = c; k <= c * 2; k++) { if (n > m && m > k) { if (d <= k && d <= m && d <= n && 2 * d >= k && 2 * d < m && 2 * d < n) { printf("%d\n%d\n%d\n", n, m, k); return 0; } } } } } printf("-1\n"); return 0; } ```
#include <bits/stdc++.h> using namespace std; const int MAXN = int(1e5) + 10; const int MOD = int(1e9) + 7; const int oo = INT_MAX; int v[4], ans[3]; int main() { while (scanf("%d%d%d%d", &v[0], &v[1], &v[2], &v[3]) == 4) { memset(ans, -1, sizeof(ans)); for (int i = v[0]; i <= v[0] * 2; ++i) { for (int j = v[1]; j <= v[1] * 2; ++j) { for (int k = v[2]; k <= v[2] * 2; ++k) { if (i > j && j > k && v[3] <= k && 2 * v[3] >= k && 2 * v[3] < j && 2 * v[3] < i) { ans[0] = i; ans[1] = j; ans[2] = k; } } } } if (ans[0] != -1) { for (int i = 0; i < 3; ++i) { printf("%d\n", ans[i]); } } else { puts("-1"); } } return 0; }
### Prompt Generate a Cpp solution to the following problem: A family consisting of father bear, mother bear and son bear owns three cars. Father bear can climb into the largest car and he likes it. Also, mother bear can climb into the middle car and she likes it. Moreover, son bear can climb into the smallest car and he likes it. It's known that the largest car is strictly larger than the middle car, and the middle car is strictly larger than the smallest car. Masha came to test these cars. She could climb into all cars, but she liked only the smallest car. It's known that a character with size a can climb into some car with size b if and only if a ≀ b, he or she likes it if and only if he can climb into this car and 2a β‰₯ b. You are given sizes of bears and Masha. Find out some possible integer non-negative sizes of cars. Input You are given four integers V1, V2, V3, Vm(1 ≀ Vi ≀ 100) β€” sizes of father bear, mother bear, son bear and Masha, respectively. It's guaranteed that V1 > V2 > V3. Output Output three integers β€” sizes of father bear's car, mother bear's car and son bear's car, respectively. If there are multiple possible solutions, print any. If there is no solution, print "-1" (without quotes). Examples Input 50 30 10 10 Output 50 30 10 Input 100 50 10 21 Output -1 Note In first test case all conditions for cars' sizes are satisfied. In second test case there is no answer, because Masha should be able to climb into smallest car (so size of smallest car in not less than 21), but son bear should like it, so maximum possible size of it is 20. ### Response ```cpp #include <bits/stdc++.h> using namespace std; const int MAXN = int(1e5) + 10; const int MOD = int(1e9) + 7; const int oo = INT_MAX; int v[4], ans[3]; int main() { while (scanf("%d%d%d%d", &v[0], &v[1], &v[2], &v[3]) == 4) { memset(ans, -1, sizeof(ans)); for (int i = v[0]; i <= v[0] * 2; ++i) { for (int j = v[1]; j <= v[1] * 2; ++j) { for (int k = v[2]; k <= v[2] * 2; ++k) { if (i > j && j > k && v[3] <= k && 2 * v[3] >= k && 2 * v[3] < j && 2 * v[3] < i) { ans[0] = i; ans[1] = j; ans[2] = k; } } } } if (ans[0] != -1) { for (int i = 0; i < 3; ++i) { printf("%d\n", ans[i]); } } else { puts("-1"); } } return 0; } ```
#include <bits/stdc++.h> using namespace std; int main() { int v1, v2, v3, vm, k1 = 0, k2 = 0, k3 = 0; cin >> v1 >> v2 >> v3 >> vm; for (int i = max(v3, vm); i <= 2 * v3 && i <= 2 * vm; ++i) if (i >= v3 && i >= vm) { k3 = i; break; } if (k3 == 0) { cout << "-1"; return 0; } for (int i = 2 * vm + 1; i <= 2 * v2; ++i) if (i >= v2 && i > k3) { k2 = i; break; } if (k2 == 0) { cout << "-1"; return 0; } for (int i = 2 * vm + 1; i <= 2 * v1; ++i) if (i >= v1 && i > k2) { k1 = i; break; } if (k1 == 0) { cout << "-1"; return 0; } cout << k1 << '\n' << k2 << '\n' << k3; }
### Prompt Please provide a Cpp coded solution to the problem described below: A family consisting of father bear, mother bear and son bear owns three cars. Father bear can climb into the largest car and he likes it. Also, mother bear can climb into the middle car and she likes it. Moreover, son bear can climb into the smallest car and he likes it. It's known that the largest car is strictly larger than the middle car, and the middle car is strictly larger than the smallest car. Masha came to test these cars. She could climb into all cars, but she liked only the smallest car. It's known that a character with size a can climb into some car with size b if and only if a ≀ b, he or she likes it if and only if he can climb into this car and 2a β‰₯ b. You are given sizes of bears and Masha. Find out some possible integer non-negative sizes of cars. Input You are given four integers V1, V2, V3, Vm(1 ≀ Vi ≀ 100) β€” sizes of father bear, mother bear, son bear and Masha, respectively. It's guaranteed that V1 > V2 > V3. Output Output three integers β€” sizes of father bear's car, mother bear's car and son bear's car, respectively. If there are multiple possible solutions, print any. If there is no solution, print "-1" (without quotes). Examples Input 50 30 10 10 Output 50 30 10 Input 100 50 10 21 Output -1 Note In first test case all conditions for cars' sizes are satisfied. In second test case there is no answer, because Masha should be able to climb into smallest car (so size of smallest car in not less than 21), but son bear should like it, so maximum possible size of it is 20. ### Response ```cpp #include <bits/stdc++.h> using namespace std; int main() { int v1, v2, v3, vm, k1 = 0, k2 = 0, k3 = 0; cin >> v1 >> v2 >> v3 >> vm; for (int i = max(v3, vm); i <= 2 * v3 && i <= 2 * vm; ++i) if (i >= v3 && i >= vm) { k3 = i; break; } if (k3 == 0) { cout << "-1"; return 0; } for (int i = 2 * vm + 1; i <= 2 * v2; ++i) if (i >= v2 && i > k3) { k2 = i; break; } if (k2 == 0) { cout << "-1"; return 0; } for (int i = 2 * vm + 1; i <= 2 * v1; ++i) if (i >= v1 && i > k2) { k1 = i; break; } if (k1 == 0) { cout << "-1"; return 0; } cout << k1 << '\n' << k2 << '\n' << k3; } ```
#include <bits/stdc++.h> using namespace std; long long int MOD = 998244353; long long int mod = 1e9 + 7; long long int INF = 1e18; long long int dx[] = {1, -1, 0, 0}; long long int dy[] = {0, 0, 1, -1}; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long int a, b, c, d; cin >> a >> b >> c >> d; for (int i = a; i <= 2 * a; i++) { for (int j = b; j <= 2 * b; j++) { for (int k = c; k <= 2 * c; k++) { if (!(i > j && j > k)) continue; if (i < d) continue; if (j < d) continue; if (k < d) continue; if (i <= 2 * d) continue; if (j <= 2 * d) continue; if (k > 2 * d) continue; else { cout << i << endl << j << endl << k << endl; return 0; } } } } cout << -1; return 0; }
### Prompt Your task is to create a CPP solution to the following problem: A family consisting of father bear, mother bear and son bear owns three cars. Father bear can climb into the largest car and he likes it. Also, mother bear can climb into the middle car and she likes it. Moreover, son bear can climb into the smallest car and he likes it. It's known that the largest car is strictly larger than the middle car, and the middle car is strictly larger than the smallest car. Masha came to test these cars. She could climb into all cars, but she liked only the smallest car. It's known that a character with size a can climb into some car with size b if and only if a ≀ b, he or she likes it if and only if he can climb into this car and 2a β‰₯ b. You are given sizes of bears and Masha. Find out some possible integer non-negative sizes of cars. Input You are given four integers V1, V2, V3, Vm(1 ≀ Vi ≀ 100) β€” sizes of father bear, mother bear, son bear and Masha, respectively. It's guaranteed that V1 > V2 > V3. Output Output three integers β€” sizes of father bear's car, mother bear's car and son bear's car, respectively. If there are multiple possible solutions, print any. If there is no solution, print "-1" (without quotes). Examples Input 50 30 10 10 Output 50 30 10 Input 100 50 10 21 Output -1 Note In first test case all conditions for cars' sizes are satisfied. In second test case there is no answer, because Masha should be able to climb into smallest car (so size of smallest car in not less than 21), but son bear should like it, so maximum possible size of it is 20. ### Response ```cpp #include <bits/stdc++.h> using namespace std; long long int MOD = 998244353; long long int mod = 1e9 + 7; long long int INF = 1e18; long long int dx[] = {1, -1, 0, 0}; long long int dy[] = {0, 0, 1, -1}; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long int a, b, c, d; cin >> a >> b >> c >> d; for (int i = a; i <= 2 * a; i++) { for (int j = b; j <= 2 * b; j++) { for (int k = c; k <= 2 * c; k++) { if (!(i > j && j > k)) continue; if (i < d) continue; if (j < d) continue; if (k < d) continue; if (i <= 2 * d) continue; if (j <= 2 * d) continue; if (k > 2 * d) continue; else { cout << i << endl << j << endl << k << endl; return 0; } } } } cout << -1; return 0; } ```