Search is not available for this dataset
name
stringlengths
2
112
description
stringlengths
29
13k
source
int64
1
7
difficulty
int64
0
25
solution
stringlengths
7
983k
language
stringclasses
4 values
802_H. Fake News (medium)
Thanks to your help, Heidi is confident that no one can fool her. She has now decided to post some fake news on the HC2 Facebook page. However, she wants to be able to communicate to the HC2 committee that the post is fake, using some secret phrase hidden in the post as a subsequence. To make this method foolproof, she wants the phrase to appear n times in the post. She is asking you to design a post (string) s and a hidden phrase p such that p appears in s as a subsequence exactly n times. Input The first and only line of input contains a single integer n (1 ≤ n ≤ 1 000 000). Output The output should contain two nonempty strings s and p separated by a single space. Each string should be composed of letters (a-z and A-Z: both lowercase and uppercase are allowed) and have length at most 200. The number of occurrences of p in s as a subsequence should be exactly n. If there are many possible solutions, output any of them. It is guaranteed that at least one solution exists. Examples Input 2 Output hHheidi Hei Input 4 Output bbbba ba Input 6 Output aaabb ab Note An occurrence of p as a subsequence in s should be thought of as a set of positions in s such that the letters at these positions, in order, form p. The number of occurences is thus the number of such sets. For example, ab appears 6 times as a subsequence in aaabb, for the following sets of positions: {1, 4}, {1, 5}, {2, 4}, {2, 5}, {3, 4}, {3, 5} (that is, we should choose one of the a's and one of the b's).
2
14
def solve(k): if k == 1: return ('a', 'a') if k == 2: return ('aa', 'a') s, p = solve((k-1) // 2) x = chr(ord(p[-1])+1) return (p+x*(2-k%2)+s[len(p):]+x*2, p+x) s, p = solve(int(input())) print(s, p)
PYTHON3
802_H. Fake News (medium)
Thanks to your help, Heidi is confident that no one can fool her. She has now decided to post some fake news on the HC2 Facebook page. However, she wants to be able to communicate to the HC2 committee that the post is fake, using some secret phrase hidden in the post as a subsequence. To make this method foolproof, she wants the phrase to appear n times in the post. She is asking you to design a post (string) s and a hidden phrase p such that p appears in s as a subsequence exactly n times. Input The first and only line of input contains a single integer n (1 ≤ n ≤ 1 000 000). Output The output should contain two nonempty strings s and p separated by a single space. Each string should be composed of letters (a-z and A-Z: both lowercase and uppercase are allowed) and have length at most 200. The number of occurrences of p in s as a subsequence should be exactly n. If there are many possible solutions, output any of them. It is guaranteed that at least one solution exists. Examples Input 2 Output hHheidi Hei Input 4 Output bbbba ba Input 6 Output aaabb ab Note An occurrence of p as a subsequence in s should be thought of as a set of positions in s such that the letters at these positions, in order, form p. The number of occurences is thus the number of such sets. For example, ab appears 6 times as a subsequence in aaabb, for the following sets of positions: {1, 4}, {1, 5}, {2, 4}, {2, 5}, {3, 4}, {3, 5} (that is, we should choose one of the a's and one of the b's).
2
14
#include <bits/stdc++.h> using namespace std; long long int div_floor(const long long int &a, const long long int &b) { return a / b - (((a ^ b) < 0) and a % b); } long long int div_ceil(const long long int &a, const long long int &b) { return a / b + (((a ^ b) >= 0) and a % b); } string c = "b"; pair<string, string> sp(int n) { if (n == 1) { pair<string, string> ans = {"a", ""}; return ans; } else if (n == 2) { pair<string, string> ans = {"ab", "b"}; c = "c"; return ans; } else if (n % 2) { pair<string, string> ans = sp(n / 2); ans.first += c; ans.second = ans.second + c + c; c[0]++; return ans; } else { pair<string, string> ans = sp(n / 2 - 1); ans.first += c; ans.second = c + ans.second + c + c; c[0]++; return ans; } } void solve() { int n; cin >> n; auto output = sp(n); cout << output.first + output.second << " " << output.first << '\n'; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int t = 1; while (t--) solve(); }
CPP
802_H. Fake News (medium)
Thanks to your help, Heidi is confident that no one can fool her. She has now decided to post some fake news on the HC2 Facebook page. However, she wants to be able to communicate to the HC2 committee that the post is fake, using some secret phrase hidden in the post as a subsequence. To make this method foolproof, she wants the phrase to appear n times in the post. She is asking you to design a post (string) s and a hidden phrase p such that p appears in s as a subsequence exactly n times. Input The first and only line of input contains a single integer n (1 ≤ n ≤ 1 000 000). Output The output should contain two nonempty strings s and p separated by a single space. Each string should be composed of letters (a-z and A-Z: both lowercase and uppercase are allowed) and have length at most 200. The number of occurrences of p in s as a subsequence should be exactly n. If there are many possible solutions, output any of them. It is guaranteed that at least one solution exists. Examples Input 2 Output hHheidi Hei Input 4 Output bbbba ba Input 6 Output aaabb ab Note An occurrence of p as a subsequence in s should be thought of as a set of positions in s such that the letters at these positions, in order, form p. The number of occurences is thus the number of such sets. For example, ab appears 6 times as a subsequence in aaabb, for the following sets of positions: {1, 4}, {1, 5}, {2, 4}, {2, 5}, {3, 4}, {3, 5} (that is, we should choose one of the a's and one of the b's).
2
14
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const long long INFF = 0x3f3f3f3f3f3f3f3fll; const long long M = 1e9 + 7; const long long maxn = 3e6 + 7; const double eps = 0.00000001; long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; } template <typename T> inline T abs(T a) { return a > 0 ? a : -a; } char a[] = "abdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; string s1, s2; int tot; int i, n, m; int main() { scanf("%d", &n); tot = 0; while (--n) { if (n & 1) { s1 = s1 + a[tot]; tot++; } else { s1 = s1 + a[tot] + a[tot]; tot++; n = n / 2; } } for (i = 0; i < tot + 1; i++) s2 += a[i]; cout << s1 + s2 << ' ' << s2; }
CPP
802_H. Fake News (medium)
Thanks to your help, Heidi is confident that no one can fool her. She has now decided to post some fake news on the HC2 Facebook page. However, she wants to be able to communicate to the HC2 committee that the post is fake, using some secret phrase hidden in the post as a subsequence. To make this method foolproof, she wants the phrase to appear n times in the post. She is asking you to design a post (string) s and a hidden phrase p such that p appears in s as a subsequence exactly n times. Input The first and only line of input contains a single integer n (1 ≤ n ≤ 1 000 000). Output The output should contain two nonempty strings s and p separated by a single space. Each string should be composed of letters (a-z and A-Z: both lowercase and uppercase are allowed) and have length at most 200. The number of occurrences of p in s as a subsequence should be exactly n. If there are many possible solutions, output any of them. It is guaranteed that at least one solution exists. Examples Input 2 Output hHheidi Hei Input 4 Output bbbba ba Input 6 Output aaabb ab Note An occurrence of p as a subsequence in s should be thought of as a set of positions in s such that the letters at these positions, in order, form p. The number of occurences is thus the number of such sets. For example, ab appears 6 times as a subsequence in aaabb, for the following sets of positions: {1, 4}, {1, 5}, {2, 4}, {2, 5}, {3, 4}, {3, 5} (that is, we should choose one of the a's and one of the b's).
2
14
#include <bits/stdc++.h> using namespace std; long long a[50]; int cn[50]; int dp[5][555]; void init() { for (int i = 1; i <= 40; i++) a[i] = 1LL * i * (i + 1) * (i + 2) * (i + 3) / 24; } int get(char *t, int tn) { memset(dp, 0, sizeof dp); for (int i = tn - 1; i >= 0; i--) { dp[0][i] = dp[0][i + 1] + (t[i] == 'e') * dp[1][i + 1]; dp[1][i] = dp[1][i + 1] + (t[i] == 'a') * dp[2][i + 1]; dp[2][i] = dp[2][i + 1] + (t[i] == 'b') * dp[3][i + 1]; dp[3][i] = dp[3][i + 1] + (t[i] == 'c') * dp[4][i + 1]; dp[4][i] = dp[4][i + 1] + (t[i] == 'd'); } return dp[0][0]; } int main() { char T[555], P[555]; init(); int n, p; scanf("%d", &n); p = n; memset(cn, 0, sizeof cn); int len = 0; int st; for (st = 40; st; st--) if (a[st] <= n) break; for (int i = st; i; i--) { cn[i] = n / a[i]; n -= cn[i] * a[i]; } len = 0; for (int i = st; i; i--) { for (int j = 0; j < cn[i]; j++) { T[len++] = 'e'; } T[len++] = 'a'; T[len++] = 'b'; T[len++] = 'c'; T[len++] = 'd'; } T[len] = '\0'; int cnt = get(T, len); printf("%s eabcd\n", T); assert(cnt == p); assert(len < 200); return 0; }
CPP
802_H. Fake News (medium)
Thanks to your help, Heidi is confident that no one can fool her. She has now decided to post some fake news on the HC2 Facebook page. However, she wants to be able to communicate to the HC2 committee that the post is fake, using some secret phrase hidden in the post as a subsequence. To make this method foolproof, she wants the phrase to appear n times in the post. She is asking you to design a post (string) s and a hidden phrase p such that p appears in s as a subsequence exactly n times. Input The first and only line of input contains a single integer n (1 ≤ n ≤ 1 000 000). Output The output should contain two nonempty strings s and p separated by a single space. Each string should be composed of letters (a-z and A-Z: both lowercase and uppercase are allowed) and have length at most 200. The number of occurrences of p in s as a subsequence should be exactly n. If there are many possible solutions, output any of them. It is guaranteed that at least one solution exists. Examples Input 2 Output hHheidi Hei Input 4 Output bbbba ba Input 6 Output aaabb ab Note An occurrence of p as a subsequence in s should be thought of as a set of positions in s such that the letters at these positions, in order, form p. The number of occurences is thus the number of such sets. For example, ab appears 6 times as a subsequence in aaabb, for the following sets of positions: {1, 4}, {1, 5}, {2, 4}, {2, 5}, {3, 4}, {3, 5} (that is, we should choose one of the a's and one of the b's).
2
14
#include <bits/stdc++.h> using namespace std; const int MAXN = 210; int n; int f[MAXN][MAXN]; int c[MAXN][MAXN]; string ins; int dp(string s1, string s2) { f[0][0] = 1; for (int i = 0; i < s1.length(); i++) { for (int j = 0; j < s2.length(); j++) { f[i + 1][j] += f[i][j]; if (s1[i] == s2[j]) f[i + 1][j + 1] += f[i][j]; } f[i + 1][s2.length()] += f[i][s2.length()]; } int ans = 0; return f[s1.length()][s2.length()]; } bool solve(int k) { string s = ins; int N = n, m = 0; for (int i = 100; i >= k && s.length() < 200; i--, m++) if (c[i][k] <= N) { N -= c[i][k]; s.insert(m, "a"); i++; if (!N) { cout << s << " "; return true; } } return false; } int main() { ios::sync_with_stdio(false); cin >> n; c[0][0] = 1; for (int i = 1; i <= 100; i++) { c[i][0] = 1; for (int j = 1; j <= 5; j++) c[i][j] = c[i - 1][j - 1] + c[i - 1][j]; } for (int i = 0; i < 100; i++) ins += 'b'; if (solve(1)) { cout << "ab" << endl; return 0; } if (solve(2)) { cout << "abb" << endl; return 0; } if (solve(3)) { cout << "abbb" << endl; return 0; } if (solve(4)) { cout << "abbbb" << endl; return 0; } return 0; }
CPP
802_H. Fake News (medium)
Thanks to your help, Heidi is confident that no one can fool her. She has now decided to post some fake news on the HC2 Facebook page. However, she wants to be able to communicate to the HC2 committee that the post is fake, using some secret phrase hidden in the post as a subsequence. To make this method foolproof, she wants the phrase to appear n times in the post. She is asking you to design a post (string) s and a hidden phrase p such that p appears in s as a subsequence exactly n times. Input The first and only line of input contains a single integer n (1 ≤ n ≤ 1 000 000). Output The output should contain two nonempty strings s and p separated by a single space. Each string should be composed of letters (a-z and A-Z: both lowercase and uppercase are allowed) and have length at most 200. The number of occurrences of p in s as a subsequence should be exactly n. If there are many possible solutions, output any of them. It is guaranteed that at least one solution exists. Examples Input 2 Output hHheidi Hei Input 4 Output bbbba ba Input 6 Output aaabb ab Note An occurrence of p as a subsequence in s should be thought of as a set of positions in s such that the letters at these positions, in order, form p. The number of occurences is thus the number of such sets. For example, ab appears 6 times as a subsequence in aaabb, for the following sets of positions: {1, 4}, {1, 5}, {2, 4}, {2, 5}, {3, 4}, {3, 5} (that is, we should choose one of the a's and one of the b's).
2
14
#include <bits/stdc++.h> using namespace std; int n; string a, b; char c; void Work(int len) { if (len == 1) { c = 'A', a = "", b = c; } else if (len == 2) { c = 'B', a = "B", b = "AB"; } else if (len & 1) { Work(len >> 1); ++c, a = a + c + c, b = b + c; } else { Work((len >> 1) - 1); ++c, a = c + a + c + c, b = b + c; } } signed main() { scanf("%d", &n); Work(n); cout << b + a << ' ' << b; }
CPP
802_H. Fake News (medium)
Thanks to your help, Heidi is confident that no one can fool her. She has now decided to post some fake news on the HC2 Facebook page. However, she wants to be able to communicate to the HC2 committee that the post is fake, using some secret phrase hidden in the post as a subsequence. To make this method foolproof, she wants the phrase to appear n times in the post. She is asking you to design a post (string) s and a hidden phrase p such that p appears in s as a subsequence exactly n times. Input The first and only line of input contains a single integer n (1 ≤ n ≤ 1 000 000). Output The output should contain two nonempty strings s and p separated by a single space. Each string should be composed of letters (a-z and A-Z: both lowercase and uppercase are allowed) and have length at most 200. The number of occurrences of p in s as a subsequence should be exactly n. If there are many possible solutions, output any of them. It is guaranteed that at least one solution exists. Examples Input 2 Output hHheidi Hei Input 4 Output bbbba ba Input 6 Output aaabb ab Note An occurrence of p as a subsequence in s should be thought of as a set of positions in s such that the letters at these positions, in order, form p. The number of occurences is thus the number of such sets. For example, ab appears 6 times as a subsequence in aaabb, for the following sets of positions: {1, 4}, {1, 5}, {2, 4}, {2, 5}, {3, 4}, {3, 5} (that is, we should choose one of the a's and one of the b's).
2
14
#include <bits/stdc++.h> using namespace std; inline long long read() { register long long x = 0, f = 0; register char c = getchar(); while (c < '0' || c > '9') { if (c == '-') f = 1; c = getchar(); } while (c >= '0' && c <= '9') x = (x << 3) + (x << 1) + (c ^ '0'), c = getchar(); return f ? -x : x; } inline void write(long long x) { if (x < 0) putchar('-'), x = -x; if (x > 9) write(x / 10); putchar(x % 10 + '0'); } long long n; string s, t; char ch; inline void Solve(long long x) { if (x == 1) { ch = 't'; s = ""; t = "t"; return; } if (x == 2) { ch = 'w'; s = "w"; t = "tw"; return; } if (x & 1) { Solve(x >> 1), ++ch; if (ch > 'z') ch = 'A'; s = s + ch + ch, t += ch; } else { Solve((x >> 1) - 1), ++ch; if (ch > 'z') ch = 'A'; s = ch + s + ch + ch, t += ch; } } signed main() { n = read(); Solve(n); cout << t + s << " " << t; return 0; }
CPP
802_H. Fake News (medium)
Thanks to your help, Heidi is confident that no one can fool her. She has now decided to post some fake news on the HC2 Facebook page. However, she wants to be able to communicate to the HC2 committee that the post is fake, using some secret phrase hidden in the post as a subsequence. To make this method foolproof, she wants the phrase to appear n times in the post. She is asking you to design a post (string) s and a hidden phrase p such that p appears in s as a subsequence exactly n times. Input The first and only line of input contains a single integer n (1 ≤ n ≤ 1 000 000). Output The output should contain two nonempty strings s and p separated by a single space. Each string should be composed of letters (a-z and A-Z: both lowercase and uppercase are allowed) and have length at most 200. The number of occurrences of p in s as a subsequence should be exactly n. If there are many possible solutions, output any of them. It is guaranteed that at least one solution exists. Examples Input 2 Output hHheidi Hei Input 4 Output bbbba ba Input 6 Output aaabb ab Note An occurrence of p as a subsequence in s should be thought of as a set of positions in s such that the letters at these positions, in order, form p. The number of occurences is thus the number of such sets. For example, ab appears 6 times as a subsequence in aaabb, for the following sets of positions: {1, 4}, {1, 5}, {2, 4}, {2, 5}, {3, 4}, {3, 5} (that is, we should choose one of the a's and one of the b's).
2
14
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { ll dp[30][8] = {}; dp[0][0] = 1; for (int(i) = 0; (i) < (int)(25); ++(i)) for (int(j) = 0; (j) < (int)(8); ++(j)) for (int(k) = 0; (k) < (int)(8); ++(k)) if (j <= k) dp[i + 1][k] += dp[i][j]; ll n; cin >> n; ll ct[30] = {}; for (int i = 25; i >= 1; --i) { ct[i - 1] = n / dp[i][7]; n %= dp[i][7]; } string s = ""; for (int(i) = 0; (i) < (int)(25); ++(i)) { s += "ABCDEFG"; for (int(j) = 0; (j) < (int)(ct[i]); ++(j)) s += "H"; } cout << s << " " << "ABCDEFGH" << endl; return 0; }
CPP
802_H. Fake News (medium)
Thanks to your help, Heidi is confident that no one can fool her. She has now decided to post some fake news on the HC2 Facebook page. However, she wants to be able to communicate to the HC2 committee that the post is fake, using some secret phrase hidden in the post as a subsequence. To make this method foolproof, she wants the phrase to appear n times in the post. She is asking you to design a post (string) s and a hidden phrase p such that p appears in s as a subsequence exactly n times. Input The first and only line of input contains a single integer n (1 ≤ n ≤ 1 000 000). Output The output should contain two nonempty strings s and p separated by a single space. Each string should be composed of letters (a-z and A-Z: both lowercase and uppercase are allowed) and have length at most 200. The number of occurrences of p in s as a subsequence should be exactly n. If there are many possible solutions, output any of them. It is guaranteed that at least one solution exists. Examples Input 2 Output hHheidi Hei Input 4 Output bbbba ba Input 6 Output aaabb ab Note An occurrence of p as a subsequence in s should be thought of as a set of positions in s such that the letters at these positions, in order, form p. The number of occurences is thus the number of such sets. For example, ab appears 6 times as a subsequence in aaabb, for the following sets of positions: {1, 4}, {1, 5}, {2, 4}, {2, 5}, {3, 4}, {3, 5} (that is, we should choose one of the a's and one of the b's).
2
14
#include <bits/stdc++.h> using namespace std; using pii = pair<int, int>; using vpii = vector<pii>; using vi = vector<int>; using vvi = vector<vi>; using ll = long long; using vll = vector<long long>; template <class T> using min_queue = priority_queue<T, vector<T>, greater<T>>; template <class T> istream &operator>>(istream &, vector<T> &); template <class T> ostream &operator<<(ostream &, const vector<T> &); template <class T, class U> istream &operator>>(istream &, pair<T, U> &); template <class T, class U> ostream &operator<<(ostream &, const pair<T, U> &); template <class T> struct Inf { static constexpr T inf() { return std::numeric_limits<T>::has_infinity() ? std::numeric_limits<T>::infinty() : std::numeric_limits<T>::max(); } }; template <> struct Inf<int> { static constexpr int inf() { return 0x3f3f3f3f; } }; template <> struct Inf<long long> { static constexpr long long inf() { return 0x3f3f3f3f3f3f3f3fLL; } }; constexpr int INF = Inf<int>::inf(); constexpr ll BINF = Inf<ll>::inf(); int solve() { int n; cin >> n; const int K = 7; string s, t; for (int i = 0; i < K; i++) s.push_back('a' + i); t = s; s.pop_back(); for (int j = 0; j < K; j++) { for (int z = 0; z < j; z++) { for (int i = 0; i < K - 1; i++) s.push_back('a' + K - j - 1 + z); } int x = n % K; if (j < K - 1) n /= K; else x = n; for (int i = 0; i < x; i++) s.push_back('a' + K - 1); } cout << s << ' ' << t << endl; return 0; } int main() { ios::sync_with_stdio(0); solve(); return 0; } template <class T> istream &operator>>(istream &is, vector<T> &v) { for (auto it = v.begin(); it != v.end(); ++it) is >> *it; return is; } template <class T> ostream &operator<<(ostream &os, const vector<T> &v) { for (auto it = v.begin(); it != v.end();) os << *it, os << " \n"[++it == v.end()]; return os; } template <class T, class U> istream &operator>>(istream &is, pair<T, U> &p) { return is >> p.first >> p.second; } template <class T, class U> ostream &operator<<(ostream &os, const pair<T, U> &p) { return os << p.first << ' ' << p.second; }
CPP
802_H. Fake News (medium)
Thanks to your help, Heidi is confident that no one can fool her. She has now decided to post some fake news on the HC2 Facebook page. However, she wants to be able to communicate to the HC2 committee that the post is fake, using some secret phrase hidden in the post as a subsequence. To make this method foolproof, she wants the phrase to appear n times in the post. She is asking you to design a post (string) s and a hidden phrase p such that p appears in s as a subsequence exactly n times. Input The first and only line of input contains a single integer n (1 ≤ n ≤ 1 000 000). Output The output should contain two nonempty strings s and p separated by a single space. Each string should be composed of letters (a-z and A-Z: both lowercase and uppercase are allowed) and have length at most 200. The number of occurrences of p in s as a subsequence should be exactly n. If there are many possible solutions, output any of them. It is guaranteed that at least one solution exists. Examples Input 2 Output hHheidi Hei Input 4 Output bbbba ba Input 6 Output aaabb ab Note An occurrence of p as a subsequence in s should be thought of as a set of positions in s such that the letters at these positions, in order, form p. The number of occurences is thus the number of such sets. For example, ab appears 6 times as a subsequence in aaabb, for the following sets of positions: {1, 4}, {1, 5}, {2, 4}, {2, 5}, {3, 4}, {3, 5} (that is, we should choose one of the a's and one of the b's).
2
14
#include <bits/stdc++.h> using namespace std; long long val(long long n) { return (n * (n - 1) * (n - 2) * (n - 3) * (n - 4)) / 120; } signed main() { ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); ; long long n; cin >> n; vector<long long> cnt(51, 0); for (long long i = 50; i >= 5; i--) { long long x = val(i); while (n >= x) n -= x, cnt[i]++; } string a, b = "aaaaab"; for (long long i = 1; i <= 50; i++) { a += 'a'; while (cnt[i]--) a += 'b'; } cout << a << " " << b << "\n"; }
CPP
802_H. Fake News (medium)
Thanks to your help, Heidi is confident that no one can fool her. She has now decided to post some fake news on the HC2 Facebook page. However, she wants to be able to communicate to the HC2 committee that the post is fake, using some secret phrase hidden in the post as a subsequence. To make this method foolproof, she wants the phrase to appear n times in the post. She is asking you to design a post (string) s and a hidden phrase p such that p appears in s as a subsequence exactly n times. Input The first and only line of input contains a single integer n (1 ≤ n ≤ 1 000 000). Output The output should contain two nonempty strings s and p separated by a single space. Each string should be composed of letters (a-z and A-Z: both lowercase and uppercase are allowed) and have length at most 200. The number of occurrences of p in s as a subsequence should be exactly n. If there are many possible solutions, output any of them. It is guaranteed that at least one solution exists. Examples Input 2 Output hHheidi Hei Input 4 Output bbbba ba Input 6 Output aaabb ab Note An occurrence of p as a subsequence in s should be thought of as a set of positions in s such that the letters at these positions, in order, form p. The number of occurences is thus the number of such sets. For example, ab appears 6 times as a subsequence in aaabb, for the following sets of positions: {1, 4}, {1, 5}, {2, 4}, {2, 5}, {3, 4}, {3, 5} (that is, we should choose one of the a's and one of the b's).
2
14
#include <bits/stdc++.h> using namespace std; int N, pt[205], blen = 1000000000; long long a[205]; string ba, bb; int main() { scanf("%d", &N); int tN = N; for (int R = 3; R <= 9; R++) { N = tN; for (int i = 0; i < 200; i++) a[i] = 1; for (int i = 0; i < R; i++) { for (int j = 1; j < 200; j++) a[j] += a[j - 1]; } memset(pt, 0, sizeof(pt)); int mx = 0; while (N > 0) { int pos = upper_bound(a, a + 200, N) - a - 1; mx = max(mx, pos); N -= a[pos]; pt[pos]++; } string a, b; int len = 0; for (int i = 0; i <= mx; i++) { for (int j = 0; j < R; j++) a += (char)('a' + j); for (int j = 0; j < pt[i]; j++) a += (char)('a' + R); len += R + pt[i]; } for (int j = 0; j <= R; j++) b += (char)('a' + j); if (len < blen) { blen = len; ba = a; bb = b; } } printf("%s %s\n", ba.c_str(), bb.c_str()); }
CPP
802_H. Fake News (medium)
Thanks to your help, Heidi is confident that no one can fool her. She has now decided to post some fake news on the HC2 Facebook page. However, she wants to be able to communicate to the HC2 committee that the post is fake, using some secret phrase hidden in the post as a subsequence. To make this method foolproof, she wants the phrase to appear n times in the post. She is asking you to design a post (string) s and a hidden phrase p such that p appears in s as a subsequence exactly n times. Input The first and only line of input contains a single integer n (1 ≤ n ≤ 1 000 000). Output The output should contain two nonempty strings s and p separated by a single space. Each string should be composed of letters (a-z and A-Z: both lowercase and uppercase are allowed) and have length at most 200. The number of occurrences of p in s as a subsequence should be exactly n. If there are many possible solutions, output any of them. It is guaranteed that at least one solution exists. Examples Input 2 Output hHheidi Hei Input 4 Output bbbba ba Input 6 Output aaabb ab Note An occurrence of p as a subsequence in s should be thought of as a set of positions in s such that the letters at these positions, in order, form p. The number of occurences is thus the number of such sets. For example, ab appears 6 times as a subsequence in aaabb, for the following sets of positions: {1, 4}, {1, 5}, {2, 4}, {2, 5}, {3, 4}, {3, 5} (that is, we should choose one of the a's and one of the b's).
2
14
#include <bits/stdc++.h> using namespace std; deque<char> ch; void M2P1(string& lp, string& rp) { auto c = ch[0]; ch.pop_front(); lp = string(2, c) + lp; rp = string(1, c) + rp; } void P1(string& lp, string& rp) { auto c = ch[0]; ch.pop_front(); lp = string(1, c) + lp; rp = string(1, c) + rp; } void Solve(int n, string& lp, string& rp) { if (n == 1) { auto c = ch[0]; ch.pop_front(); lp = ""; rp = string(1, c); return; } if (n & 1) Solve(n / 2, lp, rp), M2P1(lp, rp); else Solve(n - 1, lp, rp), P1(lp, rp); } int main() { for (char c = 'a'; c <= 'z'; ++c) ch.push_back(c); for (char c = 'A'; c <= 'Z'; ++c) ch.push_back(c); int n; cin >> n; string lp, rp; Solve(n, lp, rp); cout << lp + rp << ' ' << rp << '\n'; return 0; }
CPP
802_H. Fake News (medium)
Thanks to your help, Heidi is confident that no one can fool her. She has now decided to post some fake news on the HC2 Facebook page. However, she wants to be able to communicate to the HC2 committee that the post is fake, using some secret phrase hidden in the post as a subsequence. To make this method foolproof, she wants the phrase to appear n times in the post. She is asking you to design a post (string) s and a hidden phrase p such that p appears in s as a subsequence exactly n times. Input The first and only line of input contains a single integer n (1 ≤ n ≤ 1 000 000). Output The output should contain two nonempty strings s and p separated by a single space. Each string should be composed of letters (a-z and A-Z: both lowercase and uppercase are allowed) and have length at most 200. The number of occurrences of p in s as a subsequence should be exactly n. If there are many possible solutions, output any of them. It is guaranteed that at least one solution exists. Examples Input 2 Output hHheidi Hei Input 4 Output bbbba ba Input 6 Output aaabb ab Note An occurrence of p as a subsequence in s should be thought of as a set of positions in s such that the letters at these positions, in order, form p. The number of occurences is thus the number of such sets. For example, ab appears 6 times as a subsequence in aaabb, for the following sets of positions: {1, 4}, {1, 5}, {2, 4}, {2, 5}, {3, 4}, {3, 5} (that is, we should choose one of the a's and one of the b's).
2
14
#include <bits/stdc++.h> using namespace std; int n; char now; string s, t; void solve(int len) { if (len == 1) { s = ""; t = "a"; now = 'a'; return; } if (len == 2) { s = "b"; t = "ab"; now = 'b'; return; } if (len % 2 == 0) { solve(len / 2 - 1); now++; s = now + s + now + now; t = t + now; return; } if (len % 2 == 1) { solve(len / 2); now++; s = s + now + now; t = t + now; return; } } int main() { scanf("%d", &n); solve(n); cout << t << s << " " << t; return 0; }
CPP
802_H. Fake News (medium)
Thanks to your help, Heidi is confident that no one can fool her. She has now decided to post some fake news on the HC2 Facebook page. However, she wants to be able to communicate to the HC2 committee that the post is fake, using some secret phrase hidden in the post as a subsequence. To make this method foolproof, she wants the phrase to appear n times in the post. She is asking you to design a post (string) s and a hidden phrase p such that p appears in s as a subsequence exactly n times. Input The first and only line of input contains a single integer n (1 ≤ n ≤ 1 000 000). Output The output should contain two nonempty strings s and p separated by a single space. Each string should be composed of letters (a-z and A-Z: both lowercase and uppercase are allowed) and have length at most 200. The number of occurrences of p in s as a subsequence should be exactly n. If there are many possible solutions, output any of them. It is guaranteed that at least one solution exists. Examples Input 2 Output hHheidi Hei Input 4 Output bbbba ba Input 6 Output aaabb ab Note An occurrence of p as a subsequence in s should be thought of as a set of positions in s such that the letters at these positions, in order, form p. The number of occurences is thus the number of such sets. For example, ab appears 6 times as a subsequence in aaabb, for the following sets of positions: {1, 4}, {1, 5}, {2, 4}, {2, 5}, {3, 4}, {3, 5} (that is, we should choose one of the a's and one of the b's).
2
14
#include <bits/stdc++.h> using namespace std; int a[11], n, cnt[11]; int main() { a[1] = 1; for (int k = 2; k <= 10; k++) a[k] = a[k - 1] * (k + 9) / (k - 1); scanf("%d", &n); for (int k = 10; k >= 1; k--) { while (n >= a[k]) { cnt[k]++; n -= a[k]; } } for (int k = 1; k <= 10; k++) { for (int i = 0; i < 10; i++) printf("%c", i + 'a'); for (int i = 0; i < cnt[k]; i++) printf("%c", 10 + 'a'); } printf(" "); for (int i = 0; i <= 10; i++) printf("%c", i + 'a'); return 0; }
CPP
802_H. Fake News (medium)
Thanks to your help, Heidi is confident that no one can fool her. She has now decided to post some fake news on the HC2 Facebook page. However, she wants to be able to communicate to the HC2 committee that the post is fake, using some secret phrase hidden in the post as a subsequence. To make this method foolproof, she wants the phrase to appear n times in the post. She is asking you to design a post (string) s and a hidden phrase p such that p appears in s as a subsequence exactly n times. Input The first and only line of input contains a single integer n (1 ≤ n ≤ 1 000 000). Output The output should contain two nonempty strings s and p separated by a single space. Each string should be composed of letters (a-z and A-Z: both lowercase and uppercase are allowed) and have length at most 200. The number of occurrences of p in s as a subsequence should be exactly n. If there are many possible solutions, output any of them. It is guaranteed that at least one solution exists. Examples Input 2 Output hHheidi Hei Input 4 Output bbbba ba Input 6 Output aaabb ab Note An occurrence of p as a subsequence in s should be thought of as a set of positions in s such that the letters at these positions, in order, form p. The number of occurences is thus the number of such sets. For example, ab appears 6 times as a subsequence in aaabb, for the following sets of positions: {1, 4}, {1, 5}, {2, 4}, {2, 5}, {3, 4}, {3, 5} (that is, we should choose one of the a's and one of the b's).
2
14
#include <bits/stdc++.h> using namespace std; int Comb[110][6], C[110], S; int main() { int i, j; for (i = 0; i <= 45; i++) { Comb[i][0] = 1; for (j = 1; j <= 5 && j <= i; j++) Comb[i][j] = Comb[i - 1][j] + Comb[i - 1][j - 1]; } scanf("%d", &S); for (i = 45; i >= 5; i--) { while (S >= Comb[i][5]) { C[i]++; S -= Comb[i][5]; } } for (i = 0; i < 45; i++) { while (C[i]--) printf("b"); printf("a"); } printf(" aaaaab\n"); }
CPP
802_H. Fake News (medium)
Thanks to your help, Heidi is confident that no one can fool her. She has now decided to post some fake news on the HC2 Facebook page. However, she wants to be able to communicate to the HC2 committee that the post is fake, using some secret phrase hidden in the post as a subsequence. To make this method foolproof, she wants the phrase to appear n times in the post. She is asking you to design a post (string) s and a hidden phrase p such that p appears in s as a subsequence exactly n times. Input The first and only line of input contains a single integer n (1 ≤ n ≤ 1 000 000). Output The output should contain two nonempty strings s and p separated by a single space. Each string should be composed of letters (a-z and A-Z: both lowercase and uppercase are allowed) and have length at most 200. The number of occurrences of p in s as a subsequence should be exactly n. If there are many possible solutions, output any of them. It is guaranteed that at least one solution exists. Examples Input 2 Output hHheidi Hei Input 4 Output bbbba ba Input 6 Output aaabb ab Note An occurrence of p as a subsequence in s should be thought of as a set of positions in s such that the letters at these positions, in order, form p. The number of occurences is thus the number of such sets. For example, ab appears 6 times as a subsequence in aaabb, for the following sets of positions: {1, 4}, {1, 5}, {2, 4}, {2, 5}, {3, 4}, {3, 5} (that is, we should choose one of the a's and one of the b's).
2
14
#include <bits/stdc++.h> using namespace std; template <typename T, typename U> inline void chkmax(T& x, U y) { if (x < y) x = y; } template <typename T, typename U> inline void chkmin(T& x, U y) { if (y < x) x = y; } const int N = 1000000 + 10; int hd[N]; char pat[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; int main() { hd[1] = 0; for (int i = 2; i < N; i++) { int p = 31 - __builtin_clz(i - 1); int j = 1 << p; while (1) { if (hd[i - j] >= p - 1) { hd[i] = p; break; } j >>= 1; --p; } } int n; scanf("%d", &n); if (n == 1) { puts("a a"); return 0; } vector<int> vec; while (n) { vec.push_back(hd[n]); n -= 1 << (hd[n]); } int l = vec.size(); int la = vec[l - 1]; vector<int> A, B; A.resize(l - 1), B.resize(l - 1); for (int i = 0; i < l - 1; i++) { if (vec[i] > vec[i + 1]) { A[i] = 2; B[i] = 1; } } for (int i = 0, cur = 0; i < l - 1 and cur < la; i++) { if (vec[i] == vec[i + 1]) { A[i] = B[i] = 2; ++cur; } } for (int i = 0; i < l - 1; i++) { if (!A[i]) A[i] = B[i] = 1; } int res = 0; for (int i = 0; i < l; i++) { int mul = 1; for (int j = 0; j < i; j++) { mul *= B[j]; } for (int j = i; j < l - 1; j++) { mul *= A[j]; } res += mul; } for (int i = 0; i < l - 1; i++) { for (int j = 0; j < B[i]; j++) { printf("%c", pat[i]); } } for (int i = 0; i < l - 1; i++) { for (int j = 0; j < A[i]; j++) { printf("%c", pat[i]); } } printf(" "); for (int i = 0; i < l - 1; i++) printf("%c", pat[i]); return 0; }
CPP
802_H. Fake News (medium)
Thanks to your help, Heidi is confident that no one can fool her. She has now decided to post some fake news on the HC2 Facebook page. However, she wants to be able to communicate to the HC2 committee that the post is fake, using some secret phrase hidden in the post as a subsequence. To make this method foolproof, she wants the phrase to appear n times in the post. She is asking you to design a post (string) s and a hidden phrase p such that p appears in s as a subsequence exactly n times. Input The first and only line of input contains a single integer n (1 ≤ n ≤ 1 000 000). Output The output should contain two nonempty strings s and p separated by a single space. Each string should be composed of letters (a-z and A-Z: both lowercase and uppercase are allowed) and have length at most 200. The number of occurrences of p in s as a subsequence should be exactly n. If there are many possible solutions, output any of them. It is guaranteed that at least one solution exists. Examples Input 2 Output hHheidi Hei Input 4 Output bbbba ba Input 6 Output aaabb ab Note An occurrence of p as a subsequence in s should be thought of as a set of positions in s such that the letters at these positions, in order, form p. The number of occurences is thus the number of such sets. For example, ab appears 6 times as a subsequence in aaabb, for the following sets of positions: {1, 4}, {1, 5}, {2, 4}, {2, 5}, {3, 4}, {3, 5} (that is, we should choose one of the a's and one of the b's).
2
14
#include <bits/stdc++.h> using namespace std; int C[50][50]; int main() { C[0][0] = 1; for (int i = 1; i <= 30; i++) { C[i][0] = C[i][i] = 1; for (int j = 1; j <= 30; j++) { C[i][j] = C[i - 1][j] + C[i - 1][j - 1]; } } string p = "aaaaaaaaab"; int pSize = (int)p.size() - 1; string result = ""; int n; cin >> n; for (int i = 30; i >= 9; i--) { while (n >= C[i][pSize]) { n -= C[i][pSize]; result += 'b'; } result += 'a'; } reverse(result.begin(), result.end()); result = p.substr(0, pSize - 1) + result; long long cnt = 0; int aCnt = 0; for (int i = 0; i < result.size(); i++) { aCnt += result[i] == 'a'; if (result[i] == 'b') cnt += C[aCnt][pSize]; } cout << result << " " << p << "\n"; return 0; }
CPP
802_H. Fake News (medium)
Thanks to your help, Heidi is confident that no one can fool her. She has now decided to post some fake news on the HC2 Facebook page. However, she wants to be able to communicate to the HC2 committee that the post is fake, using some secret phrase hidden in the post as a subsequence. To make this method foolproof, she wants the phrase to appear n times in the post. She is asking you to design a post (string) s and a hidden phrase p such that p appears in s as a subsequence exactly n times. Input The first and only line of input contains a single integer n (1 ≤ n ≤ 1 000 000). Output The output should contain two nonempty strings s and p separated by a single space. Each string should be composed of letters (a-z and A-Z: both lowercase and uppercase are allowed) and have length at most 200. The number of occurrences of p in s as a subsequence should be exactly n. If there are many possible solutions, output any of them. It is guaranteed that at least one solution exists. Examples Input 2 Output hHheidi Hei Input 4 Output bbbba ba Input 6 Output aaabb ab Note An occurrence of p as a subsequence in s should be thought of as a set of positions in s such that the letters at these positions, in order, form p. The number of occurences is thus the number of such sets. For example, ab appears 6 times as a subsequence in aaabb, for the following sets of positions: {1, 4}, {1, 5}, {2, 4}, {2, 5}, {3, 4}, {3, 5} (that is, we should choose one of the a's and one of the b's).
2
14
#include <bits/stdc++.h> using namespace std; long long n; char now; string s, t; inline void solve(int len) { if (len == 1) { s = ""; t = "a"; now = 'a'; return; } if (len == 2) { s = "b"; t = "ab"; now = 'b'; return; } if (len & 1) { solve(len / 2); now++; s = s + now + now; t = t + now; return; } else { solve(len / 2 - 1); now++; s = now + s + now + now; t = t + now; return; } } int main() { cin >> n; solve(n); cout << t << s << " " << t; return 0; }
CPP
802_H. Fake News (medium)
Thanks to your help, Heidi is confident that no one can fool her. She has now decided to post some fake news on the HC2 Facebook page. However, she wants to be able to communicate to the HC2 committee that the post is fake, using some secret phrase hidden in the post as a subsequence. To make this method foolproof, she wants the phrase to appear n times in the post. She is asking you to design a post (string) s and a hidden phrase p such that p appears in s as a subsequence exactly n times. Input The first and only line of input contains a single integer n (1 ≤ n ≤ 1 000 000). Output The output should contain two nonempty strings s and p separated by a single space. Each string should be composed of letters (a-z and A-Z: both lowercase and uppercase are allowed) and have length at most 200. The number of occurrences of p in s as a subsequence should be exactly n. If there are many possible solutions, output any of them. It is guaranteed that at least one solution exists. Examples Input 2 Output hHheidi Hei Input 4 Output bbbba ba Input 6 Output aaabb ab Note An occurrence of p as a subsequence in s should be thought of as a set of positions in s such that the letters at these positions, in order, form p. The number of occurences is thus the number of such sets. For example, ab appears 6 times as a subsequence in aaabb, for the following sets of positions: {1, 4}, {1, 5}, {2, 4}, {2, 5}, {3, 4}, {3, 5} (that is, we should choose one of the a's and one of the b's).
2
14
#include <bits/stdc++.h> using namespace std; template <class T> ostream& operator<<(ostream& stream, const vector<T> v) { stream << "[ "; for (int i = 0; i < (int)v.size(); i++) stream << v[i] << " "; stream << "]"; return stream; } long long fpow(long long x, long long p, long long m) { long long r = 1; for (; p; p >>= 1) { if (p & 1) r = r * x % m; x = x * x % m; } return r; } long long inv(long long a, long long b) { return a < 2 ? a : ((a - inv(b % a, a)) * b + 1) / a % b; } int gcd(int a, int b) { if (!b) return a; return gcd(b, a % b); } long long gcd(long long a, long long b) { if (!b) return a; return gcd(b, a % b); } pair<string, string> get(int n, int k) { if (n == 0) return {"", ""}; else if (n == 1) return {string(1, 'a' + k), string(1, 'a' + k)}; else if (n == 2) return {string(2, 'a' + k), string(1, 'a' + k)}; pair<string, string> r; int p = 0; if (n % 2 == 0) { r = get((n - 2) / 2, k + 1); p = 2; } else { r = get((n - 1) / 2, k + 1); p = 1; } int l = r.second.length(); r.first.insert(l, p, 'a' + k); r.first += 'a' + k; r.first += 'a' + k; r.second += 'a' + k; return r; } int main() { ios::sync_with_stdio(0); cin.tie(0); int n; cin >> n; pair<string, string> r = get(n, 0); cout << r.first << " " << r.second << "\n"; return 0; }
CPP
802_H. Fake News (medium)
Thanks to your help, Heidi is confident that no one can fool her. She has now decided to post some fake news on the HC2 Facebook page. However, she wants to be able to communicate to the HC2 committee that the post is fake, using some secret phrase hidden in the post as a subsequence. To make this method foolproof, she wants the phrase to appear n times in the post. She is asking you to design a post (string) s and a hidden phrase p such that p appears in s as a subsequence exactly n times. Input The first and only line of input contains a single integer n (1 ≤ n ≤ 1 000 000). Output The output should contain two nonempty strings s and p separated by a single space. Each string should be composed of letters (a-z and A-Z: both lowercase and uppercase are allowed) and have length at most 200. The number of occurrences of p in s as a subsequence should be exactly n. If there are many possible solutions, output any of them. It is guaranteed that at least one solution exists. Examples Input 2 Output hHheidi Hei Input 4 Output bbbba ba Input 6 Output aaabb ab Note An occurrence of p as a subsequence in s should be thought of as a set of positions in s such that the letters at these positions, in order, form p. The number of occurences is thus the number of such sets. For example, ab appears 6 times as a subsequence in aaabb, for the following sets of positions: {1, 4}, {1, 5}, {2, 4}, {2, 5}, {3, 4}, {3, 5} (that is, we should choose one of the a's and one of the b's).
2
14
#include <bits/stdc++.h> using namespace std; long long n; string s, p; long long bin[34][34]; void read() { cin >> n; for (int i = 0; i <= 30; i++) { bin[i][0] = bin[i][i] = 1; for (int j = 1; j < i; j++) { bin[i][j] = bin[i - 1][j - 1] + bin[i - 1][j]; } } } void solve() { string res = ""; for (int i = 30; i >= 9; i--) { while (n >= bin[i][9]) { n -= bin[i][9]; res += "b"; } res += "a"; } cout << "aaaaaaaa"; for (int i = res.length() - 1; i >= 0; i--) cout << res[i]; cout << " aaaaaaaaab\n"; } int main() { std::ios::sync_with_stdio(false); read(); solve(); return 0; }
CPP
802_H. Fake News (medium)
Thanks to your help, Heidi is confident that no one can fool her. She has now decided to post some fake news on the HC2 Facebook page. However, she wants to be able to communicate to the HC2 committee that the post is fake, using some secret phrase hidden in the post as a subsequence. To make this method foolproof, she wants the phrase to appear n times in the post. She is asking you to design a post (string) s and a hidden phrase p such that p appears in s as a subsequence exactly n times. Input The first and only line of input contains a single integer n (1 ≤ n ≤ 1 000 000). Output The output should contain two nonempty strings s and p separated by a single space. Each string should be composed of letters (a-z and A-Z: both lowercase and uppercase are allowed) and have length at most 200. The number of occurrences of p in s as a subsequence should be exactly n. If there are many possible solutions, output any of them. It is guaranteed that at least one solution exists. Examples Input 2 Output hHheidi Hei Input 4 Output bbbba ba Input 6 Output aaabb ab Note An occurrence of p as a subsequence in s should be thought of as a set of positions in s such that the letters at these positions, in order, form p. The number of occurences is thus the number of such sets. For example, ab appears 6 times as a subsequence in aaabb, for the following sets of positions: {1, 4}, {1, 5}, {2, 4}, {2, 5}, {3, 4}, {3, 5} (that is, we should choose one of the a's and one of the b's).
2
14
#include <bits/stdc++.h> using namespace std; pair<string, string> Solve(int n) { if (n == 1) return pair<string, string>("a", "a"); if (n == 2) return pair<string, string>("abb", "ab"); if (n % 2 == 0) { pair<string, string> a = Solve(n / 2 - 1); char c = char(a.second[(int)a.second.size() - 1] + 1); a.first.insert((int)a.second.size(), string(2, c)); a.first += string(2, c); a.second += c; return a; } else { pair<string, string> a = Solve(n / 2); char c = char(a.second[(int)a.second.size() - 1] + 1); a.first.insert((int)a.second.size(), string(1, c)); a.first += string(2, c); a.second += c; return a; } } int main() { int n; cin >> n; pair<string, string> ans = Solve(n); cout << ans.first << " " << ans.second; return 0; }
CPP
802_H. Fake News (medium)
Thanks to your help, Heidi is confident that no one can fool her. She has now decided to post some fake news on the HC2 Facebook page. However, she wants to be able to communicate to the HC2 committee that the post is fake, using some secret phrase hidden in the post as a subsequence. To make this method foolproof, she wants the phrase to appear n times in the post. She is asking you to design a post (string) s and a hidden phrase p such that p appears in s as a subsequence exactly n times. Input The first and only line of input contains a single integer n (1 ≤ n ≤ 1 000 000). Output The output should contain two nonempty strings s and p separated by a single space. Each string should be composed of letters (a-z and A-Z: both lowercase and uppercase are allowed) and have length at most 200. The number of occurrences of p in s as a subsequence should be exactly n. If there are many possible solutions, output any of them. It is guaranteed that at least one solution exists. Examples Input 2 Output hHheidi Hei Input 4 Output bbbba ba Input 6 Output aaabb ab Note An occurrence of p as a subsequence in s should be thought of as a set of positions in s such that the letters at these positions, in order, form p. The number of occurences is thus the number of such sets. For example, ab appears 6 times as a subsequence in aaabb, for the following sets of positions: {1, 4}, {1, 5}, {2, 4}, {2, 5}, {3, 4}, {3, 5} (that is, we should choose one of the a's and one of the b's).
2
14
#include <bits/stdc++.h> using namespace std; using ll = long long; using vi = vector<int>; using db = double; int n; const int N = 18; int main() { cin >> n; string s, p; for (int i = 0; i < N; ++i) p.push_back('a' + i); s = p; for (int i = 2; i <= N; ++i) for (int j = N - i; j < N; ++j) s.push_back('a' + j); while (s.size() < 200) s.push_back('a' + N - 1); int t = -1; for (auto i : s) if (i == 'a' + N - 2) ++t; reverse(s.begin(), s.end()); for (auto &i : s) { if (i == 'a' + N - 2) --t; if (i == 'a' + N - 1) if (n >= 1 << t) { n -= 1 << t; } else { i = 0; } } reverse(s.begin(), s.end()); for (auto i : s) if (i) cout << i; cout << ' ' << p << endl; return 0; }
CPP
802_H. Fake News (medium)
Thanks to your help, Heidi is confident that no one can fool her. She has now decided to post some fake news on the HC2 Facebook page. However, she wants to be able to communicate to the HC2 committee that the post is fake, using some secret phrase hidden in the post as a subsequence. To make this method foolproof, she wants the phrase to appear n times in the post. She is asking you to design a post (string) s and a hidden phrase p such that p appears in s as a subsequence exactly n times. Input The first and only line of input contains a single integer n (1 ≤ n ≤ 1 000 000). Output The output should contain two nonempty strings s and p separated by a single space. Each string should be composed of letters (a-z and A-Z: both lowercase and uppercase are allowed) and have length at most 200. The number of occurrences of p in s as a subsequence should be exactly n. If there are many possible solutions, output any of them. It is guaranteed that at least one solution exists. Examples Input 2 Output hHheidi Hei Input 4 Output bbbba ba Input 6 Output aaabb ab Note An occurrence of p as a subsequence in s should be thought of as a set of positions in s such that the letters at these positions, in order, form p. The number of occurences is thus the number of such sets. For example, ab appears 6 times as a subsequence in aaabb, for the following sets of positions: {1, 4}, {1, 5}, {2, 4}, {2, 5}, {3, 4}, {3, 5} (that is, we should choose one of the a's and one of the b's).
2
14
#include <bits/stdc++.h> using namespace std; template <typename A, typename B> inline void chmin(A &a, B b) { if (a > b) a = b; } template <typename A, typename B> inline void chmax(A &a, B b) { if (a < b) a = b; } string S; long long dp[3333333]; signed main() { for (long long i = 0; i < 26; i++) S += (char)('a' + i); for (long long i = 0; i < 26; i++) S += (char)('A' + i); fill_n(dp, 1111111, INT_MAX); dp[1] = 0; for (long long i = 1; i < 1111111; i++) { for (long long j = 1; j <= 2; j++) { chmin(dp[i * j + 1], dp[i] + 1); } } long long n; cin >> n; string s; long long cur = 0; while (n > 1) { if ((n - 1) & 1) { s += string(1, S[cur++]); n--; } else { s += string(2, S[cur++]); n = (n - 1) / 2; } } for (long long i = 0; i < S.size(); i++) s += S[i]; cout << s << " " << S << endl; return 0; }
CPP
802_H. Fake News (medium)
Thanks to your help, Heidi is confident that no one can fool her. She has now decided to post some fake news on the HC2 Facebook page. However, she wants to be able to communicate to the HC2 committee that the post is fake, using some secret phrase hidden in the post as a subsequence. To make this method foolproof, she wants the phrase to appear n times in the post. She is asking you to design a post (string) s and a hidden phrase p such that p appears in s as a subsequence exactly n times. Input The first and only line of input contains a single integer n (1 ≤ n ≤ 1 000 000). Output The output should contain two nonempty strings s and p separated by a single space. Each string should be composed of letters (a-z and A-Z: both lowercase and uppercase are allowed) and have length at most 200. The number of occurrences of p in s as a subsequence should be exactly n. If there are many possible solutions, output any of them. It is guaranteed that at least one solution exists. Examples Input 2 Output hHheidi Hei Input 4 Output bbbba ba Input 6 Output aaabb ab Note An occurrence of p as a subsequence in s should be thought of as a set of positions in s such that the letters at these positions, in order, form p. The number of occurences is thus the number of such sets. For example, ab appears 6 times as a subsequence in aaabb, for the following sets of positions: {1, 4}, {1, 5}, {2, 4}, {2, 5}, {3, 4}, {3, 5} (that is, we should choose one of the a's and one of the b's).
2
14
#include <bits/stdc++.h> using namespace std; inline int readInt() { static int n, ch; n = 0, ch = getchar(); while (!isdigit(ch)) ch = getchar(); while (isdigit(ch)) n = n * 10 + ch - '0', ch = getchar(); return n; } const int MAX_N = 1000000 + 3; string s, p; void solve(int n) { if (n == 1) { s = p = "a"; } else if (n == 2) { s = "aa"; p = "a"; } else if (n & 1) { solve(n >> 1); char newChar = 'a' + p.length(); string a = s.substr(0, p.length()), b = s.substr(p.length(), s.length() - p.length()); s = a + string(1, newChar) + b; s += string(2, newChar); p += string(1, newChar); } else { solve((n - 2) >> 1); char newChar = 'a' + p.length(); string a = s.substr(0, p.length()), b = s.substr(p.length(), s.length() - p.length()); s = a + string(2, newChar) + b; s += string(2, newChar); p += string(1, newChar); } } int main() { solve(readInt()); cout << s << ' ' << p << endl; return 0; }
CPP
802_H. Fake News (medium)
Thanks to your help, Heidi is confident that no one can fool her. She has now decided to post some fake news on the HC2 Facebook page. However, she wants to be able to communicate to the HC2 committee that the post is fake, using some secret phrase hidden in the post as a subsequence. To make this method foolproof, she wants the phrase to appear n times in the post. She is asking you to design a post (string) s and a hidden phrase p such that p appears in s as a subsequence exactly n times. Input The first and only line of input contains a single integer n (1 ≤ n ≤ 1 000 000). Output The output should contain two nonempty strings s and p separated by a single space. Each string should be composed of letters (a-z and A-Z: both lowercase and uppercase are allowed) and have length at most 200. The number of occurrences of p in s as a subsequence should be exactly n. If there are many possible solutions, output any of them. It is guaranteed that at least one solution exists. Examples Input 2 Output hHheidi Hei Input 4 Output bbbba ba Input 6 Output aaabb ab Note An occurrence of p as a subsequence in s should be thought of as a set of positions in s such that the letters at these positions, in order, form p. The number of occurences is thus the number of such sets. For example, ab appears 6 times as a subsequence in aaabb, for the following sets of positions: {1, 4}, {1, 5}, {2, 4}, {2, 5}, {3, 4}, {3, 5} (that is, we should choose one of the a's and one of the b's).
2
14
#include <bits/stdc++.h> using namespace std; int n; int op[200]; int cnt = 0; void dfs(int n, int k) { if (n == 0) { cnt = k; return; } if (n & 1) { dfs((n - 1) / 2, k + 1); op[k] = 1; } else { dfs((n - 2) / 2, k + 1); op[k] = 2; } } int main() { while (cin >> n) { dfs(n, 0); for (int i = 0; i < cnt; i++) { printf("%c", 'a' + i); } for (int i = 0; i < cnt; i++) { if (op[i] == 2) { printf("%c", 'a' + (cnt - i - 1)); } } for (int i = 1; i < cnt; i++) { printf("%c%c", 'a' + i, 'a' + i); } printf(" "); for (int i = 0; i < cnt; i++) { printf("%c", 'a' + i); } printf("\n"); } return 0; }
CPP
802_H. Fake News (medium)
Thanks to your help, Heidi is confident that no one can fool her. She has now decided to post some fake news on the HC2 Facebook page. However, she wants to be able to communicate to the HC2 committee that the post is fake, using some secret phrase hidden in the post as a subsequence. To make this method foolproof, she wants the phrase to appear n times in the post. She is asking you to design a post (string) s and a hidden phrase p such that p appears in s as a subsequence exactly n times. Input The first and only line of input contains a single integer n (1 ≤ n ≤ 1 000 000). Output The output should contain two nonempty strings s and p separated by a single space. Each string should be composed of letters (a-z and A-Z: both lowercase and uppercase are allowed) and have length at most 200. The number of occurrences of p in s as a subsequence should be exactly n. If there are many possible solutions, output any of them. It is guaranteed that at least one solution exists. Examples Input 2 Output hHheidi Hei Input 4 Output bbbba ba Input 6 Output aaabb ab Note An occurrence of p as a subsequence in s should be thought of as a set of positions in s such that the letters at these positions, in order, form p. The number of occurences is thus the number of such sets. For example, ab appears 6 times as a subsequence in aaabb, for the following sets of positions: {1, 4}, {1, 5}, {2, 4}, {2, 5}, {3, 4}, {3, 5} (that is, we should choose one of the a's and one of the b's).
2
14
#include <bits/stdc++.h> using namespace std; int n; char now; string s, t; void solve(int len) { if (len == 1) { s = ""; t = "a"; now = 'a'; return; } if (len == 2) { s = "b"; t = "ab"; now = 'b'; return; } if (len % 2 == 0) { solve(len / 2 - 1); now++; s = now + s + now + now; t = t + now; return; } if (len % 2 == 1) { solve(len / 2); now++; s = s + now + now; t = t + now; return; } } int main() { scanf("%d", &n); solve(n); cout << t << s << " " << t; return 0; }
CPP
802_H. Fake News (medium)
Thanks to your help, Heidi is confident that no one can fool her. She has now decided to post some fake news on the HC2 Facebook page. However, she wants to be able to communicate to the HC2 committee that the post is fake, using some secret phrase hidden in the post as a subsequence. To make this method foolproof, she wants the phrase to appear n times in the post. She is asking you to design a post (string) s and a hidden phrase p such that p appears in s as a subsequence exactly n times. Input The first and only line of input contains a single integer n (1 ≤ n ≤ 1 000 000). Output The output should contain two nonempty strings s and p separated by a single space. Each string should be composed of letters (a-z and A-Z: both lowercase and uppercase are allowed) and have length at most 200. The number of occurrences of p in s as a subsequence should be exactly n. If there are many possible solutions, output any of them. It is guaranteed that at least one solution exists. Examples Input 2 Output hHheidi Hei Input 4 Output bbbba ba Input 6 Output aaabb ab Note An occurrence of p as a subsequence in s should be thought of as a set of positions in s such that the letters at these positions, in order, form p. The number of occurences is thus the number of such sets. For example, ab appears 6 times as a subsequence in aaabb, for the following sets of positions: {1, 4}, {1, 5}, {2, 4}, {2, 5}, {3, 4}, {3, 5} (that is, we should choose one of the a's and one of the b's).
2
14
#include <bits/stdc++.h> using namespace std; const long long MOD = 1e9 + 7, INF = 9e18; const int inf = 2e9; vector<string> ans; string f(int l, int r) { string s = ""; for (int i = l; i <= r; i++) { s += (char)((int)'a' + i); } return s; } string f2(int l, int r) { string s = ""; for (int i = l; i <= r; i++) { s += (char)((int)'a' + i); s += (char)((int)'a' + i); } return s; } int bits(int n) { int r = 0; while (n) { n >>= 1; r++; } return r; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n, b; cin >> n; ans.push_back(f(1, 19)); int c = 0; while (n) { ans.push_back(f2(1, c)); if (n % 3 == 1) { ans.push_back("a"); } if (n % 3 == 2) { ans.push_back("aa"); } c++; n /= 3; } string s = ""; for (int i = ((int)ans.size()) - 1; i >= 0; i--) { s += ans[i]; } cout << s; cout << " " << f(0, 19); return 0; }
CPP
802_H. Fake News (medium)
Thanks to your help, Heidi is confident that no one can fool her. She has now decided to post some fake news on the HC2 Facebook page. However, she wants to be able to communicate to the HC2 committee that the post is fake, using some secret phrase hidden in the post as a subsequence. To make this method foolproof, she wants the phrase to appear n times in the post. She is asking you to design a post (string) s and a hidden phrase p such that p appears in s as a subsequence exactly n times. Input The first and only line of input contains a single integer n (1 ≤ n ≤ 1 000 000). Output The output should contain two nonempty strings s and p separated by a single space. Each string should be composed of letters (a-z and A-Z: both lowercase and uppercase are allowed) and have length at most 200. The number of occurrences of p in s as a subsequence should be exactly n. If there are many possible solutions, output any of them. It is guaranteed that at least one solution exists. Examples Input 2 Output hHheidi Hei Input 4 Output bbbba ba Input 6 Output aaabb ab Note An occurrence of p as a subsequence in s should be thought of as a set of positions in s such that the letters at these positions, in order, form p. The number of occurences is thus the number of such sets. For example, ab appears 6 times as a subsequence in aaabb, for the following sets of positions: {1, 4}, {1, 5}, {2, 4}, {2, 5}, {3, 4}, {3, 5} (that is, we should choose one of the a's and one of the b's).
2
14
#include <bits/stdc++.h> using namespace std; template <class T> int getbit(T s, int i) { return (s >> i) & 1; } template <class T> T onbit(T s, int i) { return s | (T(1) << i); } template <class T> T offbit(T s, int i) { return s & (~(T(1) << i)); } template <class T> int cntbit(T s) { return __builtin_popcnt(s); } template <class T> T gcd(T a, T b) { T r; while (b != 0) { r = a % b; a = b; b = r; } return a; } template <class T> T lcm(T a, T b) { return a / gcd(a, b) * b; } string s, temp; int main() { ios::sync_with_stdio(0); cin.tie(0); s = "abbabbb"; char cur = 'b'; for (int i = 5; i <= 19; i += 2) { temp = s; s = ""; int n = ((long long)(temp).size()); bool first = true; for (int j = 0; j < (n); ++j) { s.push_back(temp[j]); if (j != n - 2 && temp[j] == cur) { s.push_back(cur + 1); if (first) { s.push_back(cur + 1); first = false; } } } s.push_back(cur + 1); s.push_back(cur + 1); cur++; } int N; cin >> N; int n = ((long long)(s).size()); int run = 0; string res = ""; for (int i = 0; i < (n); ++i) { res.push_back(s[i]); if (i != n - 2 && s[i] == cur) { if (getbit(N, run)) { res.push_back(cur + 1); } run++; } } cout << res << " abcdefghijk" << endl; return 0; }
CPP
802_H. Fake News (medium)
Thanks to your help, Heidi is confident that no one can fool her. She has now decided to post some fake news on the HC2 Facebook page. However, she wants to be able to communicate to the HC2 committee that the post is fake, using some secret phrase hidden in the post as a subsequence. To make this method foolproof, she wants the phrase to appear n times in the post. She is asking you to design a post (string) s and a hidden phrase p such that p appears in s as a subsequence exactly n times. Input The first and only line of input contains a single integer n (1 ≤ n ≤ 1 000 000). Output The output should contain two nonempty strings s and p separated by a single space. Each string should be composed of letters (a-z and A-Z: both lowercase and uppercase are allowed) and have length at most 200. The number of occurrences of p in s as a subsequence should be exactly n. If there are many possible solutions, output any of them. It is guaranteed that at least one solution exists. Examples Input 2 Output hHheidi Hei Input 4 Output bbbba ba Input 6 Output aaabb ab Note An occurrence of p as a subsequence in s should be thought of as a set of positions in s such that the letters at these positions, in order, form p. The number of occurences is thus the number of such sets. For example, ab appears 6 times as a subsequence in aaabb, for the following sets of positions: {1, 4}, {1, 5}, {2, 4}, {2, 5}, {3, 4}, {3, 5} (that is, we should choose one of the a's and one of the b's).
2
14
#include <bits/stdc++.h> using namespace std; int n; string s, p; char c; void solve(int x) { if (x == 1) { s = "", p = "a", c = 'a'; return; } if (x == 2) { s = "b", p = "ab", c = 'b'; return; } if (!(x & 1)) { solve((x >> 1) - 1); ++c; s = c + s + c + c; p = p + c; return; } if (x & 1) { solve(x >> 1); ++c; s = s + c + c; p = p + c; return; } } int main() { scanf("%d", &n); solve(n); cout << p << s << " " << p << endl; return 0; }
CPP
802_H. Fake News (medium)
Thanks to your help, Heidi is confident that no one can fool her. She has now decided to post some fake news on the HC2 Facebook page. However, she wants to be able to communicate to the HC2 committee that the post is fake, using some secret phrase hidden in the post as a subsequence. To make this method foolproof, she wants the phrase to appear n times in the post. She is asking you to design a post (string) s and a hidden phrase p such that p appears in s as a subsequence exactly n times. Input The first and only line of input contains a single integer n (1 ≤ n ≤ 1 000 000). Output The output should contain two nonempty strings s and p separated by a single space. Each string should be composed of letters (a-z and A-Z: both lowercase and uppercase are allowed) and have length at most 200. The number of occurrences of p in s as a subsequence should be exactly n. If there are many possible solutions, output any of them. It is guaranteed that at least one solution exists. Examples Input 2 Output hHheidi Hei Input 4 Output bbbba ba Input 6 Output aaabb ab Note An occurrence of p as a subsequence in s should be thought of as a set of positions in s such that the letters at these positions, in order, form p. The number of occurences is thus the number of such sets. For example, ab appears 6 times as a subsequence in aaabb, for the following sets of positions: {1, 4}, {1, 5}, {2, 4}, {2, 5}, {3, 4}, {3, 5} (that is, we should choose one of the a's and one of the b's).
2
14
#include <bits/stdc++.h> using namespace std; const int N = 30; const int K = 4; int C[N + 1][K + 1]; int main() { for (int i = 0; i <= N; ++i) { for (int j = 0; j <= K; ++j) { if (i == 0 || j == 0) { C[i][j] = 1; } else { C[i][j] = C[i - 1][j] + C[i][j - 1]; } } } for (int i = 0; i <= N; ++i) { ; } int n; scanf("%d", &n); int it = N; while (n) { while (n < C[it][K]) { --it; for (int i = 0; i < K; ++i) { printf("%c", 'a' + i); } } n -= C[it][K]; printf("%c", 'a' + K); } while (it >= 0) { for (int i = 0; i < K; ++i) { printf("%c", 'a' + i); } --it; } printf(" %c", 'a' + K); for (int i = 0; i < K; ++i) { printf("%c", 'a' + i); } printf("\n"); return 0; }
CPP
802_H. Fake News (medium)
Thanks to your help, Heidi is confident that no one can fool her. She has now decided to post some fake news on the HC2 Facebook page. However, she wants to be able to communicate to the HC2 committee that the post is fake, using some secret phrase hidden in the post as a subsequence. To make this method foolproof, she wants the phrase to appear n times in the post. She is asking you to design a post (string) s and a hidden phrase p such that p appears in s as a subsequence exactly n times. Input The first and only line of input contains a single integer n (1 ≤ n ≤ 1 000 000). Output The output should contain two nonempty strings s and p separated by a single space. Each string should be composed of letters (a-z and A-Z: both lowercase and uppercase are allowed) and have length at most 200. The number of occurrences of p in s as a subsequence should be exactly n. If there are many possible solutions, output any of them. It is guaranteed that at least one solution exists. Examples Input 2 Output hHheidi Hei Input 4 Output bbbba ba Input 6 Output aaabb ab Note An occurrence of p as a subsequence in s should be thought of as a set of positions in s such that the letters at these positions, in order, form p. The number of occurences is thus the number of such sets. For example, ab appears 6 times as a subsequence in aaabb, for the following sets of positions: {1, 4}, {1, 5}, {2, 4}, {2, 5}, {3, 4}, {3, 5} (that is, we should choose one of the a's and one of the b's).
2
14
#include <bits/stdc++.h> using namespace std; int main() { string s; int cnt[6]; int val[105]; memset(cnt, 0, sizeof(cnt)); s += "abcde"; for (int i = 0; i < 95; i++) { s += (char)(rand() % 5 + 'a'); } for (int i = 0; s[i] != 0; i++) { if (s[i] == 'a') cnt[0]++; else cnt[s[i] - 'a'] += cnt[s[i] - 'a' - 1]; val[i] = cnt[4]; } int n; scanf("%d", &n); int ans[105]; memset(ans, 0, sizeof(ans)); int tmp = n; for (int k = 99; k >= 0; k--) { ans[k] = tmp / val[k]; tmp %= val[k]; if (tmp == 0) break; } string s2; for (int i = 0; i < 100; i++) { printf("%c", s[i]); s2 += s[i]; for (int j = 0; j < ans[i]; j++) printf("f"), s2 += 'f'; } printf(" abcdef\n"); memset(cnt, 0, sizeof(cnt)); for (int i = 0; s2[i] != 0; i++) { if (s2[i] == 'a') cnt[0]++; else cnt[s2[i] - 'a'] += cnt[s2[i] - 'a' - 1]; } assert(cnt[5] == n); }
CPP
802_H. Fake News (medium)
Thanks to your help, Heidi is confident that no one can fool her. She has now decided to post some fake news on the HC2 Facebook page. However, she wants to be able to communicate to the HC2 committee that the post is fake, using some secret phrase hidden in the post as a subsequence. To make this method foolproof, she wants the phrase to appear n times in the post. She is asking you to design a post (string) s and a hidden phrase p such that p appears in s as a subsequence exactly n times. Input The first and only line of input contains a single integer n (1 ≤ n ≤ 1 000 000). Output The output should contain two nonempty strings s and p separated by a single space. Each string should be composed of letters (a-z and A-Z: both lowercase and uppercase are allowed) and have length at most 200. The number of occurrences of p in s as a subsequence should be exactly n. If there are many possible solutions, output any of them. It is guaranteed that at least one solution exists. Examples Input 2 Output hHheidi Hei Input 4 Output bbbba ba Input 6 Output aaabb ab Note An occurrence of p as a subsequence in s should be thought of as a set of positions in s such that the letters at these positions, in order, form p. The number of occurences is thus the number of such sets. For example, ab appears 6 times as a subsequence in aaabb, for the following sets of positions: {1, 4}, {1, 5}, {2, 4}, {2, 5}, {3, 4}, {3, 5} (that is, we should choose one of the a's and one of the b's).
2
14
#include <bits/stdc++.h> using namespace std; using ll = long long; ll comb(ll n, ll k) { ll res = 1; for (int i = 0; i < k; i++) { res *= (n - i); } for (int i = 1; i <= k; i++) { res /= i; } return res; } int main() { ll n; cin >> n; string res; for (int i = 30; i >= 0; i--) { ll a = n / comb(i + 5, 5); n -= a * comb(i + 5, 5); for (int j = 0; j < a; j++) res += "a"; res += "bcdef"; } assert(res.size() <= 200); cout << res << " " << "abcdef" << endl; return 0; }
CPP
802_H. Fake News (medium)
Thanks to your help, Heidi is confident that no one can fool her. She has now decided to post some fake news on the HC2 Facebook page. However, she wants to be able to communicate to the HC2 committee that the post is fake, using some secret phrase hidden in the post as a subsequence. To make this method foolproof, she wants the phrase to appear n times in the post. She is asking you to design a post (string) s and a hidden phrase p such that p appears in s as a subsequence exactly n times. Input The first and only line of input contains a single integer n (1 ≤ n ≤ 1 000 000). Output The output should contain two nonempty strings s and p separated by a single space. Each string should be composed of letters (a-z and A-Z: both lowercase and uppercase are allowed) and have length at most 200. The number of occurrences of p in s as a subsequence should be exactly n. If there are many possible solutions, output any of them. It is guaranteed that at least one solution exists. Examples Input 2 Output hHheidi Hei Input 4 Output bbbba ba Input 6 Output aaabb ab Note An occurrence of p as a subsequence in s should be thought of as a set of positions in s such that the letters at these positions, in order, form p. The number of occurences is thus the number of such sets. For example, ab appears 6 times as a subsequence in aaabb, for the following sets of positions: {1, 4}, {1, 5}, {2, 4}, {2, 5}, {3, 4}, {3, 5} (that is, we should choose one of the a's and one of the b's).
2
14
#include <bits/stdc++.h> using namespace std; template <class S, class T> ostream& operator<<(ostream& o, const pair<S, T>& p) { return o << "(" << p.first << "," << p.second << ")"; } template <class T> ostream& operator<<(ostream& o, const vector<T>& vc) { o << "sz = " << vc.size() << endl << "["; for (const T& v : vc) o << v << ","; o << "]"; return o; } int main() { int Xo; cin >> Xo; for (int N = 4; N <= 7; N++) { int X = Xo; vector<int> vs; vector<long long> a(N + 1); a[0] = 1; for (int i = 0; i < (int)(100); i++) { for (int j = 0; j < (int)(N); j++) a[j + 1] += a[j]; if (a[N] > 1e6) break; vs.push_back(a[N]); } int K = vs.size(); string pat; for (int i = 0; i < (int)(N + 1); i++) pat += 'a' + i; string ans; for (int i = K - 1; i >= 0; i--) { int v = vs[i]; int q = X / v; X %= v; ans += string(q, pat[N]); if (ans.empty()) continue; for (int j = N - 1; j >= 0; j--) ans += pat[j]; } if (ans.size() > 200) continue; reverse(ans.begin(), ans.end()); cout << ans << " " << pat << endl; return 0; } }
CPP
802_H. Fake News (medium)
Thanks to your help, Heidi is confident that no one can fool her. She has now decided to post some fake news on the HC2 Facebook page. However, she wants to be able to communicate to the HC2 committee that the post is fake, using some secret phrase hidden in the post as a subsequence. To make this method foolproof, she wants the phrase to appear n times in the post. She is asking you to design a post (string) s and a hidden phrase p such that p appears in s as a subsequence exactly n times. Input The first and only line of input contains a single integer n (1 ≤ n ≤ 1 000 000). Output The output should contain two nonempty strings s and p separated by a single space. Each string should be composed of letters (a-z and A-Z: both lowercase and uppercase are allowed) and have length at most 200. The number of occurrences of p in s as a subsequence should be exactly n. If there are many possible solutions, output any of them. It is guaranteed that at least one solution exists. Examples Input 2 Output hHheidi Hei Input 4 Output bbbba ba Input 6 Output aaabb ab Note An occurrence of p as a subsequence in s should be thought of as a set of positions in s such that the letters at these positions, in order, form p. The number of occurences is thus the number of such sets. For example, ab appears 6 times as a subsequence in aaabb, for the following sets of positions: {1, 4}, {1, 5}, {2, 4}, {2, 5}, {3, 4}, {3, 5} (that is, we should choose one of the a's and one of the b's).
2
14
#include <bits/stdc++.h> using namespace std; long long int power(long long int x, long long int y) { long long int res = 1; while (y) { if (y & 1) res = (res * x) % 1000000007; y = y / 2, x = (x * x) % 1000000007; } return res % 1000000007; } pair<string, pair<string, string> > func(long long int n) { if (n == 1) return make_pair("a", make_pair("", "a")); else if (n == 2) return make_pair("a", make_pair("a", "a")); long long int val = (n - 1) / 2; pair<string, pair<string, string> > done = func(val); string s = ""; s += (done.second.second[done.second.second.length() - 1] + 1); if (2 * val + 1 == n) return make_pair(done.first + s, make_pair(done.second.first + s + s, done.second.second + s)); else return make_pair(done.first + s, make_pair(s + done.second.first + s + s, done.second.second + s)); } signed main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); long long int n; cin >> n; pair<string, pair<string, string> > done = func(n); cout << (done.first + done.second.first) << " " << done.second.second; }
CPP
802_H. Fake News (medium)
Thanks to your help, Heidi is confident that no one can fool her. She has now decided to post some fake news on the HC2 Facebook page. However, she wants to be able to communicate to the HC2 committee that the post is fake, using some secret phrase hidden in the post as a subsequence. To make this method foolproof, she wants the phrase to appear n times in the post. She is asking you to design a post (string) s and a hidden phrase p such that p appears in s as a subsequence exactly n times. Input The first and only line of input contains a single integer n (1 ≤ n ≤ 1 000 000). Output The output should contain two nonempty strings s and p separated by a single space. Each string should be composed of letters (a-z and A-Z: both lowercase and uppercase are allowed) and have length at most 200. The number of occurrences of p in s as a subsequence should be exactly n. If there are many possible solutions, output any of them. It is guaranteed that at least one solution exists. Examples Input 2 Output hHheidi Hei Input 4 Output bbbba ba Input 6 Output aaabb ab Note An occurrence of p as a subsequence in s should be thought of as a set of positions in s such that the letters at these positions, in order, form p. The number of occurences is thus the number of such sets. For example, ab appears 6 times as a subsequence in aaabb, for the following sets of positions: {1, 4}, {1, 5}, {2, 4}, {2, 5}, {3, 4}, {3, 5} (that is, we should choose one of the a's and one of the b's).
2
14
#include <bits/stdc++.h> using namespace std; char str[200], ans[201]; int dp[200], ins[200]; int main() { int n; cin >> n; for (int i = 0; i < 120; i += 4) { str[i] = 'a'; str[i + 1] = 'b'; str[i + 2] = 'c'; str[i + 3] = 'd'; if (i) { dp[i] = dp[i - 4] + 1; dp[i + 1] = dp[i - 3] + dp[i]; dp[i + 2] = dp[i - 2] + dp[i + 1]; dp[i + 3] = dp[i + 2] + dp[i - 1]; } else { dp[i] = dp[i + 1] = dp[i + 2] = dp[i + 3] = 1; } } for (int i = 119; n && i > -1; i -= 4) { if (dp[i] <= n) { ins[i] = n / dp[i]; n %= dp[i]; } } for (int i = 0, dif = 0; i < 200; i++) { ans[i + dif] = str[i]; for (int j = 0; j < ins[i]; j++) ans[i + (++dif)] = 'e'; } cout << ans << "\tabcde" << endl; return 0; }
CPP
802_H. Fake News (medium)
Thanks to your help, Heidi is confident that no one can fool her. She has now decided to post some fake news on the HC2 Facebook page. However, she wants to be able to communicate to the HC2 committee that the post is fake, using some secret phrase hidden in the post as a subsequence. To make this method foolproof, she wants the phrase to appear n times in the post. She is asking you to design a post (string) s and a hidden phrase p such that p appears in s as a subsequence exactly n times. Input The first and only line of input contains a single integer n (1 ≤ n ≤ 1 000 000). Output The output should contain two nonempty strings s and p separated by a single space. Each string should be composed of letters (a-z and A-Z: both lowercase and uppercase are allowed) and have length at most 200. The number of occurrences of p in s as a subsequence should be exactly n. If there are many possible solutions, output any of them. It is guaranteed that at least one solution exists. Examples Input 2 Output hHheidi Hei Input 4 Output bbbba ba Input 6 Output aaabb ab Note An occurrence of p as a subsequence in s should be thought of as a set of positions in s such that the letters at these positions, in order, form p. The number of occurences is thus the number of such sets. For example, ab appears 6 times as a subsequence in aaabb, for the following sets of positions: {1, 4}, {1, 5}, {2, 4}, {2, 5}, {3, 4}, {3, 5} (that is, we should choose one of the a's and one of the b's).
2
14
#include <bits/stdc++.h> using namespace std; inline int read() { int x = 0, f = 1; char ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); } return x * f; } int num[50 + 5], n, C[50 + 5][6]; int main() { n = read(); C[0][0] = 1; for (int i = 1; i <= 50; ++i) { C[i][0] = 1; for (int j = 1; j <= 5; ++j) C[i][j] = C[i - 1][j] + C[i - 1][j - 1]; } for (int i = 50; i >= 5; --i) while (n >= C[i][5]) n -= C[i][5], ++num[i]; for (int i = 0; i <= 50; putchar('a'), ++i) for (int j = 1; j <= num[i]; ++j) putchar('b'); printf(" aaaaab"); return 0; }
CPP
802_H. Fake News (medium)
Thanks to your help, Heidi is confident that no one can fool her. She has now decided to post some fake news on the HC2 Facebook page. However, she wants to be able to communicate to the HC2 committee that the post is fake, using some secret phrase hidden in the post as a subsequence. To make this method foolproof, she wants the phrase to appear n times in the post. She is asking you to design a post (string) s and a hidden phrase p such that p appears in s as a subsequence exactly n times. Input The first and only line of input contains a single integer n (1 ≤ n ≤ 1 000 000). Output The output should contain two nonempty strings s and p separated by a single space. Each string should be composed of letters (a-z and A-Z: both lowercase and uppercase are allowed) and have length at most 200. The number of occurrences of p in s as a subsequence should be exactly n. If there are many possible solutions, output any of them. It is guaranteed that at least one solution exists. Examples Input 2 Output hHheidi Hei Input 4 Output bbbba ba Input 6 Output aaabb ab Note An occurrence of p as a subsequence in s should be thought of as a set of positions in s such that the letters at these positions, in order, form p. The number of occurences is thus the number of such sets. For example, ab appears 6 times as a subsequence in aaabb, for the following sets of positions: {1, 4}, {1, 5}, {2, 4}, {2, 5}, {3, 4}, {3, 5} (that is, we should choose one of the a's and one of the b's).
2
14
#include <bits/stdc++.h> using namespace std; int inline read() { int x = 0, f = 1; char ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); } return x * f; } int jilu[12], n, i, j, cnt; int main() { n = read(); while (n >= 92378) { jilu[10]++; n -= 92378; } while (n >= 48620) { jilu[9]++; n -= 48620; } while (n >= 24310) { jilu[8]++; n -= 24310; } while (n >= 11440) { jilu[7]++; n -= 11440; } while (n >= 5005) { jilu[6]++; n -= 5005; } while (n >= 2002) { jilu[5]++; n -= 2002; } while (n >= 715) { jilu[4]++; n -= 715; } while (n >= 220) { jilu[3]++; n -= 220; } while (n >= 55) { jilu[2]++; n -= 55; } while (n >= 10) { jilu[1]++; n -= 10; } while (n >= 1) { jilu[0]++; n -= 1; } for (i = 0; i <= 10; i++) { cout << "abcdefghi"; cnt += 9; for (j = 1; j <= jilu[i]; j++) cout << "j"; cnt += jilu[i]; } for (i = 1; i <= 200 - cnt; i++) cout << "k"; cout << " abcdefghij"; }
CPP
802_H. Fake News (medium)
Thanks to your help, Heidi is confident that no one can fool her. She has now decided to post some fake news on the HC2 Facebook page. However, she wants to be able to communicate to the HC2 committee that the post is fake, using some secret phrase hidden in the post as a subsequence. To make this method foolproof, she wants the phrase to appear n times in the post. She is asking you to design a post (string) s and a hidden phrase p such that p appears in s as a subsequence exactly n times. Input The first and only line of input contains a single integer n (1 ≤ n ≤ 1 000 000). Output The output should contain two nonempty strings s and p separated by a single space. Each string should be composed of letters (a-z and A-Z: both lowercase and uppercase are allowed) and have length at most 200. The number of occurrences of p in s as a subsequence should be exactly n. If there are many possible solutions, output any of them. It is guaranteed that at least one solution exists. Examples Input 2 Output hHheidi Hei Input 4 Output bbbba ba Input 6 Output aaabb ab Note An occurrence of p as a subsequence in s should be thought of as a set of positions in s such that the letters at these positions, in order, form p. The number of occurences is thus the number of such sets. For example, ab appears 6 times as a subsequence in aaabb, for the following sets of positions: {1, 4}, {1, 5}, {2, 4}, {2, 5}, {3, 4}, {3, 5} (that is, we should choose one of the a's and one of the b's).
2
14
#include <bits/stdc++.h> using namespace std; const int maxn = 201; int a[maxn]; char t[maxn], s[maxn]; char c[30] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D'}; int main() { int n; scanf("%d", &n); int cnt = 0; a[cnt++] = n; while (n != 1 && n != 0) { if (n % 2 == 0) { n /= 2; a[cnt++] = --n; } else { n--; n /= 2; a[cnt++] = n; } } for (int i = 0; i < cnt; i++) { } memset(t, '\0', sizeof(t)); memset(s, '\0', sizeof(s)); int p, q, r, i; if (a[cnt - 1] == 1) { t[0] = s[0] = 'a'; r = 1; p = q = 1; i = cnt - 2; } else if (a[cnt - 1] == 0) { t[0] = 'a'; t[1] = t[2] = 'b'; s[0] = 'a'; s[1] = 'b'; r = 2; p = 3; q = 2; i = cnt - 3; } for (; i >= 0; i--, r++) { if (a[i] == a[i + 1] * 2 + 2) { int l = strlen(t); l += 4; t[l - 1] = t[l - 2] = c[r]; for (int k = l - 3; k >= r + 2; k--) { t[k] = t[k - 2]; } t[r] = t[r + 1] = c[r]; p = l; } else if (a[i] == a[i + 1] * 2 + 1) { int l = strlen(t); l += 3; t[l - 1] = t[l - 2] = c[r]; for (int k = l - 3; k >= r + 1; k--) { t[k] = t[k - 1]; } t[r] = c[r]; p = l; } s[q++] = c[r]; } printf("%s %s\n", t, s); return 0; }
CPP
802_H. Fake News (medium)
Thanks to your help, Heidi is confident that no one can fool her. She has now decided to post some fake news on the HC2 Facebook page. However, she wants to be able to communicate to the HC2 committee that the post is fake, using some secret phrase hidden in the post as a subsequence. To make this method foolproof, she wants the phrase to appear n times in the post. She is asking you to design a post (string) s and a hidden phrase p such that p appears in s as a subsequence exactly n times. Input The first and only line of input contains a single integer n (1 ≤ n ≤ 1 000 000). Output The output should contain two nonempty strings s and p separated by a single space. Each string should be composed of letters (a-z and A-Z: both lowercase and uppercase are allowed) and have length at most 200. The number of occurrences of p in s as a subsequence should be exactly n. If there are many possible solutions, output any of them. It is guaranteed that at least one solution exists. Examples Input 2 Output hHheidi Hei Input 4 Output bbbba ba Input 6 Output aaabb ab Note An occurrence of p as a subsequence in s should be thought of as a set of positions in s such that the letters at these positions, in order, form p. The number of occurences is thus the number of such sets. For example, ab appears 6 times as a subsequence in aaabb, for the following sets of positions: {1, 4}, {1, 5}, {2, 4}, {2, 5}, {3, 4}, {3, 5} (that is, we should choose one of the a's and one of the b's).
2
14
#include <bits/stdc++.h> using namespace std; long long n; long long fac[200005]; vector<char> vr; long long check(long long x) { vr.clear(); long long temp = n, st = -1; for (int i = x;; i++) { long long pr = 1; for (int j = i; j > i - x; j--) pr = pr * j; pr /= fac[x]; if (pr > temp) { st = i - 1; break; } } if (st == -1) return 0; for (int i = st; i >= x; i--) { long long pr = 1; for (int j = i; j > i - x; j--) pr = pr * j; pr /= fac[x]; while (pr <= temp) { temp -= pr; vr.push_back('b'); } vr.push_back('a'); } for (int i = 1; i < x; i++) vr.push_back('a'); return vr.size() <= 200; } int main() { fac[0] = 1; for (int i = 1; i < 11; i++) fac[i] = fac[i - 1] * i; scanf("%lld", &n); long long st = 2; while (1) { if (check(st)) { reverse(vr.begin(), vr.end()); for (int i = 0; i < vr.size(); i++) cout << vr[i]; cout << " "; for (int i = 0; i < st; i++) cout << 'a'; cout << 'b'; break; } st++; } }
CPP
802_H. Fake News (medium)
Thanks to your help, Heidi is confident that no one can fool her. She has now decided to post some fake news on the HC2 Facebook page. However, she wants to be able to communicate to the HC2 committee that the post is fake, using some secret phrase hidden in the post as a subsequence. To make this method foolproof, she wants the phrase to appear n times in the post. She is asking you to design a post (string) s and a hidden phrase p such that p appears in s as a subsequence exactly n times. Input The first and only line of input contains a single integer n (1 ≤ n ≤ 1 000 000). Output The output should contain two nonempty strings s and p separated by a single space. Each string should be composed of letters (a-z and A-Z: both lowercase and uppercase are allowed) and have length at most 200. The number of occurrences of p in s as a subsequence should be exactly n. If there are many possible solutions, output any of them. It is guaranteed that at least one solution exists. Examples Input 2 Output hHheidi Hei Input 4 Output bbbba ba Input 6 Output aaabb ab Note An occurrence of p as a subsequence in s should be thought of as a set of positions in s such that the letters at these positions, in order, form p. The number of occurences is thus the number of such sets. For example, ab appears 6 times as a subsequence in aaabb, for the following sets of positions: {1, 4}, {1, 5}, {2, 4}, {2, 5}, {3, 4}, {3, 5} (that is, we should choose one of the a's and one of the b's).
2
14
#include <bits/stdc++.h> using namespace std; string s1, s2, a = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; int n, cnt; int main() { cin >> n; while (--n) { if (n % 2) { s1 = s1 + a[cnt]; ++cnt; } else { s1 = s1 + a[cnt] + a[cnt]; ++cnt; n /= 2; } } for (int i = 0; i <= cnt; ++i) s2 += a[i]; cout << s1 + s2 << ' ' << s2; }
CPP
802_H. Fake News (medium)
Thanks to your help, Heidi is confident that no one can fool her. She has now decided to post some fake news on the HC2 Facebook page. However, she wants to be able to communicate to the HC2 committee that the post is fake, using some secret phrase hidden in the post as a subsequence. To make this method foolproof, she wants the phrase to appear n times in the post. She is asking you to design a post (string) s and a hidden phrase p such that p appears in s as a subsequence exactly n times. Input The first and only line of input contains a single integer n (1 ≤ n ≤ 1 000 000). Output The output should contain two nonempty strings s and p separated by a single space. Each string should be composed of letters (a-z and A-Z: both lowercase and uppercase are allowed) and have length at most 200. The number of occurrences of p in s as a subsequence should be exactly n. If there are many possible solutions, output any of them. It is guaranteed that at least one solution exists. Examples Input 2 Output hHheidi Hei Input 4 Output bbbba ba Input 6 Output aaabb ab Note An occurrence of p as a subsequence in s should be thought of as a set of positions in s such that the letters at these positions, in order, form p. The number of occurences is thus the number of such sets. For example, ab appears 6 times as a subsequence in aaabb, for the following sets of positions: {1, 4}, {1, 5}, {2, 4}, {2, 5}, {3, 4}, {3, 5} (that is, we should choose one of the a's and one of the b's).
2
14
#include <bits/stdc++.h> using namespace std; long long n; char now; string s, t; void work(int len) { if (len == 1) { s = ""; t = "a"; now = 'a'; return; } if (len == 2) { s = "b"; t = "ab"; now = 'b'; return; } if (len % 2 == 0) { work(len / 2 - 1); now++; s = now + s + now + now; t = t + now; return; } if (len % 2) { work(len / 2); now++; s = s + now + now; t = t + now; return; } } int main() { cin >> n; work(n); cout << t << s << " " << t; return 0; }
CPP
802_H. Fake News (medium)
Thanks to your help, Heidi is confident that no one can fool her. She has now decided to post some fake news on the HC2 Facebook page. However, she wants to be able to communicate to the HC2 committee that the post is fake, using some secret phrase hidden in the post as a subsequence. To make this method foolproof, she wants the phrase to appear n times in the post. She is asking you to design a post (string) s and a hidden phrase p such that p appears in s as a subsequence exactly n times. Input The first and only line of input contains a single integer n (1 ≤ n ≤ 1 000 000). Output The output should contain two nonempty strings s and p separated by a single space. Each string should be composed of letters (a-z and A-Z: both lowercase and uppercase are allowed) and have length at most 200. The number of occurrences of p in s as a subsequence should be exactly n. If there are many possible solutions, output any of them. It is guaranteed that at least one solution exists. Examples Input 2 Output hHheidi Hei Input 4 Output bbbba ba Input 6 Output aaabb ab Note An occurrence of p as a subsequence in s should be thought of as a set of positions in s such that the letters at these positions, in order, form p. The number of occurences is thus the number of such sets. For example, ab appears 6 times as a subsequence in aaabb, for the following sets of positions: {1, 4}, {1, 5}, {2, 4}, {2, 5}, {3, 4}, {3, 5} (that is, we should choose one of the a's and one of the b's).
2
14
#include <bits/stdc++.h> using namespace std; int n; char now; string s, t; void dd(int l) { if (l == 1) { s = ""; t = "a"; now = 'a'; return; } if (l == 2) { s = "b"; t = "ab"; now = 'b'; return; } if (l % 2 == 0) { dd(l / 2 - 1); now++; s = now + s + now + now; t = t + now; return; } else { dd(l / 2); now++; s = s + now + now; t = t + now; return; } } int main() { scanf("%d", &n); dd(n); cout << t << s << " " << t; return 0; }
CPP
802_H. Fake News (medium)
Thanks to your help, Heidi is confident that no one can fool her. She has now decided to post some fake news on the HC2 Facebook page. However, she wants to be able to communicate to the HC2 committee that the post is fake, using some secret phrase hidden in the post as a subsequence. To make this method foolproof, she wants the phrase to appear n times in the post. She is asking you to design a post (string) s and a hidden phrase p such that p appears in s as a subsequence exactly n times. Input The first and only line of input contains a single integer n (1 ≤ n ≤ 1 000 000). Output The output should contain two nonempty strings s and p separated by a single space. Each string should be composed of letters (a-z and A-Z: both lowercase and uppercase are allowed) and have length at most 200. The number of occurrences of p in s as a subsequence should be exactly n. If there are many possible solutions, output any of them. It is guaranteed that at least one solution exists. Examples Input 2 Output hHheidi Hei Input 4 Output bbbba ba Input 6 Output aaabb ab Note An occurrence of p as a subsequence in s should be thought of as a set of positions in s such that the letters at these positions, in order, form p. The number of occurences is thus the number of such sets. For example, ab appears 6 times as a subsequence in aaabb, for the following sets of positions: {1, 4}, {1, 5}, {2, 4}, {2, 5}, {3, 4}, {3, 5} (that is, we should choose one of the a's and one of the b's).
2
14
#include <bits/stdc++.h> using namespace std; const char alpha[70] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; int main() { int n; scanf("%d", &n); int p = 0; int cnt[205] = {0}; if (n == 1) { printf("a a\n"); return 0; } while (n != 1) { n--; if (n % 2 == 0) { cnt[p] = 2; n /= 2; p++; } else { cnt[p] = 1; p++; } } for (int i = 0; i < p; i++) for (int j = 0; j < cnt[i]; j++) printf("%c", alpha[i]); for (int i = 0; i < p; i++) printf("%c", alpha[i]); printf(" "); for (int i = 0; i < p; i++) printf("%c", alpha[i]); return 0; }
CPP
802_H. Fake News (medium)
Thanks to your help, Heidi is confident that no one can fool her. She has now decided to post some fake news on the HC2 Facebook page. However, she wants to be able to communicate to the HC2 committee that the post is fake, using some secret phrase hidden in the post as a subsequence. To make this method foolproof, she wants the phrase to appear n times in the post. She is asking you to design a post (string) s and a hidden phrase p such that p appears in s as a subsequence exactly n times. Input The first and only line of input contains a single integer n (1 ≤ n ≤ 1 000 000). Output The output should contain two nonempty strings s and p separated by a single space. Each string should be composed of letters (a-z and A-Z: both lowercase and uppercase are allowed) and have length at most 200. The number of occurrences of p in s as a subsequence should be exactly n. If there are many possible solutions, output any of them. It is guaranteed that at least one solution exists. Examples Input 2 Output hHheidi Hei Input 4 Output bbbba ba Input 6 Output aaabb ab Note An occurrence of p as a subsequence in s should be thought of as a set of positions in s such that the letters at these positions, in order, form p. The number of occurences is thus the number of such sets. For example, ab appears 6 times as a subsequence in aaabb, for the following sets of positions: {1, 4}, {1, 5}, {2, 4}, {2, 5}, {3, 4}, {3, 5} (that is, we should choose one of the a's and one of the b's).
2
14
#include <bits/stdc++.h> using namespace std; const int N = 100; long long binom[N][N]; int main() { ios_base::sync_with_stdio(0), cin.tie(0); for (int i = 0; i < N; i++) { binom[i][0] = binom[i][i] = 1; for (int j = 1; j < i; j++) binom[i][j] = binom[i - 1][j] + binom[i - 1][j - 1]; } int n; cin >> n; vector<int> ans; for (int i = 30; i > 0; i--) { while (binom[i][8] <= n && n > 0) { n -= binom[i][8]; ans.push_back(1); } ans.push_back(0); } reverse(ans.begin(), ans.end()); for (int i : ans) { if (i == 0) cout << 'a'; else cout << 'b'; } cout << " aaaaaaaab" << endl; return 0; }
CPP
802_H. Fake News (medium)
Thanks to your help, Heidi is confident that no one can fool her. She has now decided to post some fake news on the HC2 Facebook page. However, she wants to be able to communicate to the HC2 committee that the post is fake, using some secret phrase hidden in the post as a subsequence. To make this method foolproof, she wants the phrase to appear n times in the post. She is asking you to design a post (string) s and a hidden phrase p such that p appears in s as a subsequence exactly n times. Input The first and only line of input contains a single integer n (1 ≤ n ≤ 1 000 000). Output The output should contain two nonempty strings s and p separated by a single space. Each string should be composed of letters (a-z and A-Z: both lowercase and uppercase are allowed) and have length at most 200. The number of occurrences of p in s as a subsequence should be exactly n. If there are many possible solutions, output any of them. It is guaranteed that at least one solution exists. Examples Input 2 Output hHheidi Hei Input 4 Output bbbba ba Input 6 Output aaabb ab Note An occurrence of p as a subsequence in s should be thought of as a set of positions in s such that the letters at these positions, in order, form p. The number of occurences is thus the number of such sets. For example, ab appears 6 times as a subsequence in aaabb, for the following sets of positions: {1, 4}, {1, 5}, {2, 4}, {2, 5}, {3, 4}, {3, 5} (that is, we should choose one of the a's and one of the b's).
2
14
#include <bits/stdc++.h> using namespace std; const int MAXS = 201; int N; char letter; char s[MAXS], p[MAXS]; void solve(int n) { if (n == 1) { s[0] = 'a'; p[0] = 'a'; letter = 'b'; return; } if (n == 2) { s[0] = s[1] = 'a'; p[0] = 'a'; letter = 'b'; return; } if (n % 2 == 0) { solve((n - 2) / 2); for (int i = strlen(s) + 1; i > (int)strlen(p) + 1; i--) s[i] = s[max(i - 2, 0)]; s[strlen(p)] = letter; s[strlen(p) + 1] = letter; s[strlen(s)] = letter; s[strlen(s)] = letter; p[strlen(p)] = letter; } else { solve((n - 1) / 2); for (int i = strlen(s); i > (int)strlen(p); i--) s[i] = s[i - 1]; s[strlen(p)] = letter; s[strlen(s)] = letter; s[strlen(s)] = letter; p[strlen(p)] = letter; } letter++; } int main() { scanf("%d", &N); solve(N); printf("%s %s\n", s, p); }
CPP
802_H. Fake News (medium)
Thanks to your help, Heidi is confident that no one can fool her. She has now decided to post some fake news on the HC2 Facebook page. However, she wants to be able to communicate to the HC2 committee that the post is fake, using some secret phrase hidden in the post as a subsequence. To make this method foolproof, she wants the phrase to appear n times in the post. She is asking you to design a post (string) s and a hidden phrase p such that p appears in s as a subsequence exactly n times. Input The first and only line of input contains a single integer n (1 ≤ n ≤ 1 000 000). Output The output should contain two nonempty strings s and p separated by a single space. Each string should be composed of letters (a-z and A-Z: both lowercase and uppercase are allowed) and have length at most 200. The number of occurrences of p in s as a subsequence should be exactly n. If there are many possible solutions, output any of them. It is guaranteed that at least one solution exists. Examples Input 2 Output hHheidi Hei Input 4 Output bbbba ba Input 6 Output aaabb ab Note An occurrence of p as a subsequence in s should be thought of as a set of positions in s such that the letters at these positions, in order, form p. The number of occurences is thus the number of such sets. For example, ab appears 6 times as a subsequence in aaabb, for the following sets of positions: {1, 4}, {1, 5}, {2, 4}, {2, 5}, {3, 4}, {3, 5} (that is, we should choose one of the a's and one of the b's).
2
14
#include <bits/stdc++.h> using namespace std; template <class T1, class T2> istream &operator>>(istream &is, pair<T1, T2> &p) { return is >> p.first >> p.second; } template <class T1, class T2> ostream &operator<<(ostream &os, pair<T1, T2> &p) { return os << p.first << " " << p.second; } pair<string, string> solve(int n, char c) { if (!n) return {string(), string()}; if (n == 1) return {string() + c, string()}; if (n == 2) return {string() + c, string() + c}; pair<string, string> t = solve((n - 1) / 2, c - 1); t.first += c; t.second += c; t.second += c; if (n & 1) return t; return {t.first, c + t.second}; } signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; cin >> n; pair<string, string> res = solve(n, 'z'); cout << res.first << res.second << " " << res.first; }
CPP
802_H. Fake News (medium)
Thanks to your help, Heidi is confident that no one can fool her. She has now decided to post some fake news on the HC2 Facebook page. However, she wants to be able to communicate to the HC2 committee that the post is fake, using some secret phrase hidden in the post as a subsequence. To make this method foolproof, she wants the phrase to appear n times in the post. She is asking you to design a post (string) s and a hidden phrase p such that p appears in s as a subsequence exactly n times. Input The first and only line of input contains a single integer n (1 ≤ n ≤ 1 000 000). Output The output should contain two nonempty strings s and p separated by a single space. Each string should be composed of letters (a-z and A-Z: both lowercase and uppercase are allowed) and have length at most 200. The number of occurrences of p in s as a subsequence should be exactly n. If there are many possible solutions, output any of them. It is guaranteed that at least one solution exists. Examples Input 2 Output hHheidi Hei Input 4 Output bbbba ba Input 6 Output aaabb ab Note An occurrence of p as a subsequence in s should be thought of as a set of positions in s such that the letters at these positions, in order, form p. The number of occurences is thus the number of such sets. For example, ab appears 6 times as a subsequence in aaabb, for the following sets of positions: {1, 4}, {1, 5}, {2, 4}, {2, 5}, {3, 4}, {3, 5} (that is, we should choose one of the a's and one of the b's).
2
14
import java.io.*; import java.util.*; public class fake_news_medium { public static void main(String hi[]) throws Exception { BufferedReader infile = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(infile.readLine()); int N = Integer.parseInt(st.nextToken()); int[] cnt = new int[200]; while(N > 0) { int low = 3; int high = 200; while(low != high) { int mid = (low+high+1)/2; if(val(mid) > N) high = mid-1; else low = mid; } N -= val(low); cnt[low]++; } int max = 0; for(int v=1; v < 200; v++) if(cnt[v] > 0) max = v; StringBuilder sb = new StringBuilder("aa"); for(int v=3; v < 200; v++) { if(max >= v) sb.append("a"); while(cnt[v]-->0) sb.append("b"); } sb.append(" aaab"); System.out.println(sb); } public static long val(long x) { return x*(x-1)*(x-2)/6; } }
JAVA
802_H. Fake News (medium)
Thanks to your help, Heidi is confident that no one can fool her. She has now decided to post some fake news on the HC2 Facebook page. However, she wants to be able to communicate to the HC2 committee that the post is fake, using some secret phrase hidden in the post as a subsequence. To make this method foolproof, she wants the phrase to appear n times in the post. She is asking you to design a post (string) s and a hidden phrase p such that p appears in s as a subsequence exactly n times. Input The first and only line of input contains a single integer n (1 ≤ n ≤ 1 000 000). Output The output should contain two nonempty strings s and p separated by a single space. Each string should be composed of letters (a-z and A-Z: both lowercase and uppercase are allowed) and have length at most 200. The number of occurrences of p in s as a subsequence should be exactly n. If there are many possible solutions, output any of them. It is guaranteed that at least one solution exists. Examples Input 2 Output hHheidi Hei Input 4 Output bbbba ba Input 6 Output aaabb ab Note An occurrence of p as a subsequence in s should be thought of as a set of positions in s such that the letters at these positions, in order, form p. The number of occurences is thus the number of such sets. For example, ab appears 6 times as a subsequence in aaabb, for the following sets of positions: {1, 4}, {1, 5}, {2, 4}, {2, 5}, {3, 4}, {3, 5} (that is, we should choose one of the a's and one of the b's).
2
14
#include <bits/stdc++.h> using namespace std; string p = "abcdef"; string s = "aabcdef"; int Count(int i, int j) { if (i == p.size()) return 1; if (j == s.size()) return 0; int res = Count(i, j + 1); if (p[i] == s[j]) { res += Count(i + 1, j + 1); } return res; } const int N = 200; int x[N]; int a[N]; int main() { ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL); int n; cin >> n; int ind; int sum = 0; for (ind = 1; sum <= n; ++ind) { x[ind] = x[ind - 1] + ind * (ind + 1) * (ind + 2) * (ind + 3) / 24; sum += x[ind]; } --ind; sum -= x[ind--]; n -= sum; for (int i = ind; n > 0; --i) { while (n >= x[i]) { n -= x[i]; ++a[i]; } } string s; for (int i = 1; i <= ind; ++i) { s += string(1 + a[ind - i + 1], 'a'); s += "bcdef"; } cout << s << ' ' << p << endl; return 0; }
CPP
802_H. Fake News (medium)
Thanks to your help, Heidi is confident that no one can fool her. She has now decided to post some fake news on the HC2 Facebook page. However, she wants to be able to communicate to the HC2 committee that the post is fake, using some secret phrase hidden in the post as a subsequence. To make this method foolproof, she wants the phrase to appear n times in the post. She is asking you to design a post (string) s and a hidden phrase p such that p appears in s as a subsequence exactly n times. Input The first and only line of input contains a single integer n (1 ≤ n ≤ 1 000 000). Output The output should contain two nonempty strings s and p separated by a single space. Each string should be composed of letters (a-z and A-Z: both lowercase and uppercase are allowed) and have length at most 200. The number of occurrences of p in s as a subsequence should be exactly n. If there are many possible solutions, output any of them. It is guaranteed that at least one solution exists. Examples Input 2 Output hHheidi Hei Input 4 Output bbbba ba Input 6 Output aaabb ab Note An occurrence of p as a subsequence in s should be thought of as a set of positions in s such that the letters at these positions, in order, form p. The number of occurences is thus the number of such sets. For example, ab appears 6 times as a subsequence in aaabb, for the following sets of positions: {1, 4}, {1, 5}, {2, 4}, {2, 5}, {3, 4}, {3, 5} (that is, we should choose one of the a's and one of the b's).
2
14
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 100; int MAX; void solve(int n) { string res; for (int i = 72; i >= 1; i--) { int each = i * (i - 1) * (i - 2) * (i - 3) / 24; if (each) { int c = n / each; n %= each; while (c--) { res.insert(res.begin(), 'B'); } } res.insert(res.begin(), 'A'); } string T = "AAAAB"; MAX = max(MAX, (int)res.size()); assert(res.size() <= 200); cout << res << " " << T << endl; } int main() { ios::sync_with_stdio(0); cin.tie(0); int n; cin >> n; solve(n); return 0; }
CPP
802_H. Fake News (medium)
Thanks to your help, Heidi is confident that no one can fool her. She has now decided to post some fake news on the HC2 Facebook page. However, she wants to be able to communicate to the HC2 committee that the post is fake, using some secret phrase hidden in the post as a subsequence. To make this method foolproof, she wants the phrase to appear n times in the post. She is asking you to design a post (string) s and a hidden phrase p such that p appears in s as a subsequence exactly n times. Input The first and only line of input contains a single integer n (1 ≤ n ≤ 1 000 000). Output The output should contain two nonempty strings s and p separated by a single space. Each string should be composed of letters (a-z and A-Z: both lowercase and uppercase are allowed) and have length at most 200. The number of occurrences of p in s as a subsequence should be exactly n. If there are many possible solutions, output any of them. It is guaranteed that at least one solution exists. Examples Input 2 Output hHheidi Hei Input 4 Output bbbba ba Input 6 Output aaabb ab Note An occurrence of p as a subsequence in s should be thought of as a set of positions in s such that the letters at these positions, in order, form p. The number of occurences is thus the number of such sets. For example, ab appears 6 times as a subsequence in aaabb, for the following sets of positions: {1, 4}, {1, 5}, {2, 4}, {2, 5}, {3, 4}, {3, 5} (that is, we should choose one of the a's and one of the b's).
2
14
#include <bits/stdc++.h> using namespace std; const int SIZE = 3e5 + 5; const long long INF = 1e14 + 5; const long long MOD = 1e9 + 7; struct abc { int num; int pos; }; bool operator<(abc a, abc b) { if (a.pos != b.pos) { return a.pos > b.pos; } return a.num > b.num; } int gcd(int a, int b) { while (b) { a %= b; swap(a, b); } return a; } bool inRange(int n, int m, int n0, int m0) { return n0 > -1 && m0 > -1 && m0 < m && n0 < n; } bool cmp1(pair<int, int> a, pair<int, int> b) { return a.first < b.first; } bool cmp2(pair<int, int> a, pair<int, int> b) { return a.second < b.second; } int len, total; string ms, mb; void rec(int start, int pos) { if (pos == mb.length()) { ++total; return; } for (int i = start; i < len; ++i) { if (ms[i] != mb[pos]) continue; rec(i + 1, pos + 1); } } int count(string s, string b) { len = s.length(); total = 0; ms = s; mb = b; rec(0, 0); return total; } string check(int n) { for (int i = 0; i < 201; ++i) for (int j = i; i + j < 201; ++j) for (int k = i; i + j + k < 201; ++k) { int t1 = i * j * k; int t2 = i * j * k + i * j + i + 1; int k1 = (n - t1) / t2; int k2 = n / t2; int l1 = i + j + k + k1 + 4; int l2 = i + j + k + k2 + 3; if (l2 < 201 && k2 * t2 == n) { string ans = ""; for (int z = 0; z < i; ++z) { ans += 'a'; } for (int z = 0; z < j; ++z) { ans += 'b'; } for (int z = 0; z < k; ++z) { ans += 'c'; } ans += "abc"; for (int z = 0; z < k2; ++z) { ans += 'd'; } return ans; } if (l1 < 201 && t1 + k1 * t2 == n) { string ans = ""; for (int z = 0; z < i; ++z) { ans += 'a'; } for (int z = 0; z < j; ++z) { ans += 'b'; } for (int z = 0; z < k; ++z) { ans += 'c'; } ans += "dabc"; for (int z = 0; z < k1; ++z) { ans += 'd'; } return ans; } } return ""; } int main() { int n; scanf("%d", &n); string s1 = check(n); string s2 = "abcd"; printf("%s %s", s1.c_str(), s2.c_str()); return 0; }
CPP
802_H. Fake News (medium)
Thanks to your help, Heidi is confident that no one can fool her. She has now decided to post some fake news on the HC2 Facebook page. However, she wants to be able to communicate to the HC2 committee that the post is fake, using some secret phrase hidden in the post as a subsequence. To make this method foolproof, she wants the phrase to appear n times in the post. She is asking you to design a post (string) s and a hidden phrase p such that p appears in s as a subsequence exactly n times. Input The first and only line of input contains a single integer n (1 ≤ n ≤ 1 000 000). Output The output should contain two nonempty strings s and p separated by a single space. Each string should be composed of letters (a-z and A-Z: both lowercase and uppercase are allowed) and have length at most 200. The number of occurrences of p in s as a subsequence should be exactly n. If there are many possible solutions, output any of them. It is guaranteed that at least one solution exists. Examples Input 2 Output hHheidi Hei Input 4 Output bbbba ba Input 6 Output aaabb ab Note An occurrence of p as a subsequence in s should be thought of as a set of positions in s such that the letters at these positions, in order, form p. The number of occurences is thus the number of such sets. For example, ab appears 6 times as a subsequence in aaabb, for the following sets of positions: {1, 4}, {1, 5}, {2, 4}, {2, 5}, {3, 4}, {3, 5} (that is, we should choose one of the a's and one of the b's).
2
14
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 5; int main() { ios::sync_with_stdio(0); cin.tie(0); string ans, pat; for (int i = 0; i < 20; i++) ans += char('a' + i); pat = ans + char('a' + 20); int n; cin >> n; int t = 18; for (int j = 0; j < t; j++) { int till = 19; if (n & (1 << j)) till++; for (int k = 19 - j + 1; k <= till; k++) { ans += char('a' + k); } } for (int j = t; j < 20; j++) { if (n & (1 << j)) { for (int k = 0; k < (1 << (j - t + 1)); k++) { ans += char('a' + 20); } } } cout << ans << " " << pat << "\n"; return 0; }
CPP
802_H. Fake News (medium)
Thanks to your help, Heidi is confident that no one can fool her. She has now decided to post some fake news on the HC2 Facebook page. However, she wants to be able to communicate to the HC2 committee that the post is fake, using some secret phrase hidden in the post as a subsequence. To make this method foolproof, she wants the phrase to appear n times in the post. She is asking you to design a post (string) s and a hidden phrase p such that p appears in s as a subsequence exactly n times. Input The first and only line of input contains a single integer n (1 ≤ n ≤ 1 000 000). Output The output should contain two nonempty strings s and p separated by a single space. Each string should be composed of letters (a-z and A-Z: both lowercase and uppercase are allowed) and have length at most 200. The number of occurrences of p in s as a subsequence should be exactly n. If there are many possible solutions, output any of them. It is guaranteed that at least one solution exists. Examples Input 2 Output hHheidi Hei Input 4 Output bbbba ba Input 6 Output aaabb ab Note An occurrence of p as a subsequence in s should be thought of as a set of positions in s such that the letters at these positions, in order, form p. The number of occurences is thus the number of such sets. For example, ab appears 6 times as a subsequence in aaabb, for the following sets of positions: {1, 4}, {1, 5}, {2, 4}, {2, 5}, {3, 4}, {3, 5} (that is, we should choose one of the a's and one of the b's).
2
14
#include <bits/stdc++.h> using namespace std; const int maxn = 201; int a[maxn]; char t[maxn], s[maxn]; char c[30] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D'}; int main() { int n; scanf("%d", &n); int cnt = 0; a[cnt++] = n; while (n != 1 && n != 0) { if (n % 2 == 0) { n /= 2; a[cnt++] = --n; } else { n--; n /= 2; a[cnt++] = n; } } for (int i = 0; i < cnt; i++) { } memset(t, '\0', sizeof(t)); memset(s, '\0', sizeof(s)); int p, q, r, i; if (a[cnt - 1] == 1) { t[0] = s[0] = 'a'; r = 1; p = q = 1; i = cnt - 2; } else if (a[cnt - 1] == 0) { t[0] = t[1] = 'a'; s[0] = 'a'; r = 1; p = 2; q = 1; i = cnt - 3; } for (; i >= 0; i--, r++) { if (a[i] == a[i + 1] * 2 + 2) { int l = strlen(t); l += 4; t[l - 1] = t[l - 2] = c[r]; for (int k = l - 3; k >= r + 2; k--) { t[k] = t[k - 2]; } t[r] = t[r + 1] = c[r]; p = l; } else if (a[i] == a[i + 1] * 2 + 1) { int l = strlen(t); l += 3; t[l - 1] = t[l - 2] = c[r]; for (int k = l - 3; k >= r + 1; k--) { t[k] = t[k - 1]; } t[r] = c[r]; p = l; } s[q++] = c[r]; } printf("%s %s\n", t, s); return 0; }
CPP
802_H. Fake News (medium)
Thanks to your help, Heidi is confident that no one can fool her. She has now decided to post some fake news on the HC2 Facebook page. However, she wants to be able to communicate to the HC2 committee that the post is fake, using some secret phrase hidden in the post as a subsequence. To make this method foolproof, she wants the phrase to appear n times in the post. She is asking you to design a post (string) s and a hidden phrase p such that p appears in s as a subsequence exactly n times. Input The first and only line of input contains a single integer n (1 ≤ n ≤ 1 000 000). Output The output should contain two nonempty strings s and p separated by a single space. Each string should be composed of letters (a-z and A-Z: both lowercase and uppercase are allowed) and have length at most 200. The number of occurrences of p in s as a subsequence should be exactly n. If there are many possible solutions, output any of them. It is guaranteed that at least one solution exists. Examples Input 2 Output hHheidi Hei Input 4 Output bbbba ba Input 6 Output aaabb ab Note An occurrence of p as a subsequence in s should be thought of as a set of positions in s such that the letters at these positions, in order, form p. The number of occurences is thus the number of such sets. For example, ab appears 6 times as a subsequence in aaabb, for the following sets of positions: {1, 4}, {1, 5}, {2, 4}, {2, 5}, {3, 4}, {3, 5} (that is, we should choose one of the a's and one of the b's).
2
14
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n; cin >> n; vector<int> ord; while (n > 2) { ord.push_back(n); if (n % 2 == 0) { n = n / 2 - 1; } else { n = n / 2; } } string s, p; if (n == 1) { s = "a"; p = "a"; } else { s = "aa"; p = "a"; } reverse((ord).begin(), (ord).end()); char c = 'b'; for (int i = 0; i < (int)(ord).size(); ++i) { string u = s.substr((int)(p).size(), (int)(s).size() - (int)(p).size()); if (ord[i] == 2 * n + 1) { s = p + c + u + c + c; } else { s = p + c + c + u + c + c; } p += c; ++c; n = ord[i]; } cout << s << " " << p << "\n"; }
CPP
802_H. Fake News (medium)
Thanks to your help, Heidi is confident that no one can fool her. She has now decided to post some fake news on the HC2 Facebook page. However, she wants to be able to communicate to the HC2 committee that the post is fake, using some secret phrase hidden in the post as a subsequence. To make this method foolproof, she wants the phrase to appear n times in the post. She is asking you to design a post (string) s and a hidden phrase p such that p appears in s as a subsequence exactly n times. Input The first and only line of input contains a single integer n (1 ≤ n ≤ 1 000 000). Output The output should contain two nonempty strings s and p separated by a single space. Each string should be composed of letters (a-z and A-Z: both lowercase and uppercase are allowed) and have length at most 200. The number of occurrences of p in s as a subsequence should be exactly n. If there are many possible solutions, output any of them. It is guaranteed that at least one solution exists. Examples Input 2 Output hHheidi Hei Input 4 Output bbbba ba Input 6 Output aaabb ab Note An occurrence of p as a subsequence in s should be thought of as a set of positions in s such that the letters at these positions, in order, form p. The number of occurences is thus the number of such sets. For example, ab appears 6 times as a subsequence in aaabb, for the following sets of positions: {1, 4}, {1, 5}, {2, 4}, {2, 5}, {3, 4}, {3, 5} (that is, we should choose one of the a's and one of the b's).
2
14
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 5; string s; int poly(int n) { return (n * n * n + 3 * n * n + 2 * n) / 6; } int n; int val[N]; int main() { scanf("%d", &n); int ile_bedzie = 38; int znaki = 0; val[1] = 1; for (int i = 1; i <= 1000; ++i) val[i] = val[i - 1] + poly(i); while (ile_bedzie > 0) { while (n >= val[ile_bedzie]) { printf("a"); znaki++; n -= val[ile_bedzie]; } ile_bedzie--; printf("bcde"); znaki += 4; } printf(" abcde\n"); fprintf(stderr, "znaki=%d\n", znaki); }
CPP
802_H. Fake News (medium)
Thanks to your help, Heidi is confident that no one can fool her. She has now decided to post some fake news on the HC2 Facebook page. However, she wants to be able to communicate to the HC2 committee that the post is fake, using some secret phrase hidden in the post as a subsequence. To make this method foolproof, she wants the phrase to appear n times in the post. She is asking you to design a post (string) s and a hidden phrase p such that p appears in s as a subsequence exactly n times. Input The first and only line of input contains a single integer n (1 ≤ n ≤ 1 000 000). Output The output should contain two nonempty strings s and p separated by a single space. Each string should be composed of letters (a-z and A-Z: both lowercase and uppercase are allowed) and have length at most 200. The number of occurrences of p in s as a subsequence should be exactly n. If there are many possible solutions, output any of them. It is guaranteed that at least one solution exists. Examples Input 2 Output hHheidi Hei Input 4 Output bbbba ba Input 6 Output aaabb ab Note An occurrence of p as a subsequence in s should be thought of as a set of positions in s such that the letters at these positions, in order, form p. The number of occurences is thus the number of such sets. For example, ab appears 6 times as a subsequence in aaabb, for the following sets of positions: {1, 4}, {1, 5}, {2, 4}, {2, 5}, {3, 4}, {3, 5} (that is, we should choose one of the a's and one of the b's).
2
14
import string alphabet = list(string.ascii_lowercase + string.ascii_uppercase) def calc(n): if n == 1: return '', 'a' if n == 2: return 'a', 'a' if n % 2 == 1: u, p = calc(n//2) x = alphabet.pop() return u+x+x, p+x else: u, p = calc(n//2-1) x = alphabet.pop() return x+u+x+x, p+x n = int(input()) u, p = calc(n) print(p+u+' '+p)
PYTHON3
802_H. Fake News (medium)
Thanks to your help, Heidi is confident that no one can fool her. She has now decided to post some fake news on the HC2 Facebook page. However, she wants to be able to communicate to the HC2 committee that the post is fake, using some secret phrase hidden in the post as a subsequence. To make this method foolproof, she wants the phrase to appear n times in the post. She is asking you to design a post (string) s and a hidden phrase p such that p appears in s as a subsequence exactly n times. Input The first and only line of input contains a single integer n (1 ≤ n ≤ 1 000 000). Output The output should contain two nonempty strings s and p separated by a single space. Each string should be composed of letters (a-z and A-Z: both lowercase and uppercase are allowed) and have length at most 200. The number of occurrences of p in s as a subsequence should be exactly n. If there are many possible solutions, output any of them. It is guaranteed that at least one solution exists. Examples Input 2 Output hHheidi Hei Input 4 Output bbbba ba Input 6 Output aaabb ab Note An occurrence of p as a subsequence in s should be thought of as a set of positions in s such that the letters at these positions, in order, form p. The number of occurences is thus the number of such sets. For example, ab appears 6 times as a subsequence in aaabb, for the following sets of positions: {1, 4}, {1, 5}, {2, 4}, {2, 5}, {3, 4}, {3, 5} (that is, we should choose one of the a's and one of the b's).
2
14
#include <bits/stdc++.h> using namespace std; string t, p; int s, c = 3; string abc[60]; void add(int x) { if (x == 1) { t = p = "A"; return; } if (x == 2) { t = "AA"; p = "A"; return; } if (x % 2) { add((x - 1) / 2); t.insert(t.size() - p.size(), abc[c]); t.insert(0, abc[c]); t.insert(0, abc[c]); p.insert(0, abc[c]); } else { add((x - 2) / 2); t.insert(t.size() - p.size(), abc[c]); t.insert(t.size() - p.size(), abc[c]); t.insert(0, abc[c]); t.insert(0, abc[c]); p.insert(0, abc[c]); } c++; } int main() { for (int i = 3; i <= 27; i++) { abc[i] += 'B' + i - 3; } for (int i = 1; i <= 26; i++) { abc[27 + i] += 'a' + i - 1; } cin >> s; add(s); cout << t << " " << p << endl; return 0; }
CPP
802_H. Fake News (medium)
Thanks to your help, Heidi is confident that no one can fool her. She has now decided to post some fake news on the HC2 Facebook page. However, she wants to be able to communicate to the HC2 committee that the post is fake, using some secret phrase hidden in the post as a subsequence. To make this method foolproof, she wants the phrase to appear n times in the post. She is asking you to design a post (string) s and a hidden phrase p such that p appears in s as a subsequence exactly n times. Input The first and only line of input contains a single integer n (1 ≤ n ≤ 1 000 000). Output The output should contain two nonempty strings s and p separated by a single space. Each string should be composed of letters (a-z and A-Z: both lowercase and uppercase are allowed) and have length at most 200. The number of occurrences of p in s as a subsequence should be exactly n. If there are many possible solutions, output any of them. It is guaranteed that at least one solution exists. Examples Input 2 Output hHheidi Hei Input 4 Output bbbba ba Input 6 Output aaabb ab Note An occurrence of p as a subsequence in s should be thought of as a set of positions in s such that the letters at these positions, in order, form p. The number of occurences is thus the number of such sets. For example, ab appears 6 times as a subsequence in aaabb, for the following sets of positions: {1, 4}, {1, 5}, {2, 4}, {2, 5}, {3, 4}, {3, 5} (that is, we should choose one of the a's and one of the b's).
2
14
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.List; import java.util.StringTokenizer; import java.io.IOException; import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.InputStream; import java.util.ArrayList; /** * Built using CHelper plug-in * Actual solution is at the top * * @author niquefa_diego */ public class Main { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; InputReader in = new InputReader(inputStream); PrintWriter out = new PrintWriter(outputStream); TaskH solver = new TaskH(); solver.solve(1, in, out); out.close(); } static class TaskH { public void solve(int testNumber, InputReader in, PrintWriter out) { int n = in.nextInt(); Solution ans = Solution.solve(n); out.println(ans.getText() + " " + ans.getPattern()); } } static class Solution { List<Integer> text = new ArrayList<>(); int patternLen = 0; String getPattern() { StringBuilder sb = new StringBuilder(patternLen); for (int x = patternLen - 1; x >= 0; --x) if (x < 26) sb.append((char) (x + 'a')); else sb.append((char) (x - 26 + 'A')); return sb.toString(); } String getText() { StringBuilder sb = new StringBuilder(text.size()); for (int x : text) if (x < 26) sb.append((char) (x + 'a')); else sb.append((char) (x - 26 + 'A')); return sb.toString(); } void goOdd() { text.add(0, patternLen); text.add(0, patternLen); text.add(text.size() - patternLen, patternLen); patternLen++; } void goEven() { text.add(0, patternLen); text.add(0, patternLen); text.add(text.size() - patternLen, patternLen); text.add(text.size() - patternLen, patternLen); patternLen++; } static Solution solve(int n) { Solution ans; if (n <= 2) { ans = new Solution(); for (int i = 0; i < n; ++i) ans.text.add(0); ans.patternLen = 1; return ans; } else if (n % 2 == 1) { ans = solve((n - 1) / 2); ans.goOdd(); } else { ans = solve((n - 2) / 2); ans.goEven(); } return ans; } } static class InputReader { public BufferedReader reader; public StringTokenizer tokenizer = null; public InputReader(InputStream stream) { reader = new BufferedReader(new InputStreamReader(stream), 32768); } public String next() { while (tokenizer == null || !tokenizer.hasMoreTokens()) { try { tokenizer = new StringTokenizer(reader.readLine()); } catch (IOException e) { throw new RuntimeException(e); } } return tokenizer.nextToken(); } public int nextInt() { return Integer.parseInt(next()); } } }
JAVA
802_H. Fake News (medium)
Thanks to your help, Heidi is confident that no one can fool her. She has now decided to post some fake news on the HC2 Facebook page. However, she wants to be able to communicate to the HC2 committee that the post is fake, using some secret phrase hidden in the post as a subsequence. To make this method foolproof, she wants the phrase to appear n times in the post. She is asking you to design a post (string) s and a hidden phrase p such that p appears in s as a subsequence exactly n times. Input The first and only line of input contains a single integer n (1 ≤ n ≤ 1 000 000). Output The output should contain two nonempty strings s and p separated by a single space. Each string should be composed of letters (a-z and A-Z: both lowercase and uppercase are allowed) and have length at most 200. The number of occurrences of p in s as a subsequence should be exactly n. If there are many possible solutions, output any of them. It is guaranteed that at least one solution exists. Examples Input 2 Output hHheidi Hei Input 4 Output bbbba ba Input 6 Output aaabb ab Note An occurrence of p as a subsequence in s should be thought of as a set of positions in s such that the letters at these positions, in order, form p. The number of occurences is thus the number of such sets. For example, ab appears 6 times as a subsequence in aaabb, for the following sets of positions: {1, 4}, {1, 5}, {2, 4}, {2, 5}, {3, 4}, {3, 5} (that is, we should choose one of the a's and one of the b's).
2
14
#include <bits/stdc++.h> using namespace std; long long pow(long long x) { return x * (x - 1) * (x - 2) * (x - 3) / 24; } int main() { long long n; cin >> n; long long i = 0; while (pow(i + 1) <= n) { i++; } long long As = i; vector<int> v; while (n) { for (int i = As; i > 0; i--) { if (pow(i) <= n) { n -= pow(i); v.push_back(i); break; } } } for (int i = 1; i <= As; i++) { cout << 'a'; for (int j = 0; j < v.size(); j++) { if (v[j] == i) cout << 'b'; } } cout << " aaaab" << endl; return 0; }
CPP
802_H. Fake News (medium)
Thanks to your help, Heidi is confident that no one can fool her. She has now decided to post some fake news on the HC2 Facebook page. However, she wants to be able to communicate to the HC2 committee that the post is fake, using some secret phrase hidden in the post as a subsequence. To make this method foolproof, she wants the phrase to appear n times in the post. She is asking you to design a post (string) s and a hidden phrase p such that p appears in s as a subsequence exactly n times. Input The first and only line of input contains a single integer n (1 ≤ n ≤ 1 000 000). Output The output should contain two nonempty strings s and p separated by a single space. Each string should be composed of letters (a-z and A-Z: both lowercase and uppercase are allowed) and have length at most 200. The number of occurrences of p in s as a subsequence should be exactly n. If there are many possible solutions, output any of them. It is guaranteed that at least one solution exists. Examples Input 2 Output hHheidi Hei Input 4 Output bbbba ba Input 6 Output aaabb ab Note An occurrence of p as a subsequence in s should be thought of as a set of positions in s such that the letters at these positions, in order, form p. The number of occurences is thus the number of such sets. For example, ab appears 6 times as a subsequence in aaabb, for the following sets of positions: {1, 4}, {1, 5}, {2, 4}, {2, 5}, {3, 4}, {3, 5} (that is, we should choose one of the a's and one of the b's).
2
14
#include <bits/stdc++.h> using namespace std; int c[210][210], t[210], a[210]; int main() { cin.tie(0); ios_base::sync_with_stdio(false); for (int i = 1; i < 210; i++) c[i][0] = c[i][i] = 1; for (int i = 1; i < 210; i++) for (int j = 1; j < i; j++) c[i][j] = c[i - 1][j - 1] + c[i - 1][j]; for (int i = 0; i < 30; i++) t[i] = c[i + 5][5]; int n; cin >> n; while (n) { int tmp = upper_bound(t, t + 30, n) - t - 1; n -= t[tmp]; a[tmp]++; } int f = 1; for (int i = 29; i >= 0; i--) { if (f && a[i] == 0) continue; f = 0; for (int j = 0; j < a[i]; j++) cout << 'a'; cout << "bcdef"; } cout << " abcdef"; return 0; }
CPP
802_H. Fake News (medium)
Thanks to your help, Heidi is confident that no one can fool her. She has now decided to post some fake news on the HC2 Facebook page. However, she wants to be able to communicate to the HC2 committee that the post is fake, using some secret phrase hidden in the post as a subsequence. To make this method foolproof, she wants the phrase to appear n times in the post. She is asking you to design a post (string) s and a hidden phrase p such that p appears in s as a subsequence exactly n times. Input The first and only line of input contains a single integer n (1 ≤ n ≤ 1 000 000). Output The output should contain two nonempty strings s and p separated by a single space. Each string should be composed of letters (a-z and A-Z: both lowercase and uppercase are allowed) and have length at most 200. The number of occurrences of p in s as a subsequence should be exactly n. If there are many possible solutions, output any of them. It is guaranteed that at least one solution exists. Examples Input 2 Output hHheidi Hei Input 4 Output bbbba ba Input 6 Output aaabb ab Note An occurrence of p as a subsequence in s should be thought of as a set of positions in s such that the letters at these positions, in order, form p. The number of occurences is thus the number of such sets. For example, ab appears 6 times as a subsequence in aaabb, for the following sets of positions: {1, 4}, {1, 5}, {2, 4}, {2, 5}, {3, 4}, {3, 5} (that is, we should choose one of the a's and one of the b's).
2
14
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:102400000,102400000") using namespace std; template <class T, class U> inline void Max(T &a, U b) { if (a < b) a = b; } template <class T, class U> inline void Min(T &a, U b) { if (a > b) a = b; } inline void add(int &a, int b) { a += b; while (a >= 1000000007) a -= 1000000007; } int pow(int a, int b) { int ans = 1; while (b) { if (b & 1) ans = ans * (long long)a % 1000000007; a = (long long)a * a % 1000000007; b >>= 1; } return ans; } int n; string a = "?", b = "?"; int cal(string p, string u, int k) { if (k == n) { a = p; b = u; return 1; } int m = p.size(); if (2 * k + 1 <= n) { string t; t.push_back(m + 'a'); if (cal(p + t, u + t + t, k * 2 + 1)) return 1; } if (2 * k + 2 <= n) { string t; t.push_back(m + 'a'); if (cal(p + t, t + u + t + t, k * 2 + 2)) return 1; } return 0; } int main() { int T, i = 0, j, k, ca = 0, K, m; scanf("%d", &n); string u = "z", p = "a"; if (cal(p, u, 1)) { b = a + b; printf("%s %s\n", b.c_str(), a.c_str()); } else { p = "a", u = "za"; cal(p, u, 2); b = a + b; printf("%s %s\n", b.c_str(), a.c_str()); } assert(a != "?"); return 0; }
CPP
802_H. Fake News (medium)
Thanks to your help, Heidi is confident that no one can fool her. She has now decided to post some fake news on the HC2 Facebook page. However, she wants to be able to communicate to the HC2 committee that the post is fake, using some secret phrase hidden in the post as a subsequence. To make this method foolproof, she wants the phrase to appear n times in the post. She is asking you to design a post (string) s and a hidden phrase p such that p appears in s as a subsequence exactly n times. Input The first and only line of input contains a single integer n (1 ≤ n ≤ 1 000 000). Output The output should contain two nonempty strings s and p separated by a single space. Each string should be composed of letters (a-z and A-Z: both lowercase and uppercase are allowed) and have length at most 200. The number of occurrences of p in s as a subsequence should be exactly n. If there are many possible solutions, output any of them. It is guaranteed that at least one solution exists. Examples Input 2 Output hHheidi Hei Input 4 Output bbbba ba Input 6 Output aaabb ab Note An occurrence of p as a subsequence in s should be thought of as a set of positions in s such that the letters at these positions, in order, form p. The number of occurences is thus the number of such sets. For example, ab appears 6 times as a subsequence in aaabb, for the following sets of positions: {1, 4}, {1, 5}, {2, 4}, {2, 5}, {3, 4}, {3, 5} (that is, we should choose one of the a's and one of the b's).
2
14
#include <bits/stdc++.h> using namespace std; template <class T, class U> ostream& operator<<(ostream& o, const pair<T, U>& p) { o << "(" << p.first << "," << p.second << ")"; return o; } template <class T> ostream& operator<<(ostream& o, const vector<T>& v) { o << "["; for (T t : v) { o << t << ","; } o << "]"; return o; } long long comb[205][205]; int n; int num[10]; int z; bool sol(int pattern, int pre, int prea, int d) { if (d == 0) { if (pattern == n) { int i = 0; vector<int> res; while (num[i] >= 0) res.push_back((num[i++])); reverse((res).begin(), (res).end()); for (auto k : res) { for (int j = (int)(0); j < (int)(k); j++) printf("a"); printf("b"); } printf(" "); for (int j = (int)(0); j < (int)(z); j++) printf("a"); printf("b\n"); return true; } else { return false; } } d--; for (int i = 0; i <= 200 - pre - d; i++) { num[d] = i; int npattern = pattern + comb[prea + i][z]; if (npattern > n) continue; if (sol(npattern, pre + i + 1, prea + i, d)) return true; } return false; } int main() { fill(comb[0], comb[201], 0); comb[0][0] = 1; for (int i = (int)(1); i < (int)(201); i++) { comb[i][0] = 1; for (int j = (int)(1); j < (int)(201); j++) comb[i][j] = comb[i - 1][j - 1] + comb[i - 1][j]; } cin >> n; int initj = 3; if (n < 10) initj = 2; for (int i = (int)(1); i < (int)(9); i++) { for (int j = (int)(initj); j < (int)(50); j++) { z = j; fill(num, num + 10, -1); if (sol(0, 0, 0, i)) return 0; } } assert(false); return 0; }
CPP
802_H. Fake News (medium)
Thanks to your help, Heidi is confident that no one can fool her. She has now decided to post some fake news on the HC2 Facebook page. However, she wants to be able to communicate to the HC2 committee that the post is fake, using some secret phrase hidden in the post as a subsequence. To make this method foolproof, she wants the phrase to appear n times in the post. She is asking you to design a post (string) s and a hidden phrase p such that p appears in s as a subsequence exactly n times. Input The first and only line of input contains a single integer n (1 ≤ n ≤ 1 000 000). Output The output should contain two nonempty strings s and p separated by a single space. Each string should be composed of letters (a-z and A-Z: both lowercase and uppercase are allowed) and have length at most 200. The number of occurrences of p in s as a subsequence should be exactly n. If there are many possible solutions, output any of them. It is guaranteed that at least one solution exists. Examples Input 2 Output hHheidi Hei Input 4 Output bbbba ba Input 6 Output aaabb ab Note An occurrence of p as a subsequence in s should be thought of as a set of positions in s such that the letters at these positions, in order, form p. The number of occurences is thus the number of such sets. For example, ab appears 6 times as a subsequence in aaabb, for the following sets of positions: {1, 4}, {1, 5}, {2, 4}, {2, 5}, {3, 4}, {3, 5} (that is, we should choose one of the a's and one of the b's).
2
14
#include <bits/stdc++.h> using namespace std; int n; char now; string s, t; void solve(int len) { if (len == 1) { s = ""; t = "a"; now = 'a'; return; } if (len == 2) { s = "c"; t = "ac"; now = 'c'; return; } if (len % 2 == 0) { solve(len / 2 - 1); now++; s = now + s + now + now; t = t + now; return; } if (len % 2 == 1) { solve(len / 2); now++; s = s + now + now; t = t + now; return; } } int main() { scanf("%d", &n); solve(n); cout << t << s << " " << t; return 0; }
CPP
802_H. Fake News (medium)
Thanks to your help, Heidi is confident that no one can fool her. She has now decided to post some fake news on the HC2 Facebook page. However, she wants to be able to communicate to the HC2 committee that the post is fake, using some secret phrase hidden in the post as a subsequence. To make this method foolproof, she wants the phrase to appear n times in the post. She is asking you to design a post (string) s and a hidden phrase p such that p appears in s as a subsequence exactly n times. Input The first and only line of input contains a single integer n (1 ≤ n ≤ 1 000 000). Output The output should contain two nonempty strings s and p separated by a single space. Each string should be composed of letters (a-z and A-Z: both lowercase and uppercase are allowed) and have length at most 200. The number of occurrences of p in s as a subsequence should be exactly n. If there are many possible solutions, output any of them. It is guaranteed that at least one solution exists. Examples Input 2 Output hHheidi Hei Input 4 Output bbbba ba Input 6 Output aaabb ab Note An occurrence of p as a subsequence in s should be thought of as a set of positions in s such that the letters at these positions, in order, form p. The number of occurences is thus the number of such sets. For example, ab appears 6 times as a subsequence in aaabb, for the following sets of positions: {1, 4}, {1, 5}, {2, 4}, {2, 5}, {3, 4}, {3, 5} (that is, we should choose one of the a's and one of the b's).
2
14
#include <bits/stdc++.h> using namespace std; long long tests; long long n, m, z[505], j = 'a'; bool ok; string s; void solve() { cin >> n; m = 80; while (n) { while ((m * (m - 1) * (m - 2) * (m - 3)) / 24 > n) m--; n -= (m * (m - 1) * (m - 2) * (m - 3)) / 24; z[m]++; } for (int i = 1; i < 80; i++) { cout << 'a'; while (z[i]--) cout << 'b'; } cout << " aaaab"; } int main() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); solve(); }
CPP
802_H. Fake News (medium)
Thanks to your help, Heidi is confident that no one can fool her. She has now decided to post some fake news on the HC2 Facebook page. However, she wants to be able to communicate to the HC2 committee that the post is fake, using some secret phrase hidden in the post as a subsequence. To make this method foolproof, she wants the phrase to appear n times in the post. She is asking you to design a post (string) s and a hidden phrase p such that p appears in s as a subsequence exactly n times. Input The first and only line of input contains a single integer n (1 ≤ n ≤ 1 000 000). Output The output should contain two nonempty strings s and p separated by a single space. Each string should be composed of letters (a-z and A-Z: both lowercase and uppercase are allowed) and have length at most 200. The number of occurrences of p in s as a subsequence should be exactly n. If there are many possible solutions, output any of them. It is guaranteed that at least one solution exists. Examples Input 2 Output hHheidi Hei Input 4 Output bbbba ba Input 6 Output aaabb ab Note An occurrence of p as a subsequence in s should be thought of as a set of positions in s such that the letters at these positions, in order, form p. The number of occurences is thus the number of such sets. For example, ab appears 6 times as a subsequence in aaabb, for the following sets of positions: {1, 4}, {1, 5}, {2, 4}, {2, 5}, {3, 4}, {3, 5} (that is, we should choose one of the a's and one of the b's).
2
14
#include <bits/stdc++.h> using namespace std; string s = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; int main() { string res1, res2; int n = 0, len = 0; cin >> n; while (--n) { if (n % 2) { res1 = res1 + s[len]; ++len; } else { res1 = res1 + s[len] + s[len]; ++len; n /= 2; } } for (int i = 0; i <= len; ++i) { res2 += s[i]; } cout << res1 + res2 << " " << res2 << endl; return 0; }
CPP
802_H. Fake News (medium)
Thanks to your help, Heidi is confident that no one can fool her. She has now decided to post some fake news on the HC2 Facebook page. However, she wants to be able to communicate to the HC2 committee that the post is fake, using some secret phrase hidden in the post as a subsequence. To make this method foolproof, she wants the phrase to appear n times in the post. She is asking you to design a post (string) s and a hidden phrase p such that p appears in s as a subsequence exactly n times. Input The first and only line of input contains a single integer n (1 ≤ n ≤ 1 000 000). Output The output should contain two nonempty strings s and p separated by a single space. Each string should be composed of letters (a-z and A-Z: both lowercase and uppercase are allowed) and have length at most 200. The number of occurrences of p in s as a subsequence should be exactly n. If there are many possible solutions, output any of them. It is guaranteed that at least one solution exists. Examples Input 2 Output hHheidi Hei Input 4 Output bbbba ba Input 6 Output aaabb ab Note An occurrence of p as a subsequence in s should be thought of as a set of positions in s such that the letters at these positions, in order, form p. The number of occurences is thus the number of such sets. For example, ab appears 6 times as a subsequence in aaabb, for the following sets of positions: {1, 4}, {1, 5}, {2, 4}, {2, 5}, {3, 4}, {3, 5} (that is, we should choose one of the a's and one of the b's).
2
14
#include <bits/stdc++.h> using namespace std; int Comb[110][6], C[110], S; int main() { int i, j; for (i = 0; i <= 45; i++) { Comb[i][0] = 1; for (j = 1; j <= 5 && j <= i; j++) Comb[i][j] = Comb[i - 1][j] + Comb[i - 1][j - 1]; } scanf("%d", &S); for (i = 45; i >= 5; i--) { while (S >= Comb[i][5]) { C[i]++; S -= Comb[i][5]; } } for (i = 0; i < 45; i++) { while (C[i]--) printf("b"); printf("a"); } printf(" aaaaab\n"); }
CPP
802_H. Fake News (medium)
Thanks to your help, Heidi is confident that no one can fool her. She has now decided to post some fake news on the HC2 Facebook page. However, she wants to be able to communicate to the HC2 committee that the post is fake, using some secret phrase hidden in the post as a subsequence. To make this method foolproof, she wants the phrase to appear n times in the post. She is asking you to design a post (string) s and a hidden phrase p such that p appears in s as a subsequence exactly n times. Input The first and only line of input contains a single integer n (1 ≤ n ≤ 1 000 000). Output The output should contain two nonempty strings s and p separated by a single space. Each string should be composed of letters (a-z and A-Z: both lowercase and uppercase are allowed) and have length at most 200. The number of occurrences of p in s as a subsequence should be exactly n. If there are many possible solutions, output any of them. It is guaranteed that at least one solution exists. Examples Input 2 Output hHheidi Hei Input 4 Output bbbba ba Input 6 Output aaabb ab Note An occurrence of p as a subsequence in s should be thought of as a set of positions in s such that the letters at these positions, in order, form p. The number of occurences is thus the number of such sets. For example, ab appears 6 times as a subsequence in aaabb, for the following sets of positions: {1, 4}, {1, 5}, {2, 4}, {2, 5}, {3, 4}, {3, 5} (that is, we should choose one of the a's and one of the b's).
2
14
#include <bits/stdc++.h> using namespace std; long long n, da = 6, db = 2, a = 5; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cin >> n; while (a <= n) a = a * da++ / db++; --da, --db, a = a * db / da, --da, --db; string ans = string(da, 'a'); while (a <= n) n -= a, ans += "b"; while (a != 1) { a = a * db-- / da--; while (a <= n) { n -= a; ans.insert(da, "b"); } } cout << ans << " aaaab"; }
CPP
802_H. Fake News (medium)
Thanks to your help, Heidi is confident that no one can fool her. She has now decided to post some fake news on the HC2 Facebook page. However, she wants to be able to communicate to the HC2 committee that the post is fake, using some secret phrase hidden in the post as a subsequence. To make this method foolproof, she wants the phrase to appear n times in the post. She is asking you to design a post (string) s and a hidden phrase p such that p appears in s as a subsequence exactly n times. Input The first and only line of input contains a single integer n (1 ≤ n ≤ 1 000 000). Output The output should contain two nonempty strings s and p separated by a single space. Each string should be composed of letters (a-z and A-Z: both lowercase and uppercase are allowed) and have length at most 200. The number of occurrences of p in s as a subsequence should be exactly n. If there are many possible solutions, output any of them. It is guaranteed that at least one solution exists. Examples Input 2 Output hHheidi Hei Input 4 Output bbbba ba Input 6 Output aaabb ab Note An occurrence of p as a subsequence in s should be thought of as a set of positions in s such that the letters at these positions, in order, form p. The number of occurences is thus the number of such sets. For example, ab appears 6 times as a subsequence in aaabb, for the following sets of positions: {1, 4}, {1, 5}, {2, 4}, {2, 5}, {3, 4}, {3, 5} (that is, we should choose one of the a's and one of the b's).
2
14
#include <bits/stdc++.h> using namespace std; long long n; string s; long long c[101]; int32_t main() { cin >> n; for (long long i = 4; i <= 100; i++) { long long now = 1; for (long long j = 0; j < 4; j++) { now *= (i - j); } for (long long j = 0; j < 4; j++) { now /= (j + 1); } c[i] = now; } for (long long i = 0; i < 100; i++) { s += 'b'; } while (n > 0) { long long go; for (long long i = 4; i <= 100; i++) { if (c[i] > n) break; go = i; } string s1; long long b = 0; bool flag = false; for (long long i = 0; i < s.size(); i++) { s1 += s[i]; if (s[i] == 'b') b++; if (!flag && b == 100 - go) { s1 += 'a'; flag = true; } } n -= c[go]; s = s1; } cout << s << " " << "abbbb" << endl; return 0; }
CPP
802_H. Fake News (medium)
Thanks to your help, Heidi is confident that no one can fool her. She has now decided to post some fake news on the HC2 Facebook page. However, she wants to be able to communicate to the HC2 committee that the post is fake, using some secret phrase hidden in the post as a subsequence. To make this method foolproof, she wants the phrase to appear n times in the post. She is asking you to design a post (string) s and a hidden phrase p such that p appears in s as a subsequence exactly n times. Input The first and only line of input contains a single integer n (1 ≤ n ≤ 1 000 000). Output The output should contain two nonempty strings s and p separated by a single space. Each string should be composed of letters (a-z and A-Z: both lowercase and uppercase are allowed) and have length at most 200. The number of occurrences of p in s as a subsequence should be exactly n. If there are many possible solutions, output any of them. It is guaranteed that at least one solution exists. Examples Input 2 Output hHheidi Hei Input 4 Output bbbba ba Input 6 Output aaabb ab Note An occurrence of p as a subsequence in s should be thought of as a set of positions in s such that the letters at these positions, in order, form p. The number of occurences is thus the number of such sets. For example, ab appears 6 times as a subsequence in aaabb, for the following sets of positions: {1, 4}, {1, 5}, {2, 4}, {2, 5}, {3, 4}, {3, 5} (that is, we should choose one of the a's and one of the b's).
2
14
#include <bits/stdc++.h> using namespace std; long long int dp[202][4]; signed main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); dp[0][0] = 1; for (long long int i = 1; i <= 200; i++) { for (long long int j = 0; j <= 3; j++) { dp[i][j] = dp[i - 1][j]; if (j > 0) { dp[i][j] += dp[i - 1][j - 1]; } } } long long int m; cin >> m; string ans = ""; vector<long long int> v; while (m) { for (long long int j = 200; j >= 0; j--) { if (dp[j][3] <= m) { v.push_back(j); m -= dp[j][3]; break; } } } reverse(v.begin(), v.end()); long long int last = 0; for (long long int i = 0; i < v.size(); i++) { long long int z = v[i] - last; while (z--) { ans.push_back('b'); } ans.push_back('a'); last = v[i]; } reverse(ans.begin(), ans.end()); cout << ans << " abbb"; }
CPP
802_H. Fake News (medium)
Thanks to your help, Heidi is confident that no one can fool her. She has now decided to post some fake news on the HC2 Facebook page. However, she wants to be able to communicate to the HC2 committee that the post is fake, using some secret phrase hidden in the post as a subsequence. To make this method foolproof, she wants the phrase to appear n times in the post. She is asking you to design a post (string) s and a hidden phrase p such that p appears in s as a subsequence exactly n times. Input The first and only line of input contains a single integer n (1 ≤ n ≤ 1 000 000). Output The output should contain two nonempty strings s and p separated by a single space. Each string should be composed of letters (a-z and A-Z: both lowercase and uppercase are allowed) and have length at most 200. The number of occurrences of p in s as a subsequence should be exactly n. If there are many possible solutions, output any of them. It is guaranteed that at least one solution exists. Examples Input 2 Output hHheidi Hei Input 4 Output bbbba ba Input 6 Output aaabb ab Note An occurrence of p as a subsequence in s should be thought of as a set of positions in s such that the letters at these positions, in order, form p. The number of occurences is thus the number of such sets. For example, ab appears 6 times as a subsequence in aaabb, for the following sets of positions: {1, 4}, {1, 5}, {2, 4}, {2, 5}, {3, 4}, {3, 5} (that is, we should choose one of the a's and one of the b's).
2
14
#include <bits/stdc++.h> using namespace std; long long int n; string ans; long long int high, low; long long int comb4(long long int x) { return x * (x - 1) * (x - 2) * (x - 3) / 24; } int main() { scanf("%I64d", &n); ans = "a"; low = -1; high = 101; while (high - low > 1) { long long int mid = (high + low) / 2; long long int t = comb4(mid); if (t <= n) low = mid; else high = mid; } long long int rem = n; for (long long int i = 0; i < low - 3; i++) { long long int t = rem / comb4(low - i); for (long long int j = 0; j < t; j++) { printf("a"); } printf("b"); rem -= comb4(low - i) * t; } printf("bbb"); puts(" abbbb"); }
CPP
802_H. Fake News (medium)
Thanks to your help, Heidi is confident that no one can fool her. She has now decided to post some fake news on the HC2 Facebook page. However, she wants to be able to communicate to the HC2 committee that the post is fake, using some secret phrase hidden in the post as a subsequence. To make this method foolproof, she wants the phrase to appear n times in the post. She is asking you to design a post (string) s and a hidden phrase p such that p appears in s as a subsequence exactly n times. Input The first and only line of input contains a single integer n (1 ≤ n ≤ 1 000 000). Output The output should contain two nonempty strings s and p separated by a single space. Each string should be composed of letters (a-z and A-Z: both lowercase and uppercase are allowed) and have length at most 200. The number of occurrences of p in s as a subsequence should be exactly n. If there are many possible solutions, output any of them. It is guaranteed that at least one solution exists. Examples Input 2 Output hHheidi Hei Input 4 Output bbbba ba Input 6 Output aaabb ab Note An occurrence of p as a subsequence in s should be thought of as a set of positions in s such that the letters at these positions, in order, form p. The number of occurences is thus the number of such sets. For example, ab appears 6 times as a subsequence in aaabb, for the following sets of positions: {1, 4}, {1, 5}, {2, 4}, {2, 5}, {3, 4}, {3, 5} (that is, we should choose one of the a's and one of the b's).
2
14
#include <bits/stdc++.h> using namespace std; string s, p; void dfs(int n, char x) { if (n == 1) { s = s + x; p += x; return; } if (n == 2) { s = s + x + x; p += x; return; } if (n % 2) { dfs(n / 2, x + 1); s = p + x + s.substr(p.size(), s.size() - p.size() + 1) + x + x; p += x; } else { dfs(n / 2 - 1, x + 1); s = p + x + x + s.substr(p.size(), s.size() - p.size() + 1) + x + x; p += x; } } int main() { int n; scanf("%d", &n); dfs(n, 'a'); cout << s << " " << p; return 0; }
CPP
802_H. Fake News (medium)
Thanks to your help, Heidi is confident that no one can fool her. She has now decided to post some fake news on the HC2 Facebook page. However, she wants to be able to communicate to the HC2 committee that the post is fake, using some secret phrase hidden in the post as a subsequence. To make this method foolproof, she wants the phrase to appear n times in the post. She is asking you to design a post (string) s and a hidden phrase p such that p appears in s as a subsequence exactly n times. Input The first and only line of input contains a single integer n (1 ≤ n ≤ 1 000 000). Output The output should contain two nonempty strings s and p separated by a single space. Each string should be composed of letters (a-z and A-Z: both lowercase and uppercase are allowed) and have length at most 200. The number of occurrences of p in s as a subsequence should be exactly n. If there are many possible solutions, output any of them. It is guaranteed that at least one solution exists. Examples Input 2 Output hHheidi Hei Input 4 Output bbbba ba Input 6 Output aaabb ab Note An occurrence of p as a subsequence in s should be thought of as a set of positions in s such that the letters at these positions, in order, form p. The number of occurences is thus the number of such sets. For example, ab appears 6 times as a subsequence in aaabb, for the following sets of positions: {1, 4}, {1, 5}, {2, 4}, {2, 5}, {3, 4}, {3, 5} (that is, we should choose one of the a's and one of the b's).
2
14
#include <bits/stdc++.h> using namespace std; const int MAX = 1e6 + 10; int getlen(int b) { int ans = 0; while (b) { ans++; b >>= 1; } return ans; } string p, s; void slove(int now, int deep) { string cnt; cnt += ((char)('a' + deep)); if (now == 1) { p = s = cnt; return; } else if (now == 2) { p += ((char)('a' + deep + 1)) + cnt; s += ((char)('a' + deep + 1)) + cnt + cnt; return; } if (now & 1) { slove(now >> 1, deep + 1); int lenp = p.size(); int lens = s.size(); s = s.substr(0, lenp) + cnt + s.substr(lenp, lens - lenp) + cnt + cnt; p += cnt; } else { slove((now >> 1) - 1, deep + 1); int lenp = p.size(); int lens = s.size(); s = s.substr(0, lenp) + cnt + cnt + s.substr(lenp, lens - lenp) + cnt + cnt; p += cnt; } } int ans = 0; void ac(int lenp, int lens) { if (lenp == p.size()) { ans++; return; } if (lens == s.size()) { return; } if (s[lens] == p[lenp]) { ac(lenp + 1, lens + 1); } ac(lenp, lens + 1); } int main() { int n; while (~scanf("%d", &n)) { s.clear(); p.clear(); slove(n, 0); cout << s << " " << p << endl; } return 0; }
CPP
802_H. Fake News (medium)
Thanks to your help, Heidi is confident that no one can fool her. She has now decided to post some fake news on the HC2 Facebook page. However, she wants to be able to communicate to the HC2 committee that the post is fake, using some secret phrase hidden in the post as a subsequence. To make this method foolproof, she wants the phrase to appear n times in the post. She is asking you to design a post (string) s and a hidden phrase p such that p appears in s as a subsequence exactly n times. Input The first and only line of input contains a single integer n (1 ≤ n ≤ 1 000 000). Output The output should contain two nonempty strings s and p separated by a single space. Each string should be composed of letters (a-z and A-Z: both lowercase and uppercase are allowed) and have length at most 200. The number of occurrences of p in s as a subsequence should be exactly n. If there are many possible solutions, output any of them. It is guaranteed that at least one solution exists. Examples Input 2 Output hHheidi Hei Input 4 Output bbbba ba Input 6 Output aaabb ab Note An occurrence of p as a subsequence in s should be thought of as a set of positions in s such that the letters at these positions, in order, form p. The number of occurences is thus the number of such sets. For example, ab appears 6 times as a subsequence in aaabb, for the following sets of positions: {1, 4}, {1, 5}, {2, 4}, {2, 5}, {3, 4}, {3, 5} (that is, we should choose one of the a's and one of the b's).
2
14
#include <bits/stdc++.h> using namespace std; long long n; char now; string s, t; inline void solve(int len) { if (len == 1) { s = ""; t = "a"; now = 'a'; return; } if (len == 2) { s = "b"; t = "ab"; now = 'b'; return; } if (len & 1) { solve(len / 2); now++; s = s + now + now; t = t + now; return; } else { solve(len / 2 - 1); now++; s = now + s + now + now; t = t + now; return; } } int main() { cin >> n; solve(n); cout << t << s << " " << t; return 0; }
CPP
802_H. Fake News (medium)
Thanks to your help, Heidi is confident that no one can fool her. She has now decided to post some fake news on the HC2 Facebook page. However, she wants to be able to communicate to the HC2 committee that the post is fake, using some secret phrase hidden in the post as a subsequence. To make this method foolproof, she wants the phrase to appear n times in the post. She is asking you to design a post (string) s and a hidden phrase p such that p appears in s as a subsequence exactly n times. Input The first and only line of input contains a single integer n (1 ≤ n ≤ 1 000 000). Output The output should contain two nonempty strings s and p separated by a single space. Each string should be composed of letters (a-z and A-Z: both lowercase and uppercase are allowed) and have length at most 200. The number of occurrences of p in s as a subsequence should be exactly n. If there are many possible solutions, output any of them. It is guaranteed that at least one solution exists. Examples Input 2 Output hHheidi Hei Input 4 Output bbbba ba Input 6 Output aaabb ab Note An occurrence of p as a subsequence in s should be thought of as a set of positions in s such that the letters at these positions, in order, form p. The number of occurences is thus the number of such sets. For example, ab appears 6 times as a subsequence in aaabb, for the following sets of positions: {1, 4}, {1, 5}, {2, 4}, {2, 5}, {3, 4}, {3, 5} (that is, we should choose one of the a's and one of the b's).
2
14
#include <bits/stdc++.h> using namespace std; pair<string, string> sq(int n, char& next) { if (n == 2) return {"a", "a"}; if (n == 1) return {"", "a"}; auto x = next; next = (next == 'z' ? 'A' : next + 1); if (n % 2) { auto [u, p] = sq(n / 2, next); return {u + x + x, p + x}; } auto [u, p] = sq(n / 2 - 1, next); return {x + u + x + x, p + x}; } int main() { std::ios::sync_with_stdio(false); cin.tie(nullptr); cout.precision(10); int n; cin >> n; char next = 'b'; auto [u, p] = sq(n, next); cout << p << u << ' ' << p << '\n'; cout.flush(); return 0; }
CPP
802_H. Fake News (medium)
Thanks to your help, Heidi is confident that no one can fool her. She has now decided to post some fake news on the HC2 Facebook page. However, she wants to be able to communicate to the HC2 committee that the post is fake, using some secret phrase hidden in the post as a subsequence. To make this method foolproof, she wants the phrase to appear n times in the post. She is asking you to design a post (string) s and a hidden phrase p such that p appears in s as a subsequence exactly n times. Input The first and only line of input contains a single integer n (1 ≤ n ≤ 1 000 000). Output The output should contain two nonempty strings s and p separated by a single space. Each string should be composed of letters (a-z and A-Z: both lowercase and uppercase are allowed) and have length at most 200. The number of occurrences of p in s as a subsequence should be exactly n. If there are many possible solutions, output any of them. It is guaranteed that at least one solution exists. Examples Input 2 Output hHheidi Hei Input 4 Output bbbba ba Input 6 Output aaabb ab Note An occurrence of p as a subsequence in s should be thought of as a set of positions in s such that the letters at these positions, in order, form p. The number of occurences is thus the number of such sets. For example, ab appears 6 times as a subsequence in aaabb, for the following sets of positions: {1, 4}, {1, 5}, {2, 4}, {2, 5}, {3, 4}, {3, 5} (that is, we should choose one of the a's and one of the b's).
2
14
#include <bits/stdc++.h> using namespace std; string p, u; char c; void solve(int x) { if (x == 1) return p = "", c = 'a', p += c, u = "", c++, void(); else if (x == 2) return solve(x / 2), p = p + c, u = u + c, c++, void(); else if (x & 1) return solve((x - 1) / 2), p = p + c, u = u + c + c, c++, void(); solve((x - 2) / 2), p = p + c; string c_; c_ += c, u = c_ + u + c + c, c++; } int main() { int n; scanf("%d", &n), solve(n), cout << p + u << " " << p << endl; }
CPP
802_H. Fake News (medium)
Thanks to your help, Heidi is confident that no one can fool her. She has now decided to post some fake news on the HC2 Facebook page. However, she wants to be able to communicate to the HC2 committee that the post is fake, using some secret phrase hidden in the post as a subsequence. To make this method foolproof, she wants the phrase to appear n times in the post. She is asking you to design a post (string) s and a hidden phrase p such that p appears in s as a subsequence exactly n times. Input The first and only line of input contains a single integer n (1 ≤ n ≤ 1 000 000). Output The output should contain two nonempty strings s and p separated by a single space. Each string should be composed of letters (a-z and A-Z: both lowercase and uppercase are allowed) and have length at most 200. The number of occurrences of p in s as a subsequence should be exactly n. If there are many possible solutions, output any of them. It is guaranteed that at least one solution exists. Examples Input 2 Output hHheidi Hei Input 4 Output bbbba ba Input 6 Output aaabb ab Note An occurrence of p as a subsequence in s should be thought of as a set of positions in s such that the letters at these positions, in order, form p. The number of occurences is thus the number of such sets. For example, ab appears 6 times as a subsequence in aaabb, for the following sets of positions: {1, 4}, {1, 5}, {2, 4}, {2, 5}, {3, 4}, {3, 5} (that is, we should choose one of the a's and one of the b's).
2
14
#include <bits/stdc++.h> using namespace std; bool debug = 0; int n, m, k; int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0}; string direc = "RDLU"; long long ln, lk, lm; void etp(bool f = 0) { puts(f ? "YES" : "NO"); exit(0); } void addmod(int &x, int y, int mod = 1000000007) { x += y; if (x >= mod) x -= mod; assert(x >= 0 && x < mod); } void et() { puts("-1"); exit(0); } int b[222]; void fmain(int tid) { for (int i = 4; i <= 100; i++) { b[i] = i * (i - 1) * (i - 2) * (i - 3) / 24; } scanf("%d", &n); map<int, int> mp; for (int i = 70, x = n; i > 3; i--) { while (x >= b[i]) { mp[i]++; x -= b[i]; } } int pre = 0; for (auto p : mp) { for (int(j) = 0; (j) < (int)(p.first - pre); (j)++) printf("a"); for (int(j) = 0; (j) < (int)(p.second); (j)++) printf("b"); pre = p.first; } printf(" aaaab"); } int main() { int t = 1; for (int(i) = 1; (i) <= (int)(t); (i)++) { fmain(i); } return 0; }
CPP
802_H. Fake News (medium)
Thanks to your help, Heidi is confident that no one can fool her. She has now decided to post some fake news on the HC2 Facebook page. However, she wants to be able to communicate to the HC2 committee that the post is fake, using some secret phrase hidden in the post as a subsequence. To make this method foolproof, she wants the phrase to appear n times in the post. She is asking you to design a post (string) s and a hidden phrase p such that p appears in s as a subsequence exactly n times. Input The first and only line of input contains a single integer n (1 ≤ n ≤ 1 000 000). Output The output should contain two nonempty strings s and p separated by a single space. Each string should be composed of letters (a-z and A-Z: both lowercase and uppercase are allowed) and have length at most 200. The number of occurrences of p in s as a subsequence should be exactly n. If there are many possible solutions, output any of them. It is guaranteed that at least one solution exists. Examples Input 2 Output hHheidi Hei Input 4 Output bbbba ba Input 6 Output aaabb ab Note An occurrence of p as a subsequence in s should be thought of as a set of positions in s such that the letters at these positions, in order, form p. The number of occurences is thus the number of such sets. For example, ab appears 6 times as a subsequence in aaabb, for the following sets of positions: {1, 4}, {1, 5}, {2, 4}, {2, 5}, {3, 4}, {3, 5} (that is, we should choose one of the a's and one of the b's).
2
14
#include <bits/stdc++.h> using namespace std; char aux[] = "qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM"; int n, p; int main() { cin >> n; if (n == 1) { cout << "a a"; return 0; } --n; while (n) { if (n % 2 == 1) { cout << aux[p]; ++p, --n; } else { cout << aux[p] << aux[p]; ++p; n = n / 2 - 1; } } for (int i = 0; i <= p; ++i) { cout << aux[i]; } cout << " "; for (int i = 0; i <= p; ++i) { cout << aux[i]; } return 0; }
CPP
802_H. Fake News (medium)
Thanks to your help, Heidi is confident that no one can fool her. She has now decided to post some fake news on the HC2 Facebook page. However, she wants to be able to communicate to the HC2 committee that the post is fake, using some secret phrase hidden in the post as a subsequence. To make this method foolproof, she wants the phrase to appear n times in the post. She is asking you to design a post (string) s and a hidden phrase p such that p appears in s as a subsequence exactly n times. Input The first and only line of input contains a single integer n (1 ≤ n ≤ 1 000 000). Output The output should contain two nonempty strings s and p separated by a single space. Each string should be composed of letters (a-z and A-Z: both lowercase and uppercase are allowed) and have length at most 200. The number of occurrences of p in s as a subsequence should be exactly n. If there are many possible solutions, output any of them. It is guaranteed that at least one solution exists. Examples Input 2 Output hHheidi Hei Input 4 Output bbbba ba Input 6 Output aaabb ab Note An occurrence of p as a subsequence in s should be thought of as a set of positions in s such that the letters at these positions, in order, form p. The number of occurences is thus the number of such sets. For example, ab appears 6 times as a subsequence in aaabb, for the following sets of positions: {1, 4}, {1, 5}, {2, 4}, {2, 5}, {3, 4}, {3, 5} (that is, we should choose one of the a's and one of the b's).
2
14
#include <bits/stdc++.h> using namespace std; long long n; char now; string s, t; inline long long read() { long long x = 0; bool f = 0; char ch = getchar(); for (; !isdigit(ch); ch = getchar()) f ^= (ch == '-'); for (; isdigit(ch); ch = getchar()) x = (x << 3) + (x << 1) + (ch ^ 48); return f ? -x : x; } inline void solve(int len) { if (len == 1) { s = ""; t = "a"; now = 'a'; return; } if (len == 2) { s = "b"; t = "ab"; now = 'b'; return; } if (len & 1) { solve(len / 2); now++; s = s + now + now; t = t + now; return; } else { solve(len / 2 - 1); now++; s = now + s + now + now; t = t + now; return; } } int main() { n = read(); solve(n); cout << t << s << " " << t; return 0; }
CPP
802_H. Fake News (medium)
Thanks to your help, Heidi is confident that no one can fool her. She has now decided to post some fake news on the HC2 Facebook page. However, she wants to be able to communicate to the HC2 committee that the post is fake, using some secret phrase hidden in the post as a subsequence. To make this method foolproof, she wants the phrase to appear n times in the post. She is asking you to design a post (string) s and a hidden phrase p such that p appears in s as a subsequence exactly n times. Input The first and only line of input contains a single integer n (1 ≤ n ≤ 1 000 000). Output The output should contain two nonempty strings s and p separated by a single space. Each string should be composed of letters (a-z and A-Z: both lowercase and uppercase are allowed) and have length at most 200. The number of occurrences of p in s as a subsequence should be exactly n. If there are many possible solutions, output any of them. It is guaranteed that at least one solution exists. Examples Input 2 Output hHheidi Hei Input 4 Output bbbba ba Input 6 Output aaabb ab Note An occurrence of p as a subsequence in s should be thought of as a set of positions in s such that the letters at these positions, in order, form p. The number of occurences is thus the number of such sets. For example, ab appears 6 times as a subsequence in aaabb, for the following sets of positions: {1, 4}, {1, 5}, {2, 4}, {2, 5}, {3, 4}, {3, 5} (that is, we should choose one of the a's and one of the b's).
2
14
#include <bits/stdc++.h> using namespace std; using ll = long long; using pii = pair<int, int>; const int INF = 0x3f3f3f3f, N = 2e5 + 5; inline int read() { int sum = 0, f = 1; char c = getchar(); while (c > '9' || c < '0') { if (c == '-') f = -f; c = getchar(); } while (c >= '0' && c <= '9') sum = sum * 10 + c - 48, c = getchar(); return sum * f; } string s, p; int n; void solve(int n, char c) { if (n <= 0) return; else if (n == 1) { s += c; p += c; return; } else if (n == 2) { s += c; s += c; p += c; return; } else { if (n & 1) { solve(n / 2, c + 1); s = p + c + s.substr(p.size(), s.size() - p.size() + 1) + c + c; p += c; } else { solve(n / 2 - 1, c + 1); s = p + c + c + s.substr(p.size(), s.size() - p.size() + 1) + c + c; p += c; } } } int main() { ios::sync_with_stdio(false); cin.tie(0); cin >> n; solve(n, 'a'); cout << s << ' ' << p << '\n'; return 0; }
CPP
802_H. Fake News (medium)
Thanks to your help, Heidi is confident that no one can fool her. She has now decided to post some fake news on the HC2 Facebook page. However, she wants to be able to communicate to the HC2 committee that the post is fake, using some secret phrase hidden in the post as a subsequence. To make this method foolproof, she wants the phrase to appear n times in the post. She is asking you to design a post (string) s and a hidden phrase p such that p appears in s as a subsequence exactly n times. Input The first and only line of input contains a single integer n (1 ≤ n ≤ 1 000 000). Output The output should contain two nonempty strings s and p separated by a single space. Each string should be composed of letters (a-z and A-Z: both lowercase and uppercase are allowed) and have length at most 200. The number of occurrences of p in s as a subsequence should be exactly n. If there are many possible solutions, output any of them. It is guaranteed that at least one solution exists. Examples Input 2 Output hHheidi Hei Input 4 Output bbbba ba Input 6 Output aaabb ab Note An occurrence of p as a subsequence in s should be thought of as a set of positions in s such that the letters at these positions, in order, form p. The number of occurences is thus the number of such sets. For example, ab appears 6 times as a subsequence in aaabb, for the following sets of positions: {1, 4}, {1, 5}, {2, 4}, {2, 5}, {3, 4}, {3, 5} (that is, we should choose one of the a's and one of the b's).
2
14
#include <bits/stdc++.h> using namespace std; void file_put() { freopen("filename.in", "r", stdin); freopen("filename.out", "w", stdout); } const int N = 105; int n = 100, k, a[N], num[N], s = 0, p = 0; int C(int n) { return n * (n - 1) * (n - 2) / 6; } int main() { scanf("%d", &k); for (int i = (1); i < (n + 1); i++) a[i] = C(i); for (int i = n; i && k; i--) { num[i] = k / a[i], k %= a[i]; if (!p && num[i]) p = i; } for (int i = (1); i < (p + 1); i++) { printf("a"); for (int j = (1); j < (num[i] + 1); j++) printf("b"); } printf(" aaab\n"); return 0; }
CPP
802_H. Fake News (medium)
Thanks to your help, Heidi is confident that no one can fool her. She has now decided to post some fake news on the HC2 Facebook page. However, she wants to be able to communicate to the HC2 committee that the post is fake, using some secret phrase hidden in the post as a subsequence. To make this method foolproof, she wants the phrase to appear n times in the post. She is asking you to design a post (string) s and a hidden phrase p such that p appears in s as a subsequence exactly n times. Input The first and only line of input contains a single integer n (1 ≤ n ≤ 1 000 000). Output The output should contain two nonempty strings s and p separated by a single space. Each string should be composed of letters (a-z and A-Z: both lowercase and uppercase are allowed) and have length at most 200. The number of occurrences of p in s as a subsequence should be exactly n. If there are many possible solutions, output any of them. It is guaranteed that at least one solution exists. Examples Input 2 Output hHheidi Hei Input 4 Output bbbba ba Input 6 Output aaabb ab Note An occurrence of p as a subsequence in s should be thought of as a set of positions in s such that the letters at these positions, in order, form p. The number of occurences is thus the number of such sets. For example, ab appears 6 times as a subsequence in aaabb, for the following sets of positions: {1, 4}, {1, 5}, {2, 4}, {2, 5}, {3, 4}, {3, 5} (that is, we should choose one of the a's and one of the b's).
2
14
#include <bits/stdc++.h> using namespace std; long long c[210][5], n; vector<char> res; int main(void) { c[0][0] = 1; for (int i = 1; i <= 200; i++) { c[i][0] = 1; for (int j = 1; j <= 5; j++) c[i][j] = c[i - 1][j] + c[i - 1][j - 1]; } cin >> n; int r = 125; while (c[r][4] > n) r--; for (int i = r; i; i--) { while (n && n >= c[i][4]) { res.push_back('b'); n -= c[i][4]; } res.push_back('a'); } for (int i = res.size() - 1; i >= 0; i--) putchar(res[i]); printf(" aaaab\n"); return 0; }
CPP
802_H. Fake News (medium)
Thanks to your help, Heidi is confident that no one can fool her. She has now decided to post some fake news on the HC2 Facebook page. However, she wants to be able to communicate to the HC2 committee that the post is fake, using some secret phrase hidden in the post as a subsequence. To make this method foolproof, she wants the phrase to appear n times in the post. She is asking you to design a post (string) s and a hidden phrase p such that p appears in s as a subsequence exactly n times. Input The first and only line of input contains a single integer n (1 ≤ n ≤ 1 000 000). Output The output should contain two nonempty strings s and p separated by a single space. Each string should be composed of letters (a-z and A-Z: both lowercase and uppercase are allowed) and have length at most 200. The number of occurrences of p in s as a subsequence should be exactly n. If there are many possible solutions, output any of them. It is guaranteed that at least one solution exists. Examples Input 2 Output hHheidi Hei Input 4 Output bbbba ba Input 6 Output aaabb ab Note An occurrence of p as a subsequence in s should be thought of as a set of positions in s such that the letters at these positions, in order, form p. The number of occurences is thus the number of such sets. For example, ab appears 6 times as a subsequence in aaabb, for the following sets of positions: {1, 4}, {1, 5}, {2, 4}, {2, 5}, {3, 4}, {3, 5} (that is, we should choose one of the a's and one of the b's).
2
14
#include <bits/stdc++.h> const int F[8] = {1, 21, 231, 1771, 10626, 53130, 230230, 888030}; int N, f[1000001], c[1000001], U[8]; int main() { f[0] = 0; for (int i = 1; i <= 1000000; i++) f[i] = 1000000000; for (int i = 0; i < 8; i++) for (int j = F[i]; j <= 1000000; j++) if (f[j - F[i]] + 1 < f[j]) { f[j] = f[j - F[i]] + 1; c[j] = i; } while (~scanf("%d", &N)) { for (int i = 0; i < 8; i++) U[i] = 0; for (int i = N; i; i -= F[c[i]]) U[c[i]]++; for (int i = 7; ~i; i--) { for (int T = U[i]; T--;) putchar('a'); putchar('b'); } printf("bbbbbbbbbbbbbbbbbbb abbbbbbbbbbbbbbbbbbbb\n"); } return 0; }
CPP
802_H. Fake News (medium)
Thanks to your help, Heidi is confident that no one can fool her. She has now decided to post some fake news on the HC2 Facebook page. However, she wants to be able to communicate to the HC2 committee that the post is fake, using some secret phrase hidden in the post as a subsequence. To make this method foolproof, she wants the phrase to appear n times in the post. She is asking you to design a post (string) s and a hidden phrase p such that p appears in s as a subsequence exactly n times. Input The first and only line of input contains a single integer n (1 ≤ n ≤ 1 000 000). Output The output should contain two nonempty strings s and p separated by a single space. Each string should be composed of letters (a-z and A-Z: both lowercase and uppercase are allowed) and have length at most 200. The number of occurrences of p in s as a subsequence should be exactly n. If there are many possible solutions, output any of them. It is guaranteed that at least one solution exists. Examples Input 2 Output hHheidi Hei Input 4 Output bbbba ba Input 6 Output aaabb ab Note An occurrence of p as a subsequence in s should be thought of as a set of positions in s such that the letters at these positions, in order, form p. The number of occurences is thus the number of such sets. For example, ab appears 6 times as a subsequence in aaabb, for the following sets of positions: {1, 4}, {1, 5}, {2, 4}, {2, 5}, {3, 4}, {3, 5} (that is, we should choose one of the a's and one of the b's).
2
14
#include <bits/stdc++.h> using namespace std; const int T = 700; const long long f[] = {0LL, 1LL, 8LL, 36LL, 120LL, 330LL, 792LL, 1716LL, 3432LL, 6435LL, 11440LL, 19448LL, 31824LL, 50388LL, 77520LL, 116280LL, 170544LL, 245157LL, 346104LL, 480700LL, 657800LL, 888030LL, 1184040LL, 1560780LL, 2035800LL, 2629575LL, 3365856LL, 4272048LL, 5379616LL, 6724520LL, 8347680LL, 10295472LL, 12620256LL, 15380937LL, 18643560LL, 22481940LL, 26978328LL, 32224114LL, 38320568LL, 45379620LL, 53524680LL, 62891499LL, 73629072LL, 85900584LL, 99884400LL, 115775100LL, 133784560LL, 154143080LL, 177100560LL, 202927725LL, 231917400LL, 264385836LL, 300674088LL, 341149446LL, 386206920LL, 436270780LL, 491796152LL, 553270671LL, 621216192LL, 696190560LL, 778789440LL, 869648208LL, 969443904LL, 1078897248LL, 1198774720LL, 1329890705LL, 1473109704LL, 1629348612LL, 1799579064LL, 1984829850LL, 2186189400LL, 2404808340LL, 2641902120LL, 2898753715LL, 3176716400LL, 3477216600LL, 3801756816LL, 4151918628LL, 4529365776LL, 4935847320LL, 5373200880LL, 5843355957LL, 6348337336LL, 6890268572LL, 7471375560LL, 8093990190LL, 8760554088LL, 9473622444LL, 10235867928LL, 11050084695LL, 11919192480LL, 12846240784LL, 13834413152LL, 14887031544LL, 16007560800LL, 17199613200LL, 18466953120LL, 19813501785LL, 21243342120LL, 22760723700LL, 24370067800LL, 26075972546LL, 27883218168LL, 29796772356LL, 31821795720LL, 33963647355LL, 36227890512LL, 38620298376LL, 41146859952LL, 43813786060LL, 46627515440LL, 49594720968LL, 52722315984LL, 56017460733LL, 59487568920LL, 63140314380LL, 66983637864LL, 71025753942LL, 75275158024LL, 79740633500LL, 84431259000LL, 89356415775LL, 94525795200LL, 99949406400LL, 105637584000LL, 111600996000LL, 117850651776LL, 124397910208LL, 131254487936LL, 138432467745LL, 145944307080LL, 153802846692LL, 162021319416LL, 170613359082LL, 179593009560LL, 188974733940LL, 198773423848LL, 209004408899LL, 219683466288LL, 230826830520LL, 242451203280LL, 254573763444LL, 267212177232LL, 280384608504LL, 294109729200LL, 308406729925LL, 323295330680LL, 338795791740LL, 354928924680LL, 371716103550LL, 389179276200LL, 407340975756LL, 426224332248LL, 445853084391LL, 466251591520LL, 487444845680LL, 509458483872LL, 532318800456LL, 556052759712LL, 580688008560LL, 606252889440LL, 632776453353LL, 660288473064LL, 688819456468LL, 718400660120LL, 749064102930LL, 780842580024LL, 813769676772LL, 847879782984LL, 883208107275LL, 919790691600LL, 957664425960LL, 996867063280LL, 1037437234460LL, 1079414463600LL, 1122839183400LL, 1167752750736LL, 1214197462413LL, 1262216571096LL, 1311854301420LL, 1363155866280LL, 1416167483302LL, 1470936391496LL, 1527510868092LL, 1585940245560LL, 1646274928815LL, 1708566412608LL, 1772867299104LL, 1839231315648LL, 1907713332720LL, 1978369382080LL, 2051256675104LL, 2126433621312LL, 2203959847089LL, 2283896214600LL, 2366304840900LL, 2451249117240LL, 2538793728570LL, 2629004673240LL, 2721949282900LL, 2817696242600LL, 2916315611091LL, 3017878841328LL, 3122458801176LL, 3230129794320LL, 3340967581380LL, 3455049401232LL, 3572453992536LL, 3693261615472LL, 3817554073685LL, 3945414736440LL, 4076928560988LL, 4212182115144LL, 4351263600078LL, 4494262873320LL, 4641271471980LL, 4792382636184LL, 4947691332727LL, 5107294278944LL, 5271289966800LL, 5439778687200LL, 5612862554520LL, 5790645531360LL, 5973233453520LL, 6160734055200LL, 6353256994425LL, 6550913878696LL, 6753818290868LL, 6962085815256LL, 7175834063970LL, 7395182703480LL, 7620253481412LL, 7851170253576LL, 8088059011227LL, 8331047908560LL, 8580267290440LL, 8835849720368LL, 9097930008684LL, 9366645241008LL, 9642134806920LL, 9924540428880LL, 10214006191389LL, 10510678570392LL, 10814706462924LL, 11126241217000LL, 11445436661750LL, 11772449137800LL, 12107437527900LL, 12450563287800LL, 12801990477375LL, 13161885792000LL, 13530418594176LL, 13907760945408LL, 14294087638336LL, 14689576229120LL, 15094407070080LL, 15508763342592LL, 15932831090241LL, 16366799252232LL, 16810859697060LL, 17265207256440LL, 17730039759498LL, 18205558067224LL, 18691966107188LL, 19189470908520LL, 19698282637155LL, 20218614631344LL, 20750683437432LL, 21294708845904LL, 21850913927700LL, 22419525070800LL, 23000772017080LL, 23594887899440LL, 24202109279205LL, 24822676183800LL, 25456832144700LL, 26104824235656LL, 26766903111198LL, 27443323045416LL, 28134341971020LL, 28840221518680LL, 29561227056647LL, 30297627730656LL, 31049696504112LL, 31817710198560LL, 32601949534440LL, 33402699172128LL, 34220247753264LL, 35054887942368LL, 35906916468745LL, 36776634168680LL, 37664346027924LL, 38570361224472LL, 39494993171634LL, 40438559561400LL, 41401382408100LL, 42383788092360LL, 43386107405355LL, 44408675593360LL, 45451832402600LL, 46515922124400LL, 47601293640636LL, 48708300469488LL, 49837300811496LL, 50988657595920LL, 52162738527405LL, 53359916132952LL, 54580567809196LL, 55825075869992LL, 57093827594310LL, 58387215274440LL, 59705636264508LL, 61049493029304LL, 62419193193423LL, 63815149590720LL, 65237780314080LL, 66687508765504LL, 68164763706512LL, 69669979308864LL, 71203595205600LL, 72766056542400LL, 74357814029265LL, 75979323992520LL, 77631048427140LL, 79313455049400LL, 81027017349850LL, 82772214646616LL, 84549532139028LL, 86359460961576LL, 88202498238195LL, 90079147136880LL, 91989916924632LL, 93935323022736LL, 95915887062372LL, 97932136940560LL, 99984606876440LL, 102073837467888LL, 104200375748469LL, 106364775244728LL, 108567596033820LL, 110809404801480LL, 113090774900334LL, 115412286408552LL, 117774526188844LL, 120178087947800LL, 122623572295575LL, 125111586805920LL, 127642746076560LL, 130217671789920LL, 132836992774200LL, 135501345064800LL, 138211371966096LL, 140967724113568LL, 143771059536281LL, 146622043719720LL, 149521349668980LL, 152469657972312LL, 155467656865026LL, 158516042293752LL, 161615517981060LL, 164766795490440LL, 167970594291643LL, 171227641826384LL, 174538673574408LL, 177904433119920LL, 181325672218380LL, 184803150863664LL, 188337637355592LL, 191929908367824LL, 195580749016125LL, 199290952927000LL, 203061322306700LL, 206892668010600LL, 210785809612950LL, 214741575477000LL, 218760802825500LL, 222844337811576LL, 226993035589983LL, 231207760388736LL, 235489385581120LL, 239838793758080LL, 244256876800992LL, 248744535954816LL, 253302681901632LL, 257932234834560LL, 262634124532065LL, 267409290432648LL, 272258681709924LL, 277183257348088LL, 282183986217770LL, 287261847152280LL, 292417829024244LL, 297652930822632LL, 302968161730179LL, 308364541201200LL, 313843099039800LL, 319404875478480LL, 325050921257140LL, 330782297702480LL, 336600076807800LL, 342505341313200LL, 348499184786181LL, 354582711702648LL, 360757037528316LL, 367023288800520LL, 373382603210430LL, 379836129685672LL, 386385028473356LL, 393030471223512LL, 399773641072935LL, 406615732729440LL, 413557952556528LL, 420601518658464LL, 427747660965768LL, 434997621321120LL, 442352653565680LL, 449814023625824LL, 457383009600297LL, 465060901847784LL, 472849003074900LL, 480748628424600LL, 488761105565010LL, 496887774778680LL, 505129989052260LL, 513489114166600LL, 521966528787275LL, 530563624555536LL, 539281806179688LL, 548122491526896LL, 557087111715420LL, 566177111207280LL, 575393947901352LL, 584739093226896LL, 594214032237517LL, 603820263705560LL, 613559300216940LL, 623432668266408LL, 633441908353254LL, 643588575077448LL, 653874237236220LL, 664300477921080LL, 674868894615279LL, 685581099291712LL, 696438718511264LL, 707443393521600LL, 718596780356400LL, 729900549935040LL, 741356388162720LL, 752965996031040LL, 764731089719025LL, 776653400694600LL, 788734675816516LL, 800976677436728LL, 813381183503226LL, 825949987663320LL, 838684899367380LL, 851587743973032LL, 864660362849811LL, 877904613484272LL, 891322369585560LL, 904915521191440LL, 918685974774788LL, 932635653350544LL, 946766496583128LL, 961080460894320LL, 975579519571605LL, 990265662876984LL, 1005140898156252LL, 1020207249948744LL, 1035466760097550LL, 1050921487860200LL, 1066573510019820LL, 1082424920996760LL, 1098477832960695LL, 1114734375943200LL, 1131196697950800LL, 1147866965078496LL, 1164747361623768LL, 1181840090201056LL, 1199147371856720LL, 1216671446184480LL, 1234414571441337LL, 1252379024663976LL, 1270567101785652LL, 1288981117753560LL, 1307623406646690LL, 1326496321794168LL, 1345602235894084LL, 1364943541132808LL, 1384522649304795LL, 1404341991932880LL, 1424404020389064LL, 1444711206015792LL, 1465266040247724LL, 1486071034734000LL, 1507128721461000LL, 1528441652875600LL, 1550012402008925LL, 1571843562600600LL, 1593937749223500LL, 1616297597409000LL, 1638925763772726LL, 1661824926140808LL, 1684997783676636LL, 1708447057008120LL, 1732175488355455LL, 1756185841659392LL, 1780480902710016LL, 1805063479276032LL, 1829936401234560LL, 1855102520701440LL, 1880564712162048LL, 1906325872602624LL, 1932388921642113LL, 1958756801664520LL, 1985432477951780LL, 2012418938817144LL, 2039719195739082LL, 2067336283495704LL, 2095273260299700LL, 2123533207933800LL, 2152119231886755LL, 2181034461489840LL, 2210282050053880LL, 2239865175006800LL, 2269787038031700LL, 2300050865205456LL, 2330659907137848LL, 2361617439111216LL, 2392926761220645LL, 2424591198514680LL, 2456614101136572LL, 2488998844466056LL, 2521748829261662LL, 2554867481803560LL, 2588358254036940LL, 2622224623715928LL, 2656470094548039LL, 2691098196339168LL, 2726112485139120LL, 2761516543387680LL, 2797313980061224LL, 2833508430819872LL, 2870103558155184LL, 2907103051538400LL, 2944510627569225LL, 2982330030125160LL, 3020565030511380LL, 3059219427611160LL, 3098297048036850LL, 3137801746281400LL, 3177737404870436LL, 3218107934514888LL, 3258917274264171LL, 3300169391659920LL, 3341868282890280LL, 3384017972944752LL, 3426622515769596LL, 3469685994423792LL, 3513212521235560LL, 3557206237959440LL, 3601671315933933LL, 3646611956239704LL, 3692032389858348LL, 3737936877831720LL, 3784329711421830LL, 3831215212271304LL, 3878597732564412LL, 3926481655188664LL, 3974871393896975LL, 4023771393470400LL, 4073186129881440LL, 4123120110457920LL, 4173577874047440LL, 4224563991182400LL, 4276083064245600LL, 4328139727636416LL, 4380738647937553LL, 4433884524082376LL, 4487582087522820LL, 4541836102397880LL, 4596651365702682LL, 4652032707458136LL, 4707984990881172LL, 4764513112555560LL, 4821622002603315LL, 4879316624856688LL, 4937601977030744LL, 4996483090896528LL, 5055965032454820LL, 5116052902110480LL, 5176751834847384LL, 5238067000403952LL, 5300003603449269LL, 5362566883759800LL, 5425762116396700LL, 5489594611883720LL, 5554069716385710LL, 5619192811887720LL, 5684969316374700LL, 5751404684011800LL, 5818504405325271LL, 5886274007383968LL, 5954719053981456LL, 6023845145818720LL, 6093657920687480LL, 6164163053654112LL, 6235366257244176LL, 6307273281627552LL, 6379889914804185LL, 6453221982790440LL, 6527275349806068LL, 6602055918461784LL, 6677569629947458LL, 6753822464220920LL, 6830820440197380LL, 6908569615939464LL, 6987076088847867LL, 7066345995852624LL, 7146385513605000LL, 7227200858670000LL, 7308798287719500LL, 7391184097726000LL, 7474364626157000LL, 7558346251170000LL, 7643135391808125LL, 7728738508196376LL, 7815162101738508LL, 7902412715314536LL, 7990496933478870LL, 8079421382659080LL, 8169192731355292LL, 8259817690340216LL, 8351303012859807LL, 8443655494834560LL, 8536881975061440LL, 8630989335416448LL, 8725984501057824LL, 8821874440629888LL, 8918666166467520LL, 9016366734801280LL, 9114983245963169LL, 9214522844593032LL, 9314992719845604LL, 9416400105598200LL, 9518752280659050LL, 9622056568976280LL, 9726320339847540LL, 9831551008130280LL, 9937756034452675LL, 10044942925425200LL, 10153119233852856LL, 10262292558948048LL, 10372470546544116LL, 10483660889309520LL, 10595871326962680LL, 10709109646487472LL, 10823383682349381LL, 10938701316712312LL, 11055070479656060LL, 11172499149394440LL, 11290995352494078LL, 11410567164093864LL, 11531222708125068LL, 11652970157532120LL, 11775817734494055LL, 11899773710646624LL, 12024846407305072LL, 12151044195687584LL, 12278375497139400LL, 12406848783357600LL, 12536472576616560LL, 12667255449994080LL, 12799206027598185LL, 12932332984794600LL, 13066645048434900LL, 13202150997085336LL, 13338859661256338LL, 13476779923632696LL, 13615920719304420LL, 13756291035998280LL, 13897899914310027LL, 14040756447937296LL, 14184869783913192LL, 14330249122840560LL, 14476903719126940LL, 14624842881220208LL, 14774075971844904LL, 14924612408239248LL, 15076461662392845LL, 15229633261285080LL, 15384136787124204LL, 15539981877587112LL, 15697178226059814LL, 15855735581878600LL, 16015663750571900LL, 16176972594102840LL, 16339672031112495LL, 16503772037163840LL, 16669282644986400LL, 16836213944721600LL, 17004576084168816LL, 17174379269032128LL, 17345633763167776LL, 17518349888832320LL, 17692538026931505LL, 17868208617269832LL, 18045372158800836LL, 18224039209878072LL, 18404220388506810LL, 18585926372596440LL, 18769167900213588LL, 18953955769835944LL, 19140300840606803LL, 19328214032590320LL, 19517706327027480LL, 19708788766592784LL, 19901472455651652LL, 20095768560518544LL, 20291688309715800LL, 20489242994233200LL, 20688443967788245LL, 20889302647087160LL, 21091830512086620LL, 21296039106256200LL, 21501940036841550LL, 21709544975128296LL, 21918865656706668LL, 22129913881736856LL, 22342701515215095LL, 22557240487240480LL, 22773542793282512LL, 22991620494449376LL, 23211485717756952LL, 23433150656398560LL, 23656627570015440LL, 23881928784967968LL, 24109066694607609LL, 24338053759549608LL, 24568902507946420LL, 24801625535761880LL, 25036235507046114LL, 25272745154211192LL, 25511167278307524LL, 25751514749301000LL, 25993800506350875LL, 26238037558088400LL, 26484238982896200LL, 26732417929188400LL, 26982587615691500LL, 27234761331726000LL, 27488952437488776LL, 27745174364336208LL, 28003440615068061LL, 28263764764212120LL, 28526160458309580LL, 28790641416201192LL, 29057221429314166LL, 29325914361949832LL, 29596734151572060LL, 29869694809096440LL, 30144810419180223LL, 30422095140513024LL, 30701563206108288LL, 30983228923595520LL, 31267106675513280LL, 31553210919602944LL, 31841556189103232LL, 32132157093045504LL, 32425028316549825LL, 32720184621121800LL, 33017640844950180LL, 33317411903205240LL, 33619512788337930LL, 33923958570379800LL, 34230764397243700LL, 34539945495025256LL, 34851517168305123LL, 35165494800452016LL, 35481893853926520LL, 35800729870585680LL, 36122018471988372LL, 36445775359701456LL, 36772016315606712LL, 37100757202208560LL, 37432013962942565LL, 37765802622484728LL, 38102139287061564LL, 38441040144760968LL, 38782521465843870LL, 39126599603056680LL, 39473290991944524LL, 39822612151165272LL, 40174579682804359LL, 40529210272690400LL, 40886520690711600LL, 41246527791132960LL, 41609248512914280LL, 41974699880028960LL, 42342899001783600LL, 42713863073138400LL}; long long K; long long c[T + 1]; int main() { scanf("%I64d", &K); for (int i = T; i; i--) c[i] = K / f[i], K %= f[i]; int t = T; while (!c[t]) t--; for (int i = t; i; i--) { for (int j = 1; j <= c[i]; j++) putchar('f'); printf("estival"); } printf(" festival\n"); return 0; }
CPP
802_H. Fake News (medium)
Thanks to your help, Heidi is confident that no one can fool her. She has now decided to post some fake news on the HC2 Facebook page. However, she wants to be able to communicate to the HC2 committee that the post is fake, using some secret phrase hidden in the post as a subsequence. To make this method foolproof, she wants the phrase to appear n times in the post. She is asking you to design a post (string) s and a hidden phrase p such that p appears in s as a subsequence exactly n times. Input The first and only line of input contains a single integer n (1 ≤ n ≤ 1 000 000). Output The output should contain two nonempty strings s and p separated by a single space. Each string should be composed of letters (a-z and A-Z: both lowercase and uppercase are allowed) and have length at most 200. The number of occurrences of p in s as a subsequence should be exactly n. If there are many possible solutions, output any of them. It is guaranteed that at least one solution exists. Examples Input 2 Output hHheidi Hei Input 4 Output bbbba ba Input 6 Output aaabb ab Note An occurrence of p as a subsequence in s should be thought of as a set of positions in s such that the letters at these positions, in order, form p. The number of occurences is thus the number of such sets. For example, ab appears 6 times as a subsequence in aaabb, for the following sets of positions: {1, 4}, {1, 5}, {2, 4}, {2, 5}, {3, 4}, {3, 5} (that is, we should choose one of the a's and one of the b's).
2
14
#include <bits/stdc++.h> using namespace std; string s = "FESTIVAL"; long long dp[1010][10]; int a[1010]; int main(void) { int i, j, k; dp[0][0] = 1; for ((i) = 0; (i) < (int)(1000); (i)++) for ((j) = 0; (j) < (int)(8); (j)++) for ((k) = 0; (k) < (int)(8); (k)++) if (j <= k) dp[i + 1][k] = min(dp[i + 1][k] + dp[i][j], (1ll << 60)); long long K; cin >> K; for (i = 25; i >= 1; i--) { a[i] = K / dp[i][7]; K %= dp[i][7]; } string s; for ((i) = 0; (i) < (int)(25); (i)++) { s += "FESTIVA"; for ((j) = 0; (j) < (int)(a[i + 1]); (j)++) s += 'L'; } cout << s << ' ' << "FESTIVAL" << endl; return 0; }
CPP
802_H. Fake News (medium)
Thanks to your help, Heidi is confident that no one can fool her. She has now decided to post some fake news on the HC2 Facebook page. However, she wants to be able to communicate to the HC2 committee that the post is fake, using some secret phrase hidden in the post as a subsequence. To make this method foolproof, she wants the phrase to appear n times in the post. She is asking you to design a post (string) s and a hidden phrase p such that p appears in s as a subsequence exactly n times. Input The first and only line of input contains a single integer n (1 ≤ n ≤ 1 000 000). Output The output should contain two nonempty strings s and p separated by a single space. Each string should be composed of letters (a-z and A-Z: both lowercase and uppercase are allowed) and have length at most 200. The number of occurrences of p in s as a subsequence should be exactly n. If there are many possible solutions, output any of them. It is guaranteed that at least one solution exists. Examples Input 2 Output hHheidi Hei Input 4 Output bbbba ba Input 6 Output aaabb ab Note An occurrence of p as a subsequence in s should be thought of as a set of positions in s such that the letters at these positions, in order, form p. The number of occurences is thus the number of such sets. For example, ab appears 6 times as a subsequence in aaabb, for the following sets of positions: {1, 4}, {1, 5}, {2, 4}, {2, 5}, {3, 4}, {3, 5} (that is, we should choose one of the a's and one of the b's).
2
14
import java.util.Arrays; import java.util.Scanner; public class H { static Scanner sc = new Scanner(System.in); public static void main(String[] args) { int N = sc.nextInt(); int[][] c = new int[10][10]; for (int i = 0; i < c[0].length; i++) { c[0][i] = i + 1; } for (int i = 1; i < c.length; i++) { c[i][0] = 1; for (int j = 1; j < c[i].length; j++) { c[i][j] = c[i][j - 1] + c[i - 1][j]; } } int[] count = new int[c.length]; for (int i = c[0].length - 1; i >= 0; i--) { count[i] = N / c[c.length - 1][i]; N %= c[c.length - 1][i]; } StringBuilder sb = new StringBuilder(); for (int i = 0; i < count.length; i++) { for (int j = 0; j < c.length; j++) { sb.append((char)('a' + j)); } for (int j = 0; j < count[i]; j++) { sb.append((char)('a' + c[0].length)); } } sb.append(' '); for (int i = 0; i <= c.length; i++) { sb.append((char)('a' + i)); } System.out.println(sb); } }
JAVA
802_H. Fake News (medium)
Thanks to your help, Heidi is confident that no one can fool her. She has now decided to post some fake news on the HC2 Facebook page. However, she wants to be able to communicate to the HC2 committee that the post is fake, using some secret phrase hidden in the post as a subsequence. To make this method foolproof, she wants the phrase to appear n times in the post. She is asking you to design a post (string) s and a hidden phrase p such that p appears in s as a subsequence exactly n times. Input The first and only line of input contains a single integer n (1 ≤ n ≤ 1 000 000). Output The output should contain two nonempty strings s and p separated by a single space. Each string should be composed of letters (a-z and A-Z: both lowercase and uppercase are allowed) and have length at most 200. The number of occurrences of p in s as a subsequence should be exactly n. If there are many possible solutions, output any of them. It is guaranteed that at least one solution exists. Examples Input 2 Output hHheidi Hei Input 4 Output bbbba ba Input 6 Output aaabb ab Note An occurrence of p as a subsequence in s should be thought of as a set of positions in s such that the letters at these positions, in order, form p. The number of occurences is thus the number of such sets. For example, ab appears 6 times as a subsequence in aaabb, for the following sets of positions: {1, 4}, {1, 5}, {2, 4}, {2, 5}, {3, 4}, {3, 5} (that is, we should choose one of the a's and one of the b's).
2
14
#include <bits/stdc++.h> using namespace std; const int N = 4e5 + 5; int n; int main() { ios_base::sync_with_stdio(0); ; cin >> n; vector<int> v; if (n == 1) { cout << "a a\n"; return 0; } while (n > 2) { if (n & 1) { v.push_back(1); } else { v.push_back(2); n -= 2; } n >>= 1; } reverse(v.begin(), v.end()); string s = "", p = "", t = ""; char q = 'a'; if (n == 2) { p = "a"; t = "a"; q++; } int len = v.size(); for (int i = 0; i < len; i++) { if (v[i] == 1) { p += q; s += q; s += q; q++; } else { p += q; t = q + t; s += q; s += q; q++; } } cout << p + t + s << " " << p << endl; }
CPP
802_H. Fake News (medium)
Thanks to your help, Heidi is confident that no one can fool her. She has now decided to post some fake news on the HC2 Facebook page. However, she wants to be able to communicate to the HC2 committee that the post is fake, using some secret phrase hidden in the post as a subsequence. To make this method foolproof, she wants the phrase to appear n times in the post. She is asking you to design a post (string) s and a hidden phrase p such that p appears in s as a subsequence exactly n times. Input The first and only line of input contains a single integer n (1 ≤ n ≤ 1 000 000). Output The output should contain two nonempty strings s and p separated by a single space. Each string should be composed of letters (a-z and A-Z: both lowercase and uppercase are allowed) and have length at most 200. The number of occurrences of p in s as a subsequence should be exactly n. If there are many possible solutions, output any of them. It is guaranteed that at least one solution exists. Examples Input 2 Output hHheidi Hei Input 4 Output bbbba ba Input 6 Output aaabb ab Note An occurrence of p as a subsequence in s should be thought of as a set of positions in s such that the letters at these positions, in order, form p. The number of occurences is thus the number of such sets. For example, ab appears 6 times as a subsequence in aaabb, for the following sets of positions: {1, 4}, {1, 5}, {2, 4}, {2, 5}, {3, 4}, {3, 5} (that is, we should choose one of the a's and one of the b's).
2
14
#include <bits/stdc++.h> using namespace std; stack<int> st; int n; string str, pat; int main() { str = ""; pat = ""; cin >> n; while (n) { if (n % 2) st.push(1), n = (n - 1) / 2; else st.push(0), n = (n - 2) / 2; } int curr, cont = 0; string ch = " "; while (!st.empty()) { curr = st.top(); st.pop(); ch[0] = char('a' + cont); pat += ch; if (cont) str += ch + ch; if (!curr) str.insert(cont, ch); str.insert(cont, ch); cont++; } cout << str << " " << pat << "\n"; return 0; }
CPP
802_H. Fake News (medium)
Thanks to your help, Heidi is confident that no one can fool her. She has now decided to post some fake news on the HC2 Facebook page. However, she wants to be able to communicate to the HC2 committee that the post is fake, using some secret phrase hidden in the post as a subsequence. To make this method foolproof, she wants the phrase to appear n times in the post. She is asking you to design a post (string) s and a hidden phrase p such that p appears in s as a subsequence exactly n times. Input The first and only line of input contains a single integer n (1 ≤ n ≤ 1 000 000). Output The output should contain two nonempty strings s and p separated by a single space. Each string should be composed of letters (a-z and A-Z: both lowercase and uppercase are allowed) and have length at most 200. The number of occurrences of p in s as a subsequence should be exactly n. If there are many possible solutions, output any of them. It is guaranteed that at least one solution exists. Examples Input 2 Output hHheidi Hei Input 4 Output bbbba ba Input 6 Output aaabb ab Note An occurrence of p as a subsequence in s should be thought of as a set of positions in s such that the letters at these positions, in order, form p. The number of occurences is thus the number of such sets. For example, ab appears 6 times as a subsequence in aaabb, for the following sets of positions: {1, 4}, {1, 5}, {2, 4}, {2, 5}, {3, 4}, {3, 5} (that is, we should choose one of the a's and one of the b's).
2
14
#include <bits/stdc++.h> using namespace std; int IN() { int c, f, x; while (!isdigit(c = getchar()) && c != '-') ; c == '-' ? (f = 1, x = 0) : (f = 0, x = c - '0'); while (isdigit(c = getchar())) x = (x << 1) + (x << 3) + c - '0'; return !f ? x : -x; } string s, t, alp = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; int n, c = 1; void cal(int n) { if (n == 2) { s = "a", t = "a"; return; } if (n == 3) { s = "a", t = "aa"; return; } if (n & 1) { cal((n - 1) / 2); s += alp[c]; t += alp[c]; t += alp[c++]; } else { cal(n - 1); s += alp[c]; t += alp[c++]; } } int main() { n = IN(); if (n == 1) return puts("a a"), 0; cal(n); printf("%s %s\n", (s + t).c_str(), s.c_str()); }
CPP
802_H. Fake News (medium)
Thanks to your help, Heidi is confident that no one can fool her. She has now decided to post some fake news on the HC2 Facebook page. However, she wants to be able to communicate to the HC2 committee that the post is fake, using some secret phrase hidden in the post as a subsequence. To make this method foolproof, she wants the phrase to appear n times in the post. She is asking you to design a post (string) s and a hidden phrase p such that p appears in s as a subsequence exactly n times. Input The first and only line of input contains a single integer n (1 ≤ n ≤ 1 000 000). Output The output should contain two nonempty strings s and p separated by a single space. Each string should be composed of letters (a-z and A-Z: both lowercase and uppercase are allowed) and have length at most 200. The number of occurrences of p in s as a subsequence should be exactly n. If there are many possible solutions, output any of them. It is guaranteed that at least one solution exists. Examples Input 2 Output hHheidi Hei Input 4 Output bbbba ba Input 6 Output aaabb ab Note An occurrence of p as a subsequence in s should be thought of as a set of positions in s such that the letters at these positions, in order, form p. The number of occurences is thus the number of such sets. For example, ab appears 6 times as a subsequence in aaabb, for the following sets of positions: {1, 4}, {1, 5}, {2, 4}, {2, 5}, {3, 4}, {3, 5} (that is, we should choose one of the a's and one of the b's).
2
14
#include <bits/stdc++.h> using namespace std; int dp[4][100]; int main() { int n, f = 25, m = 100; dp[0][0] = 1; cin >> n; string a = ""; while (f--) a += "abcd"; a += " abcde"; for (int l = 0; l < 4; l++) for (int i = 1; i < 100; i++) dp[l][i] = dp[l][i - 1] + ((i % 4 == l) ? ((l == 0) ? 1 : dp[l - 1][i - 1]) : 0); while (n) { if (dp[3][m - 1] <= n) { a.insert(m, n / dp[3][m - 1], 'e'); n = n % dp[3][m - 1]; } m -= 4; } cout << a << endl; return 0; }
CPP
802_H. Fake News (medium)
Thanks to your help, Heidi is confident that no one can fool her. She has now decided to post some fake news on the HC2 Facebook page. However, she wants to be able to communicate to the HC2 committee that the post is fake, using some secret phrase hidden in the post as a subsequence. To make this method foolproof, she wants the phrase to appear n times in the post. She is asking you to design a post (string) s and a hidden phrase p such that p appears in s as a subsequence exactly n times. Input The first and only line of input contains a single integer n (1 ≤ n ≤ 1 000 000). Output The output should contain two nonempty strings s and p separated by a single space. Each string should be composed of letters (a-z and A-Z: both lowercase and uppercase are allowed) and have length at most 200. The number of occurrences of p in s as a subsequence should be exactly n. If there are many possible solutions, output any of them. It is guaranteed that at least one solution exists. Examples Input 2 Output hHheidi Hei Input 4 Output bbbba ba Input 6 Output aaabb ab Note An occurrence of p as a subsequence in s should be thought of as a set of positions in s such that the letters at these positions, in order, form p. The number of occurences is thus the number of such sets. For example, ab appears 6 times as a subsequence in aaabb, for the following sets of positions: {1, 4}, {1, 5}, {2, 4}, {2, 5}, {3, 4}, {3, 5} (that is, we should choose one of the a's and one of the b's).
2
14
#include <bits/stdc++.h> using namespace std; string s1, s2, a = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; int cnt = 0; int main() { int n; scanf("%d", &n); while (--n) { if (n % 2) { s1 += a[cnt++]; } else { s1 += a[cnt]; s1 += a[cnt++]; n /= 2; } } for (int i = 0; i <= cnt; i++) s2 += a[i]; cout << s1 + s2 << " " << s2 << endl; return 0; }
CPP
802_H. Fake News (medium)
Thanks to your help, Heidi is confident that no one can fool her. She has now decided to post some fake news on the HC2 Facebook page. However, she wants to be able to communicate to the HC2 committee that the post is fake, using some secret phrase hidden in the post as a subsequence. To make this method foolproof, she wants the phrase to appear n times in the post. She is asking you to design a post (string) s and a hidden phrase p such that p appears in s as a subsequence exactly n times. Input The first and only line of input contains a single integer n (1 ≤ n ≤ 1 000 000). Output The output should contain two nonempty strings s and p separated by a single space. Each string should be composed of letters (a-z and A-Z: both lowercase and uppercase are allowed) and have length at most 200. The number of occurrences of p in s as a subsequence should be exactly n. If there are many possible solutions, output any of them. It is guaranteed that at least one solution exists. Examples Input 2 Output hHheidi Hei Input 4 Output bbbba ba Input 6 Output aaabb ab Note An occurrence of p as a subsequence in s should be thought of as a set of positions in s such that the letters at these positions, in order, form p. The number of occurences is thus the number of such sets. For example, ab appears 6 times as a subsequence in aaabb, for the following sets of positions: {1, 4}, {1, 5}, {2, 4}, {2, 5}, {3, 4}, {3, 5} (that is, we should choose one of the a's and one of the b's).
2
14
def getstr(n): if n==1: return 'a','',1 elif n==2: return 'ab','b',2 else: if n%2==0: p,u,now=getstr((n-2)//2) c = chr(ord('a')+now) return p+c,c+u+c+c,now+1 else: p,u,now=getstr((n-1)//2) c = chr(ord('a')+now) return p+c,u+c+c,now+1 n = int(input()) ans = getstr(n) print(ans[0]+ans[1],ans[0])
PYTHON3
802_H. Fake News (medium)
Thanks to your help, Heidi is confident that no one can fool her. She has now decided to post some fake news on the HC2 Facebook page. However, she wants to be able to communicate to the HC2 committee that the post is fake, using some secret phrase hidden in the post as a subsequence. To make this method foolproof, she wants the phrase to appear n times in the post. She is asking you to design a post (string) s and a hidden phrase p such that p appears in s as a subsequence exactly n times. Input The first and only line of input contains a single integer n (1 ≤ n ≤ 1 000 000). Output The output should contain two nonempty strings s and p separated by a single space. Each string should be composed of letters (a-z and A-Z: both lowercase and uppercase are allowed) and have length at most 200. The number of occurrences of p in s as a subsequence should be exactly n. If there are many possible solutions, output any of them. It is guaranteed that at least one solution exists. Examples Input 2 Output hHheidi Hei Input 4 Output bbbba ba Input 6 Output aaabb ab Note An occurrence of p as a subsequence in s should be thought of as a set of positions in s such that the letters at these positions, in order, form p. The number of occurences is thus the number of such sets. For example, ab appears 6 times as a subsequence in aaabb, for the following sets of positions: {1, 4}, {1, 5}, {2, 4}, {2, 5}, {3, 4}, {3, 5} (that is, we should choose one of the a's and one of the b's).
2
14
#include <bits/stdc++.h> using namespace std; const int MOD = 1e9 + 7; int fx[] = {-1, +0, +1, +0, +1, +1, -1, -1, +0}; int fy[] = {+0, -1, +0, +1, +1, -1, +1, -1, +0}; int day[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; template <typename T> inline bool isLeap(T y) { return (y % 400 == 0) || (y % 100 ? y % 4 == 0 : false); } template <typename T> inline T GCD(T a, T b) { a = abs(a); b = abs(b); if (a < b) swap(a, b); while (b) { a = a % b; swap(a, b); } return a; } template <typename T> inline T EGCD(T a, T b, T &x, T &y) { if (a == 0) { x = 0; y = 1; return b; } T x1, y1; T d = EGCD(b % a, a, x1, y1); x = y1 - (b / a) * x1; y = x1; return d; } template <typename T> inline T LCM(T x, T y) { T tp = GCD(x, y); if ((x / tp) * 1. * y > 9e18) return 9e18; return (x / tp) * y; } template <typename T> inline T BigMod(T A, T B, T M = MOD) { T ret = 1; while (B) { if (B & 1) ret = (ret * A) % M; A = (A * A) % M; B = B >> 1; } return ret; } template <typename T> inline T InvMod(T A, T M = MOD) { return BigMod(A, M - 2, M); } template <typename T> T scani(T &n) { n = 0; bool negative = false; char c = getchar(); while (c < '0' || c > '9') { if (c == '-') negative = true; c = getchar(); } while (c >= '0' && c <= '9') { n = n * 10 + c - 48; c = getchar(); } if (negative) n = ~(n - 1); return n; } template <typename T> void write(T n, int type = true) { if (n < 0) { putchar('-'); n = -n; } if (!n) { putchar('0'); if (type == 32) putchar(' '); else if (type) putchar('\n'); return; } char buff[22]; int len = 0; while (n) buff[len++] = n % 10 + 48, n /= 10; for (int i = len - 1; i >= 0; i--) putchar(buff[i]); if (type == 32) putchar(' '); else if (type) putchar('\n'); } int scans(char *a) { int i = 0; char c = 0; while (c < 33) c = getchar(); while (c > 33) { a[i++] = c; c = getchar(); } a[i] = 0; return i; } void zAlgo(char *s, int *z) { int L, R, sz; sz = strlen(s); z[0] = L = R = 0; for (int i = (1); i < (sz); ++i) { z[i] = 0; if (i <= R) z[i] = min(z[i - L], R - i + 1); while (i + z[i] < sz && s[i + z[i]] == s[z[i]]) z[i]++; if (i + z[i] - 1 > R) L = i, R = i + z[i] - 1; } } void zAlgo(string &s, int *z) { int L, R, sz; sz = s.size(); z[0] = L = R = 0; for (int i = (1); i < (sz); ++i) { z[i] = 0; if (i <= R) z[i] = min(z[i - L], R - i + 1); while (i + z[i] < sz && s[i + z[i]] == s[z[i]]) z[i]++; if (i + z[i] - 1 > R) L = i, R = i + z[i] - 1; } } void zAlgo(int *s, int *z, int n) { int L, R, sz; sz = n; z[0] = L = R = 0; for (int i = (1); i < (sz); ++i) { z[i] = 0; if (i <= R) z[i] = min(z[i - L], R - i + 1); while (i + z[i] < sz && s[i + z[i]] == s[z[i]]) z[i]++; if (i + z[i] - 1 > R) L = i, R = i + z[i] - 1; } } template <typename T> inline T SqrDis(T x1, T y1, T x2, T y2) { return ((x1 - x2) * (x1 - x2)) + ((y1 - y2) * (y1 - y2)); } template <typename T> inline T Area2(T Ax, T Ay, T Bx, T By, T Cx, T Cy) { T ret = Ax * (By - Cy) + Bx * (Cy - Ay) + Cx * (Ay - By); if (ret < 0) return ret = -ret; return ret; } const int N = 2000006; const int M = 44444; const unsigned long long hs = 3797; char ch[111]; int n, m; int main() { cin >> n; if (n == 1) { cout << "a a\n"; return 0; } for (char i = 'a'; i <= 'z'; i++) ch[++m] = i; for (char i = 'A'; i <= 'Z'; i++) ch[++m] = i; m = 0; string a, b; while (n > 1) { n--; if (n & 1) a += ch[++m]; else { n /= 2; a += ch[++m]; a += ch[m]; } } for (int i = 1; i <= m; i++) b += ch[i]; cout << a << b << ' ' << b << '\n'; return 0; }
CPP
802_H. Fake News (medium)
Thanks to your help, Heidi is confident that no one can fool her. She has now decided to post some fake news on the HC2 Facebook page. However, she wants to be able to communicate to the HC2 committee that the post is fake, using some secret phrase hidden in the post as a subsequence. To make this method foolproof, she wants the phrase to appear n times in the post. She is asking you to design a post (string) s and a hidden phrase p such that p appears in s as a subsequence exactly n times. Input The first and only line of input contains a single integer n (1 ≤ n ≤ 1 000 000). Output The output should contain two nonempty strings s and p separated by a single space. Each string should be composed of letters (a-z and A-Z: both lowercase and uppercase are allowed) and have length at most 200. The number of occurrences of p in s as a subsequence should be exactly n. If there are many possible solutions, output any of them. It is guaranteed that at least one solution exists. Examples Input 2 Output hHheidi Hei Input 4 Output bbbba ba Input 6 Output aaabb ab Note An occurrence of p as a subsequence in s should be thought of as a set of positions in s such that the letters at these positions, in order, form p. The number of occurences is thus the number of such sets. For example, ab appears 6 times as a subsequence in aaabb, for the following sets of positions: {1, 4}, {1, 5}, {2, 4}, {2, 5}, {3, 4}, {3, 5} (that is, we should choose one of the a's and one of the b's).
2
14
#include <bits/stdc++.h> using namespace std; pair<string, string> solve(int n) { if (n <= 4) { return {string(n, 'a'), string("a")}; } if (n % 2) { auto prv = solve(n / 2); string s = prv.first; string p = prv.second; char c = max(*max_element((s).begin(), (s).end()), *max_element((p).begin(), (p).end())) + 1; s.erase(0, p.size()); return {p + c + s + c + c, p + c}; } else { auto prv = solve(n / 2 - 1); string s = prv.first; string p = prv.second; char c = max(*max_element((s).begin(), (s).end()), *max_element((p).begin(), (p).end())) + 1; s.erase(0, p.size()); return {p + c + c + s + c + c, p + c}; } } int main() { int n; cin >> n; auto ans = solve(n); cout << ans.first << ' ' << ans.second << endl; }
CPP
802_H. Fake News (medium)
Thanks to your help, Heidi is confident that no one can fool her. She has now decided to post some fake news on the HC2 Facebook page. However, she wants to be able to communicate to the HC2 committee that the post is fake, using some secret phrase hidden in the post as a subsequence. To make this method foolproof, she wants the phrase to appear n times in the post. She is asking you to design a post (string) s and a hidden phrase p such that p appears in s as a subsequence exactly n times. Input The first and only line of input contains a single integer n (1 ≤ n ≤ 1 000 000). Output The output should contain two nonempty strings s and p separated by a single space. Each string should be composed of letters (a-z and A-Z: both lowercase and uppercase are allowed) and have length at most 200. The number of occurrences of p in s as a subsequence should be exactly n. If there are many possible solutions, output any of them. It is guaranteed that at least one solution exists. Examples Input 2 Output hHheidi Hei Input 4 Output bbbba ba Input 6 Output aaabb ab Note An occurrence of p as a subsequence in s should be thought of as a set of positions in s such that the letters at these positions, in order, form p. The number of occurences is thus the number of such sets. For example, ab appears 6 times as a subsequence in aaabb, for the following sets of positions: {1, 4}, {1, 5}, {2, 4}, {2, 5}, {3, 4}, {3, 5} (that is, we should choose one of the a's and one of the b's).
2
14
#include <bits/stdc++.h> using namespace std; long long n; char aa; string a, q; inline long long read() { long long x = 0; bool f = 0; char ch = getchar(); for (; !isdigit(ch); ch = getchar()) f ^= (ch == '-'); for (; isdigit(ch); ch = getchar()) x = (x << 3) + (x << 1) + (ch ^ 48); return f ? -x : x; } inline void solve(int len) { if (len == 1) { a = ""; q = "a"; aa = 'a'; return; } if (len == 2) { a = "b"; q = "ab"; aa = 'b'; return; } if (len & 1) { solve(len / 2); aa++; a = a + aa + aa; q = q + aa; return; } else { solve(len / 2 - 1); aa++; a = aa + a + aa + aa; q = q + aa; return; } } int main() { n = read(); solve(n); cout << q << a << " " << q << endl; return 0; }
CPP
802_H. Fake News (medium)
Thanks to your help, Heidi is confident that no one can fool her. She has now decided to post some fake news on the HC2 Facebook page. However, she wants to be able to communicate to the HC2 committee that the post is fake, using some secret phrase hidden in the post as a subsequence. To make this method foolproof, she wants the phrase to appear n times in the post. She is asking you to design a post (string) s and a hidden phrase p such that p appears in s as a subsequence exactly n times. Input The first and only line of input contains a single integer n (1 ≤ n ≤ 1 000 000). Output The output should contain two nonempty strings s and p separated by a single space. Each string should be composed of letters (a-z and A-Z: both lowercase and uppercase are allowed) and have length at most 200. The number of occurrences of p in s as a subsequence should be exactly n. If there are many possible solutions, output any of them. It is guaranteed that at least one solution exists. Examples Input 2 Output hHheidi Hei Input 4 Output bbbba ba Input 6 Output aaabb ab Note An occurrence of p as a subsequence in s should be thought of as a set of positions in s such that the letters at these positions, in order, form p. The number of occurences is thus the number of such sets. For example, ab appears 6 times as a subsequence in aaabb, for the following sets of positions: {1, 4}, {1, 5}, {2, 4}, {2, 5}, {3, 4}, {3, 5} (that is, we should choose one of the a's and one of the b's).
2
14
#include <bits/stdc++.h> using namespace std; const int N = 35; int c[N][N]; int cnt[N]; int main() { for (int i = 0; i < N; i++) { c[i][0] = 1; for (int j = 1; j <= i; j++) c[i][j] = c[i - 1][j] + c[i - 1][j - 1]; } int n; cin >> n; for (int i = N - 1; i >= 6; i--) while (n >= c[i][6]) { n -= c[i][6]; cnt[i]++; } for (int i = 1; i < N; i++) { cout << 'a'; while (cnt[i]) { cout << 'b'; cnt[i]--; } } cout << "\naaaaaab\n"; return 0; }
CPP
802_H. Fake News (medium)
Thanks to your help, Heidi is confident that no one can fool her. She has now decided to post some fake news on the HC2 Facebook page. However, she wants to be able to communicate to the HC2 committee that the post is fake, using some secret phrase hidden in the post as a subsequence. To make this method foolproof, she wants the phrase to appear n times in the post. She is asking you to design a post (string) s and a hidden phrase p such that p appears in s as a subsequence exactly n times. Input The first and only line of input contains a single integer n (1 ≤ n ≤ 1 000 000). Output The output should contain two nonempty strings s and p separated by a single space. Each string should be composed of letters (a-z and A-Z: both lowercase and uppercase are allowed) and have length at most 200. The number of occurrences of p in s as a subsequence should be exactly n. If there are many possible solutions, output any of them. It is guaranteed that at least one solution exists. Examples Input 2 Output hHheidi Hei Input 4 Output bbbba ba Input 6 Output aaabb ab Note An occurrence of p as a subsequence in s should be thought of as a set of positions in s such that the letters at these positions, in order, form p. The number of occurences is thus the number of such sets. For example, ab appears 6 times as a subsequence in aaabb, for the following sets of positions: {1, 4}, {1, 5}, {2, 4}, {2, 5}, {3, 4}, {3, 5} (that is, we should choose one of the a's and one of the b's).
2
14
#include <bits/stdc++.h> using namespace std; string arr[52]; void solve() { int n; cin >> n; vector<int> path; int m = n; path.push_back(m); while (m > 2) { if (m % 2) { path.push_back((m - 1) / 2); m = (m - 1) / 2; } else { path.push_back((m - 2) / 2); m = (m - 2) / 2; } } path.pop_back(); reverse(path.begin(), path.end()); string u; string p; int curr = 1; if (m == 1) { u = ""; p = "a"; } else { u = "a"; p = "a"; } for (auto num : path) { if (num == 2 * m + 1) { u = u + arr[curr] + arr[curr]; p = p + arr[curr]; curr++; } else if (num == 2 * m + 2) { u = arr[curr] + u + arr[curr] + arr[curr]; p = p + arr[curr]; curr++; } m = num; } string s = p + u; cout << s << " " << p << "\n"; return; } signed main() { ios::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL); int t; t = 1; for (int j = 0; j < 26; j++) { arr[j].resize(1, 'a' + j); } for (int j = 0; j < 26; j++) { arr[26 + j].resize(1, 'A' + j); } while (t--) { solve(); } return 0; }
CPP
802_H. Fake News (medium)
Thanks to your help, Heidi is confident that no one can fool her. She has now decided to post some fake news on the HC2 Facebook page. However, she wants to be able to communicate to the HC2 committee that the post is fake, using some secret phrase hidden in the post as a subsequence. To make this method foolproof, she wants the phrase to appear n times in the post. She is asking you to design a post (string) s and a hidden phrase p such that p appears in s as a subsequence exactly n times. Input The first and only line of input contains a single integer n (1 ≤ n ≤ 1 000 000). Output The output should contain two nonempty strings s and p separated by a single space. Each string should be composed of letters (a-z and A-Z: both lowercase and uppercase are allowed) and have length at most 200. The number of occurrences of p in s as a subsequence should be exactly n. If there are many possible solutions, output any of them. It is guaranteed that at least one solution exists. Examples Input 2 Output hHheidi Hei Input 4 Output bbbba ba Input 6 Output aaabb ab Note An occurrence of p as a subsequence in s should be thought of as a set of positions in s such that the letters at these positions, in order, form p. The number of occurences is thus the number of such sets. For example, ab appears 6 times as a subsequence in aaabb, for the following sets of positions: {1, 4}, {1, 5}, {2, 4}, {2, 5}, {3, 4}, {3, 5} (that is, we should choose one of the a's and one of the b's).
2
14
#include <bits/stdc++.h> using namespace std; string p, s; int n; void dfs(int n, char c) { if (n == 1) { s += c, p += c; return; } else if (n == 2) { s += c, s += c, p += c; return; } if (n & 1) { dfs(n / 2, c + 1); s = p + c + s.substr(p.size(), s.size() - p.size() + 1) + c + c, p += c; } else { dfs(n / 2 - 1, c + 1); s = p + c + c + s.substr(p.size(), s.size() - p.size() + 1) + c + c, p += c; } } int main() { scanf("%d", &n); dfs(n, 'a'); cout << s << ' ' << p; }
CPP
802_H. Fake News (medium)
Thanks to your help, Heidi is confident that no one can fool her. She has now decided to post some fake news on the HC2 Facebook page. However, she wants to be able to communicate to the HC2 committee that the post is fake, using some secret phrase hidden in the post as a subsequence. To make this method foolproof, she wants the phrase to appear n times in the post. She is asking you to design a post (string) s and a hidden phrase p such that p appears in s as a subsequence exactly n times. Input The first and only line of input contains a single integer n (1 ≤ n ≤ 1 000 000). Output The output should contain two nonempty strings s and p separated by a single space. Each string should be composed of letters (a-z and A-Z: both lowercase and uppercase are allowed) and have length at most 200. The number of occurrences of p in s as a subsequence should be exactly n. If there are many possible solutions, output any of them. It is guaranteed that at least one solution exists. Examples Input 2 Output hHheidi Hei Input 4 Output bbbba ba Input 6 Output aaabb ab Note An occurrence of p as a subsequence in s should be thought of as a set of positions in s such that the letters at these positions, in order, form p. The number of occurences is thus the number of such sets. For example, ab appears 6 times as a subsequence in aaabb, for the following sets of positions: {1, 4}, {1, 5}, {2, 4}, {2, 5}, {3, 4}, {3, 5} (that is, we should choose one of the a's and one of the b's).
2
14
#include <bits/stdc++.h> using namespace std; pair<pair<string, string>, string> solve(int n) { if (n == 1) { return {{"a", ""}, "a"}; } if (n == 2) { return {{"a", "a"}, "a"}; } int k = n - 1 >> 1; auto res = solve(k); string c = ""; c += res.second[res.second.size() - 1] + 1; if (k * 2 + 1 == n) { return {{res.first.first + c, res.first.second + c + c}, res.second + c}; } else { return {{res.first.first + c, c + res.first.second + c + c}, res.second + c}; } } int main() { int n; cin >> n; auto it = solve(n); cout << it.first.first + it.first.second << " " << it.second << endl; }
CPP
802_H. Fake News (medium)
Thanks to your help, Heidi is confident that no one can fool her. She has now decided to post some fake news on the HC2 Facebook page. However, she wants to be able to communicate to the HC2 committee that the post is fake, using some secret phrase hidden in the post as a subsequence. To make this method foolproof, she wants the phrase to appear n times in the post. She is asking you to design a post (string) s and a hidden phrase p such that p appears in s as a subsequence exactly n times. Input The first and only line of input contains a single integer n (1 ≤ n ≤ 1 000 000). Output The output should contain two nonempty strings s and p separated by a single space. Each string should be composed of letters (a-z and A-Z: both lowercase and uppercase are allowed) and have length at most 200. The number of occurrences of p in s as a subsequence should be exactly n. If there are many possible solutions, output any of them. It is guaranteed that at least one solution exists. Examples Input 2 Output hHheidi Hei Input 4 Output bbbba ba Input 6 Output aaabb ab Note An occurrence of p as a subsequence in s should be thought of as a set of positions in s such that the letters at these positions, in order, form p. The number of occurences is thus the number of such sets. For example, ab appears 6 times as a subsequence in aaabb, for the following sets of positions: {1, 4}, {1, 5}, {2, 4}, {2, 5}, {3, 4}, {3, 5} (that is, we should choose one of the a's and one of the b's).
2
14
#include <bits/stdc++.h> using namespace std; const int maxn = 1e6 + 10; long long f[maxn]; long long C(int n, int m) { return f[n] / f[m] / f[n - m]; } int main() { int n; scanf("%d", &n); f[0] = 1; for (int i = 1; i <= 20; i++) f[i] = f[i - 1] * i; string s, p = "abbbbbbbb"; int lenp = 8; for (int i = 20; i >= lenp; i--) { long long tmp = C(i, lenp); while (n >= tmp) { s += 'a'; n -= tmp; } s += 'b'; } s += "bbbbbbb"; printf("%s %s\n", s.c_str(), p.c_str()); }
CPP
802_H. Fake News (medium)
Thanks to your help, Heidi is confident that no one can fool her. She has now decided to post some fake news on the HC2 Facebook page. However, she wants to be able to communicate to the HC2 committee that the post is fake, using some secret phrase hidden in the post as a subsequence. To make this method foolproof, she wants the phrase to appear n times in the post. She is asking you to design a post (string) s and a hidden phrase p such that p appears in s as a subsequence exactly n times. Input The first and only line of input contains a single integer n (1 ≤ n ≤ 1 000 000). Output The output should contain two nonempty strings s and p separated by a single space. Each string should be composed of letters (a-z and A-Z: both lowercase and uppercase are allowed) and have length at most 200. The number of occurrences of p in s as a subsequence should be exactly n. If there are many possible solutions, output any of them. It is guaranteed that at least one solution exists. Examples Input 2 Output hHheidi Hei Input 4 Output bbbba ba Input 6 Output aaabb ab Note An occurrence of p as a subsequence in s should be thought of as a set of positions in s such that the letters at these positions, in order, form p. The number of occurences is thus the number of such sets. For example, ab appears 6 times as a subsequence in aaabb, for the following sets of positions: {1, 4}, {1, 5}, {2, 4}, {2, 5}, {3, 4}, {3, 5} (that is, we should choose one of the a's and one of the b's).
2
14
#include <bits/stdc++.h> using namespace std; char c = 'a'; pair<string, string> gen(int n) { ; if (n == 1) return {"a", ""}; else if (n == 2) return {"a", "a"}; else if (n & 1) { pair<string, string> res = gen((n - 1) / 2); c++; return {res.first + string(1, c), res.second + string(2, c)}; } else { pair<string, string> res = gen((n - 1) / 2); c++; return {res.first + string(1, c), string(1, c) + res.second + string(2, c)}; } } void solve() { int n; cin >> n; pair<string, string> res = gen(n); cout << res.first + res.second << ' ' << res.first; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int t = 1; while (t--) { solve(); } }
CPP
802_H. Fake News (medium)
Thanks to your help, Heidi is confident that no one can fool her. She has now decided to post some fake news on the HC2 Facebook page. However, she wants to be able to communicate to the HC2 committee that the post is fake, using some secret phrase hidden in the post as a subsequence. To make this method foolproof, she wants the phrase to appear n times in the post. She is asking you to design a post (string) s and a hidden phrase p such that p appears in s as a subsequence exactly n times. Input The first and only line of input contains a single integer n (1 ≤ n ≤ 1 000 000). Output The output should contain two nonempty strings s and p separated by a single space. Each string should be composed of letters (a-z and A-Z: both lowercase and uppercase are allowed) and have length at most 200. The number of occurrences of p in s as a subsequence should be exactly n. If there are many possible solutions, output any of them. It is guaranteed that at least one solution exists. Examples Input 2 Output hHheidi Hei Input 4 Output bbbba ba Input 6 Output aaabb ab Note An occurrence of p as a subsequence in s should be thought of as a set of positions in s such that the letters at these positions, in order, form p. The number of occurences is thus the number of such sets. For example, ab appears 6 times as a subsequence in aaabb, for the following sets of positions: {1, 4}, {1, 5}, {2, 4}, {2, 5}, {3, 4}, {3, 5} (that is, we should choose one of the a's and one of the b's).
2
14
#include <bits/stdc++.h> using namespace std; long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); } int n; char a[100]; int na; char b[100]; int nb; char get(int x) { if (x < 26) return 'a' + x; if (x < 52) return 'A' + (x - 26); assert(false); return '?'; } void run() { scanf("%d", &n); int p = 0; while ((2 << p) - 1 <= n) ++p; n -= (1 << p) - 1; na = 0, nb = 0; int nc = 0; a[na++] = get(nc++); for (int i = (0); i < (p); ++i) { if (n & (1 << i)) a[na++] = get(nc), b[nb++] = get(nc), ++nc; if (i != p - 1) { a[na++] = get(nc), a[na++] = get(nc), b[nb++] = get(nc); ++nc; } } for (int i = (0); i < (na); ++i) printf("%c", a[i]); for (int i = (0); i < (nb); ++i) printf("%c", b[i]); printf(" "); for (int i = (0); i < (nc); ++i) printf("%c", get(i)); puts(""); } int main() { run(); return 0; }
CPP