text
stringlengths
49
983k
#include <bits/stdc++.h> int main() { int n, i, r, j, d, k, x = 0; scanf("%d", &n); r = n / 4; char str[n]; scanf("%s", str); for (i = 0; str[i]; i++) { if (str[i] == '*') { for (j = i + 1; j <= i + r + 1; j++) { if (str[j] == '*') { d = j - i; for (k = i + d; str[k]; k = k + d) { if (str[k] == '*') x++; else break; } if (x >= 4) { printf("yes"); return 0; } else x = 0; } } } } printf("no"); }
#include <bits/stdc++.h> using namespace std; const int inf = (1 << 30) - 1; const int mod = 1000000007; int n; char s[105]; int main() { scanf("%d\n", &n); scanf("%s", s); for (int i = 0; i < n; i++) { for (int j = i + 1; j < n; j++) { int d = j - i; if (j + d + d + d < n && s[i] == '*' && s[j] == '*' && s[j + d] == '*' && s[j + d + d] == '*' && s[j + d + d + d] == '*') { puts("yes"); return 0; } } } puts("no"); return 0; }
#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_popcounll(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; } int n; string s; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> n >> s; for (int i = 0; i < (n); ++i) if (s[i] == '*') { for (int add = 1; add < 100; add++) { bool ok = true; for (int j = 1; j <= 4; j++) { int vt = i + add * j; if (vt >= n || s[vt] != '*') { ok = false; break; } } if (ok) { cout << "yes" << endl; return 0; } } } cout << "no" << endl; return 0; }
#include <bits/stdc++.h> using namespace std; const int N = 1010; char s[N]; int n; int main() { scanf("%d%s", &n, s + 1); for (int j = (int)1; j <= (int)n; ++j) for (int i = (int)1; i <= (int)n; ++i) if (s[i] == '*' && s[i + j] == '*' && s[i + 2 * j] == '*' && s[i + 3 * j] == '*' && s[i + 4 * j] == '*') { printf("yes"); return 0; } printf("no"); return 0; }
#include <bits/stdc++.h> using namespace std; int i, j, k, n, m; char p[110]; inline void print(int x) { printf("%s\n", x ? "yes" : "no"); exit(0); } int main() { scanf("%d%s", &n, p + 1); for (i = 1; i <= n; i++) for (j = 1; j <= n; j++) if (j + i * 4 <= n) { if (p[j] == '*' && p[j + i] == '*' && p[j + i * 2] == '*' && p[j + i * 3] == '*' && p[j + i * 4] == '*') print(1); } print(0); return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; string in; cin >> in; int aux; int jump, k = 0; for (int i = 0; i < n; i++) { for (jump = 1; jump < n / 2 + 5; jump++) { k = 0; for (int j = i; j < n && k <= 4 && in[j] == '*'; j += jump, k++) ; if (k >= 5) { cout << "yes" << endl; return 0; } } } cout << "no" << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n, l, i, j; cin >> n; string s; cin >> s; l = s.size(); for (i = 0; i < l - 4; i++) { if (s[i] == '*') { for (j = 1; i + 4 * j < l; j++) { if (s[i + j] == '*' && s[i + 2 * j] == '*' && s[i + 3 * j] == '*' && s[i + 4 * j] == '*') { cout << "yes" << endl; return 0; } } } } cout << "no" << endl; return 0; }
#include <bits/stdc++.h> using namespace std; const int MAXN = 105; int n; string s; bool ans = false; int main() { scanf("%d\n", &n); getline(cin, s); for (int i = 1; i <= 2 * n; i++) { for (int j = 0; j < n; j++) { bool ok = true; for (int k = 0; k < 5; k++) { if (j + k * i >= n || s[j + k * i] == '.') ok = false; } if (ok) ans = true; } } if (ans) puts("yes"); else puts("no"); return 0; }
#include <bits/stdc++.h> using namespace std; int main() { string a; int n, f = 0; cin >> n; cin >> a; for (int i = 0; i < n && (!f); i++) { for (int j = 1; i + j + j + j + j < n; j++) { if (a[i] == '*' && a[i + j] == '*' && a[i + 2 * j] == '*' && a[i + 3 * j] == '*' && a[i + 4 * j] == '*') { cout << "yes" << endl; f = 1; break; } } } if (!f) cout << "no" << endl; return 0; }
#include <bits/stdc++.h> const int inf = (1ll << 31) - 1; const int maxn = (int)1e5 + 10; using namespace std; int n; string second; bool check(int x) { for (int i = 0; i < n; i++) { int cur = 5; int y = i; while (cur > 0) { if (y >= n || second[y] == '.') break; y += x; cur--; } if (cur == 0) return 1; } return 0; } int main() { cin >> n >> second; for (int i = 1; i <= n; i++) { if (check(i)) { cout << "yes\n"; return 0; } } cout << "no\n"; return 0; }
#include <bits/stdc++.h> using namespace std; const int N = 13; const double eps = 1e-8; const int maxn = 1102; const int INF = 0x7f7f7f7f; char s[maxn]; bool check(int begin, int d, int n) { int step = 0; for (int i = begin; i < n; i += d) { if (s[i] == '.') { return false; } else { step++; if (step == 5) { return true; } } } return false; } int main() { int n; scanf("%d%s", &n, s); for (int i = 0; i < n; ++i) { for (int j = 1; i + j < n; ++j) { if (check(i, j, n)) { puts("yes"); return 0; } } } puts("no"); return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n; while (cin >> n) { char str[110]; cin >> str; for (int beg = 0; beg < n; beg++) { for (int d = 1; d < n; d++) { int c = 0; int pos = beg; while (pos < n && str[pos] == '*') { c++; pos += d; } if (c >= 5) { cout << "yes" << endl; return 0; } } } cout << "no" << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; void solve() { int N; char in[120]; scanf("%d%s", &N, in); int len = strlen(in); int flag = 0; for (int i = 0; i < len; i++) { for (int d = 1; d < len; d++) { if (i + 4 * d >= len) break; if (in[i] == '*' && in[i + d] == '*' && in[i + 2 * d] == '*' && in[i + 3 * d] == '*' && in[i + 4 * d] == '*') flag = 1; } } if (flag) printf("yes\n"); else printf("no\n"); } int main() { solve(); return 0; }
#include <bits/stdc++.h> using namespace std; template <class T> string toStr(const T &x) { stringstream s; s << x; return s.str(); } template <class T> int toInt(const T &x) { stringstream s; s << x; int r; s >> r; return r; } int dx[8] = {-1, -1, -1, 0, 1, 1, 1, 0}; int dy[8] = {-1, 0, 1, 1, 1, 0, -1, -1}; int main() { int n; cin >> n; string s; cin >> s; for (int i = 0; i < n; ++i) { for (int j = 1; j <= n; ++j) { if (s[i] != '*' || i + j * 4 >= n) continue; if (s[i + j] == '*' && s[i + j * 2] == '*' && s[i + j * 3] == '*' && s[i + j * 4] == '*') { cout << "yes"; return 0; } } } cout << "no"; return 0; }
#include <bits/stdc++.h> using namespace std; constexpr long long MAXN = 128; char a[MAXN]; int n; int main() { cin >> n; for (int i = 1; i <= n; i++) cin >> a[i]; for (int st = 1; st <= n; st++) { for (int jump = 1; jump <= n; jump++) { int cnt = 0; for (int i = st; i <= n; i += jump) { if (a[i] == '.') break; cnt++; if (cnt == 5) return cout << "YES\n", false; } } } return cout << "NO\n", false; }
#include <bits/stdc++.h> using namespace std; int n; string s; int main() { cin >> n >> s; for (int i = 1; i < n; i++) for (int j = 0; j < n - 4 * i; j++) if (s[j] == '*' && s[j + i] == '*' && s[j + 2 * i] == '*' && s[j + 3 * i] == '*' && s[j + 4 * i] == '*') { cout << "yes"; return 0; } cout << "no"; }
#include <bits/stdc++.h> using namespace std; int n, a[110], dem; char s[110]; bool flag; int main() { scanf("%d\n", &n); for (int i = 1; i <= n; i++) scanf("%s\n", s + 1); for (int i = 1; i <= n; i++) if (s[i] == '*') { if (s[i] != s[i - 1]) a[i] = ++dem; else a[i] = dem; } for (int len = 1; len <= n; len++) for (int i1 = 1; i1 <= n; i1++) { int i2 = i1 + len, i3 = i2 + len, i4 = i3 + len, i5 = i4 + len; if (i5 <= n && a[i1] && a[i2] && a[i3] && a[i4] && a[i5]) flag = true; } if (flag) cout << "yes"; else cout << "no"; }
#include <bits/stdc++.h> using namespace std; int n; char str[200]; int main() { scanf("%d%s", &n, str); int an = 0; for (int i = 1; i < n; i++) { for (int j = 0; j < n; j++) if (j + i * 4 < n) { bool bo = 1; for (int k = 0; k < 5; k++) if (str[j + k * i] == '.' || j + k * i >= n) { bo = 0; break; } if (bo) { an = 1; break; } } else break; if (an) break; } if (an) printf("yes"); else printf("no"); return 0; }
#include <bits/stdc++.h> const int mod = 1000000007; using namespace std; int main() { int n; cin >> n; string s; cin >> s; for (int i = 0; i < n; ++i) { if (s[i] == '*') { for (int j = 1; j < n; ++j) { int cnt = 0; for (int k = 0; k <= 4; ++k) { if (i + k * j >= n) break; if (s[i + k * j] == '*') cnt++; } if (cnt == 5) { puts("yes"); return 0; } } } } puts("no"); return 0; }
#include <bits/stdc++.h> using namespace std; int main() { long i, j, step, cnt, n; char s[200]; scanf("%d", &n); cin >> s; bool check = false; for (i = 0; i < strlen(s); i++) if (s[i] == '*') { for (step = 1; i + step <= n; step++) { j = i; cnt = 1; while (j + step < n) { j += step; if (s[j] != '*') break; cnt++; if (cnt == 5) { check = true; break; } } if (check) break; } } if (check) printf("yes"); else printf("no"); return 0; }
#include <bits/stdc++.h> using namespace std; long long n, m, i, j, k, t, ans; string s; bool cond[101]; int main() { ios_base::sync_with_stdio(0); static const size_t npos = -1; cin >> n; cin >> s; if (n <= 4) { cout << "no" << endl; return 0; } for (i = 0; i < s.size(); i++) if (s[i] == '*') cond[i] = true; for (i = 0; i < n - 4; i++) { if (s[i] == '*') { ans = 0; for (j = 1; j < n; j++) { if (4 * j < s.size() && s[i] == s[i + j] && s[i] == s[i + 2 * j] && s[i] == s[i + 3 * j] && s[i] == s[i + 4 * j]) { cout << "yes" << endl; return 0; } } } } cout << "no" << endl; return 0; }
#include <bits/stdc++.h> using namespace std; string str; int n, i, x, k, t, j; int main() { cin >> n; cin >> str; for (k = 1; k <= n; k++) { for (i = 0; i < n; i++) { t = 0; for (j = i; j < n; j += k) { if (str[j] == '.') break; t++; } if (t >= 5) return cout << "yes" << '\n', 0; } } cout << "no" << '\n'; }
#include <bits/stdc++.h> unsigned char get_num(void) { char tmp[8]; fgets(tmp, 8, stdin); return atoi(tmp); } int main(void) { unsigned char n; n = get_num(); char str[n]; unsigned char jmp_lim = n - 4; unsigned char jump_size; scanf("%s", str); for (jump_size = 1; jump_size <= jmp_lim; jump_size++) { unsigned char start_lim = n - jump_size; unsigned char start_dot; for (start_dot = 0; start_dot < start_lim; start_dot++) { if (str[start_dot] == 42) { unsigned char dot = start_dot; unsigned char yes = 0; while (dot + jump_size <= n) { dot = dot + jump_size; if (str[dot] == 42) { yes++; } else { break; } } if (yes == 4) { printf("yes"); return 0; } } } } printf("no"); return 0; }
#include <bits/stdc++.h> using namespace std; template <class T> string to_s(const T& a) { ostringstream os; os << a; return os.str(); } template <class T> T to_T(const string& s) { istringstream is(s); T r; is >> r; return r; } int main() { int n; string s; cin >> n >> s; for (int i = (0); i < (long long)(n); i++) { if (s[i] == '.') continue; for (int j = (1); j < (long long)(26); j++) { bool good = true; for (int d = (1); d < (long long)(5); d++) { int x = i + d * j; if (x >= n || s[x] != '*') { good = false; break; } } if (good) { cout << "yes"; return 0; } } } cout << "no"; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; char c[100] = ""; cin >> c; bool f = false; for (int k = 1; k < 26; k++) for (int j = 0; j < n; j++) if (j + 4 * k < n) if ((c[j] == c[j + k]) && (c[j + k] == c[j + 2 * k]) && (c[j + 2 * k] == c[j + 3 * k]) && (c[j + 3 * k] == c[j + 4 * k]) && (c[j] == '*')) f = true; if (f == true) cout << "yes"; else cout << "no"; return 0; }
#include <bits/stdc++.h> using namespace std; bool encuentra(int A[], int buscado, int actual, int n) { for (int i = actual; i < n; i++) { if (A[i] > buscado) return false; if (A[i] == buscado) return true; } return false; } int main() { int n; cin >> n; int A[n]; int cont = 0; for (int i = 0; i < n; i++) { char c; cin >> c; if (c == '*') { A[cont] = i; cont++; } } if (cont < 5) { cout << "no"; return 0; } for (int i = 0; i < cont - 4; i++) { for (int j = i + 1; j < cont; j++) { int dif = A[j] - A[i]; if (encuentra(A, A[i] + 2 * dif, j + 1, cont) && encuentra(A, A[i] + 3 * dif, j + 1, cont) && encuentra(A, A[i] + 4 * dif, j + 1, cont)) { cout << "yes"; return 0; } } } cout << "no"; return 0; }
#include <bits/stdc++.h> using namespace std; bool fill(char x[], int i, int j) { if (x[i] == x[i + j] && x[i] == x[i + 2 * j] && x[i] == x[i + 3 * j] && x[i] == x[i + 4 * j]) return true; return false; } int main() { int n, m = 0; ; cin >> n; char x[105]; for (int i = 0; i < n; i++) x[i] = '.'; for (int i = 0; i < n; i++) cin >> x[i]; for (int i = 0; i < n; i++) { if (x[i] == '*') { for (int j = 1; j <= n / 4; j++) if (fill(x, i, j)) { cout << "yes"; m = 1; break; } if (m == 1) break; } } if (m == 0) cout << "no"; return 0; }
#include <bits/stdc++.h> char s[107]; int n, a[107]; inline bool check(int i, int j) { return (i + 4 * j) < n && s[i] == '*' && s[i + j] == '*' && s[i + 2 * j] == '*' && s[i + 3 * j] == '*' && s[i + 4 * j] == '*' && a[i] <= a[i + j] && a[i + j] <= a[i + 2 * j] && a[i + 2 * j] <= a[i + 3 * j] && a[i + 3 * j] <= a[i + 4 * j]; } int main() { scanf("%d", &n); scanf("%s", s); for (int i = 0, j = 0; i < n;) { if (s[i] == '*') { j++; while (i < n && s[i] == '*') { a[i] = j; i++; } } else { i++; a[i] = -1; } } for (int i = 0; i < n; ++i) { for (int j = 1; j < n; ++j) { if (check(i, j)) { printf("YES"); return 0; } } } printf("NO"); return 0; }
#include <bits/stdc++.h> int main() { int n, i, j, k, a; char ch[100]; scanf("%d ", &n); gets(ch); a = 0; for (i = 0; i < n; i++) { if (ch[i] == '*') { for (k = 1; (i + k) < n; k++) { if (ch[i + k] == '*' && (i + k) < n) { for (j = i + k; j < n; j += k) { if (ch[j] == '*') a++; else { if (a >= 4) { printf("yes"); return 0; } else { a = 0; break; } } } } if (a >= 4) { printf("yes"); return 0; } else a = 0; } } } printf("no"); return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int N; cin >> N; char *str = new char[N]; cin >> str; if (N < 5) { cout << "no" << endl; return 0; } for (int i = 0; i <= N - 5; i++) { if (str[i] == '.') continue; bool find = false; int sj = i + 1; while (sj <= N - 4) { int j = sj; for (; j < N; j++) { if (str[j] == '*') { find = true; break; } } if (!find) { cout << "no" << endl; return 0; } int count = 1; int k = j; while (str[k] == '*') { count++; k += j - i; if (k >= N || count == 5) break; } if (count == 5) { cout << "yes" << endl; return 0; } else { sj++; } } } cout << "no" << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long int n; cin >> n; string s; cin >> s; for (long long int gap = 1; gap < n; gap += 1) { for (long long int i = 0; i < n; i += 1) { long long int count = 0; for (long long int j = i; j < n; j += gap) { if (s[j] != '*') { break; } count++; } if (count == 5) { cout << "yes"; return 0; } } } cout << "no"; return 0; }
#include <bits/stdc++.h> using namespace std; int n, cnt; bool flag; char vis[105]; int num[105]; int main() { while (~scanf("%d", &n)) { flag = false; scanf("%s", vis); memset(num, 0, sizeof(num)); for (int i = 0; i < n; i++) { if (vis[i] == '*') num[i] = 1; } cnt = (n + 1) / 4; for (int i = 0; i < n; i++) { for (int j = 1; j <= cnt; j++) { if (num[i] && num[i + j] && num[i + 2 * j] && num[i + 3 * j] && num[i + 4 * j]) { flag = true; break; } } } if (flag) puts("yes"); else puts("no"); } return 0; }
#include <bits/stdc++.h> using namespace std; const long long OO = 1e9 + 7; int main() { int n, m; while (cin >> n) { string s; cin >> s; for (int k = 1; k < n; k++) { for (int j = 0; j < n; j++) { int cnt = 0; for (int i = j; i < n; i += k) { if (s[i] == '*') cnt++; else break; } if (cnt >= 5) { cout << "yes"; return 0; } } } cout << "no"; } return 0; }
#include <bits/stdc++.h> using namespace std; int xx[] = {1, 1, 1, 0, -1, -1, -1, 0}; int yy[] = {-1, 0, 1, 1, 1, 0, -1, -1}; int rx[] = {1, -1, 0, 0}; int ry[] = {0, 0, 1, -1}; long long int gcd(long long int a, long long int b) { return ((a % b == 0) ? b : gcd(b, a % b)); } bool comp(pair<long long int, long long int> a, pair<long long int, long long int> b) { if (a.first == b.first) { return a.second > b.second; } return a.first < b.first; } int main() { int n, len, i, pos, j, k; string str; cin >> n; cin >> str; pos = n + 10; for (i = 0; i < n; i++) { if (str[i] == '*') { pos = i; break; } } bool f = false, ff = false; int count = 0; for (k = 0; k < n; k++) { if (str[k] == '*') { pos = k; for (i = 1; i <= n; i++) { f = true; ff = false; count = 0; for (j = pos; j < n; j = j + i) { ff = true; if (str[j] != '*') { f = false; } count++; if (f && ff && count >= 5) { cout << "yes" << endl; return 0; } } } } } cout << "no" << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n, t; bool ans = true; string s; cin >> n >> s; int l = n; int l4 = l / 4, l3 = l - 3; for (int k = 0; k < l - 3; k++) { for (int i = 1; i <= l4; i++) { ans = true; t = 0; for (int j = k; t < 5 && j < l; j += i, t++) { if (s[j] == '.') { ans = false; break; } } if (ans && t == 5) { cout << "yes\n"; return 0; } } } cout << "no"; return 0; }
#include <bits/stdc++.h> int main() { char s[101]; int n, i, j, k, l = 0; scanf("%d", &n); scanf("%s", &s); for (i = 1; i < n / 4 + 1; i++) { for (j = 0; j < n; j++) { l = 0; if (s[j] == '*') { for (k = j; k < n; k += i) { if (s[k] == '*') { l++; if (l == 5) { printf("YES"); return 0; } } else { break; } } } } } printf("NO"); return 0; }
#include <bits/stdc++.h> char inp[110]; int main() { int n; scanf("%d%s", &n, inp); int a = 0; for (int i = 0; i < n; i++) { for (int j = 1; i + 4 * j < n; j++) { for (int k = 0; k < 5; k++) { if (inp[i + j * k] != '*') break; if (k == 4) a = 1; } } } puts(a ? "yes" : "no"); return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; string a; cin >> a; for (int i = 0; i < n; i++) { if (a[i] == '*') { int step = 1; while (step + i < n) { int length = 1; int cur = i + step; while (cur < n) { if (a[cur] != '*') break; if (length == 4) { cout << "yes" << endl; return 0; } length++; cur += step; } step++; } } } cout << "no" << endl; return 0; }
#include <bits/stdc++.h> using namespace std; map<char, long long> tpt; set<long long> st; long long x3, x4, x5, m, x1, x2, d, p, j, k, x, y, n, i, b[100007]; string s, s1, s2, s3; char a[10007]; int main() { cin >> n; for (i = 1; i <= n; i++) { cin >> a[i]; } for (x1 = 1; x1 < n; x1++) { for (x2 = x1 + 1; x2 <= n; x2++) { d = x2 - x1; x3 = x2 + d; x4 = x2 + d * 2; x5 = x2 + d * 3; if (x5 <= n && a[x1] == '*' && a[x2] == '*' && a[x3] == '*' && a[x4] == '*' && a[x5] == '*') k = 1; } } if (k == 1) cout << "yes" << endl; else cout << "no" << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int n, sum; char a[110]; int main() { cin >> n; for (int i = 1; i <= n; ++i) { cin >> a[i]; if (a[i] == '*') sum++; } if (sum < 5) { cout << "no"; return 0; } for (int ln = 1; ln <= n; ++ln) { for (int i = 1; i <= n; ++i) { if (a[i] == '*') { int c = 0; for (int j = i; j <= n; j += ln) { if (a[j] == '*') ++c; else break; if (c >= 5) { cout << "yes"; return 0; } } } } } cout << "no"; return 0; }
#include <bits/stdc++.h> int map[101]; int main() { int n; scanf("%d\n", &n); int i; for (i = 0; i < n; i++) { char tmp; scanf("%c", &tmp); map[i] = (tmp == '*'); } int j; for (i = 1; i <= 25; i++) { for (j = 0; j < 100; j++) { int k; for (k = 0; k < 5; k++) { if (j + k * i >= n) break; if (!map[j + k * i]) break; } if (k >= 5) break; } if (j < 100) break; } if (i <= 25) printf("yes\n", i); else printf("no\n"); }
#include <bits/stdc++.h> int main() { int n, i, j, r; char lvl[110]; scanf("%d", &n); scanf(" %s", lvl); for (r = 1; r < n; r++) { for (i = 0; i < n; i++) { for (j = 0; j <= 4; j++) { if (i + j * r >= n || lvl[i + j * r] != '*') break; } if (j >= 5) { printf("yes\n"); return 0; } } } printf("no\n"); return 0; }
#include <bits/stdc++.h> using namespace std; int s[105]; int main() { int n; string a; cin >> n >> a; for (int i = 1; i < n; i++) { for (int j = 0; j < n; j++) { if (a[j] == '*') { int k = 0; int t = j; while (k < 4 && j + i < n && a[j + i] == '*') j += i, k++; if (k == 4) return puts("yes"), 0; j = t; } } } cout << "no" << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; char *c = new char[n]; cin >> c; bool f = false; for (int k = 1; k < 100; k++) for (int j = 0; j < n; j++) if ((j + 4 * k) < n) if ((c[j] == c[j + k]) && (c[j + k] == c[j + 2 * k]) && (c[j + 2 * k] == c[j + 3 * k]) && (c[j + 3 * k] == c[j + 4 * k]) && (c[j] == '*')) f = true; if (f == true) cout << "yes"; else cout << "no"; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int i, j, k, cnt, n, flg; flg = 0; string s; cin >> n >> s; for (i = (0); i < (n); ++i) { for (j = (1); j < (n); ++j) { k = i; cnt = 0; while (k < n && cnt < 6 && s[k] != '.') { k += j; cnt++; } if (cnt == 5) { flg = 1; break; } } if (flg == 1) break; } if (flg) cout << "yes" << endl; else cout << "no" << endl; }
#include <bits/stdc++.h> using namespace std; int main() { int ar[1010] = {0}, n, i, j = 1; char ch; cin >> n; int count = 0; for (i = 1; i <= n; i++) { cin >> ch; if (ch == '*') { ar[i] = 1; } } count = 0; int flag = 0; int ans, a; for (i = 1; i <= n; i++) { if (ar[i]) { a = i; ans = 1; while (ans < n) { count = -1; for (int k = a;; k += ans) { if (ar[k] == 1) { count++; if (count == 4) { cout << "yes\n"; return 0; } } else break; } ans++; } } } cout << "no\n"; return 0; }
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:128777216") using namespace std; const long long LINF = 1000000000000000000LL; const int INF = 1000000000; const long double eps = 1e-9; const long double PI = 3.1415926535897932384626433832795l; void prepare(string s) { if (s.length() != 0) { freopen((s + ".in").c_str(), "r", stdin); freopen((s + ".out").c_str(), "w", stdout); } } const int NMAX = 155; int n; char s[NMAX]; void read() { scanf("%d\n", &n); scanf("%s", s); } void solve() { for (int i = 0; i < (int)(n); i++) { if (s[i] == '*') { for (int j = 1; j <= n; j++) { bool ok = true; int c = 0; for (int k = i; c < 5 && k < n; k += j, c++) { ok = ok && s[k] == '*'; } if (ok && c == 5) { printf("yes\n"); return; } } } } printf("no\n"); } int main() { prepare(""); read(); solve(); return 0; }
#include <bits/stdc++.h> using namespace std; const int oo = 0x3f3f3f3f; int n; char s[109]; bool proc2(int i, int j) { int acc = 0; while (i < n) { if (s[i] == '.') acc = 0; else acc++; if (acc == 5) { return 1; } i += j; } return 0; } bool proc() { for (int(j) = (1); (j) < (n / 2); ++(j)) for (int(i) = (0); (i) < (j + 2); ++(i)) { if (proc2(i, j)) return 1; } return 0; } int main() { while (scanf("%d", &n) == 1) { scanf("%s", s); puts(proc() ? "yes" : "no"); } return 0; }
#include <bits/stdc++.h> using namespace std; int main(int argc, char **argv) { int n, p[101]; char c[101]; cin >> n; for (int i = 0; i < n; ++i) { cin >> c[i]; } for (int i = 0; i < n; ++i) { for (int j = 0; j <= n; ++j) { p[j] = 0; } for (int j = i; j <= n; ++j) { if ((c[j] == '*') && (c[j - i] == '*')) p[j] = p[j - i] + 1; if (p[j] == 4) { cout << "yes"; return 0; } } } cout << "no"; return 0; }
#include <bits/stdc++.h> using namespace std; char arr[108]; int main() { int i, j, k, t, n, m, a, b, c, x, y, z; cin >> n; int flag = 0; for (i = 1; i <= n; i++) { cin >> arr[i]; } int gap, cnt = 0; for (i = 1; i <= n; i++) { if (arr[i] == '*') { for (j = i + 1; j <= i + n / 4; j++) { if (arr[j] == '*') { cnt = 0; gap = j - i; for (k = j; k <= n; k += gap) { if (arr[k] == '*') { cnt++; if (cnt >= 4) { flag = 1; break; } } else break; } } if (flag == 1) break; } if (flag == 1) break; } } if (flag == 1) cout << "yes"; else cout << "no"; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { bool exit = true, found = true; int n; cin >> n; string s; cin >> s; vector<int> y; vector<int> x; for (int i = 0; i < n; i++) { if (s[i] == '*') { x.push_back(i); } } exit = false; for (int j = x.size() - 1; j >= 0; j--) { for (int k = 0; k < x.size(); k++) { exit = false; float z = x[j] - x[k] + 1.0; float c = (z - 5.0) / 4.0; if (x[k] < x[j] && c == int(c)) { c++; for (int i = x[k]; i <= x[j]; i += int(c)) { if (s[i] != '*') { exit = true; break; } } if (!exit) { cout << "yes"; return 0; } } } } cout << "no"; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n; char A[100 + 3]; cin >> n; cin >> A; int s = 1; while (s < (n / 4) + 1) { for (int i = 0; i < n && i + 4 * s < n; i++) { if (A[i] == '*' && A[i + s] == '*' && A[i + 2 * s] == '*' && A[i + 3 * s] == '*' && A[i + 4 * s] == '*') { cout << "yes" << endl; return 0; } } s++; } cout << "no" << endl; return 0; }
#include <bits/stdc++.h> using namespace std; template <typename T> inline T sqr(const T &x) { return x * x; } const int N_MAX = 20000; const int SUP_I = (int)1e+9; const unsigned long long int SUP_LL = (unsigned long long int)1e+16; const double EPS = 1e-6; int main() { int n; cin >> n; char c; vector<int> a; for (int i = 0; i < n; i++) { cin >> c; if (c == '*') a.push_back(i); } bool f = false; if (a.size() >= 5) { for (int i1 = 0; i1 < a.size() - 4 && !f; i1++) { for (int i2 = i1 + 1; i2 < a.size() - 3 && !f; i2++) { for (int i3 = i2 + 1; i3 < a.size() - 2 && !f; i3++) { for (int i4 = i3 + 1; i4 < a.size() - 1 && !f; i4++) { for (int i5 = i4 + 1; i5 < a.size() && !f; i5++) { int delux = a[i2] - a[i1]; f = (a[i5] - a[i4] == delux && a[i4] - a[i3] == delux && a[i3] - a[i2] == delux); } } } } } } if (f) cout << "yes" << endl; else cout << "no" << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { bool mycondition = true; int saveI = -1; int n; cin >> n; char myString[n]; for (int i = 0; i < n; i++) { cin >> myString[i]; } for (int j = 0; j < n; j++) { if (myString[j] == '*') { saveI = j; } for (int i = 1; i <= n - 1; i++) { if (saveI + (4 * i) <= n - 1) { if (myString[saveI] == '*' && myString[saveI + i] == '*' && myString[saveI + (2 * i)] == '*' && myString[saveI + (3 * i)] == '*' && myString[saveI + (4 * i)] == '*') { cout << "YES" << endl; return 0; } } else { break; } } } cout << "NO" << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; string s; cin >> s; for (int i = 0; i < n; i++) { if (s[i] == '*') { for (int j = 1; j < n; j++) { int t = i; int k = 0; while (k < 6 && t < n && s[t] == '*') { t = t + j; k++; } if (k == 5) { cout << "yes"; return 0; } } } } cout << "no"; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long n; cin >> n; string s; cin >> s; vector<long long> v; for (long long i = 0; i < n; i++) { if (s[i] == '*') v.push_back(i + 1); } bool ko = false; for (long long i = 0; i < v.size(); i++) { bool ok = false; for (long long j = i + 1; j < v.size(); j++) { long long d = v[j] - v[i]; long long prev = v[j]; long long ans = 2; for (long long k = j + 1; k < v.size(); k++) { if ((v[k] - prev) == d) { ans++; prev = v[k]; } } if (ans >= 5) { ok = true; break; } } if (ok == true) { ko = true; break; } } if (ko == true) cout << "yes" << endl; else cout << "no" << endl; return 0; }
#include <bits/stdc++.h> using namespace std; const long double eps = 1e-9; const int inf = (1 << 30) - 1; const long long inf64 = ((long long)1 << 62) - 1; const long double pi = acos(-1); template <class T> T sqr(T x) { return x * x; } template <class T> T abs(T x) { return x < 0 ? -x : x; } const int MAXN = 200; const int k = 4; int a[MAXN]; int main() { ios_base::sync_with_stdio(0); int n; cin >> n; string s; cin >> s; for (int i = 0; i < n; ++i) { a[i] = (s[i] == '*' ? 1 : 0); } for (int d = 1; d < n; ++d) { for (int i = 0; i + k * d < n; ++i) { bool key = true; for (int j = 0; j <= k; ++j) { if (a[i + j * d] == 0) { key = false; break; } } if (key) { cout << "yes" << endl; return 0; } } } cout << "no" << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int n; char s[500]; int main() { ios::sync_with_stdio(0); cin >> n >> s; for (int i = 0; i < n - 3; ++i) { if (s[i] == '*') { for (int j = i + 1; j < n - 2; ++j) { if (s[j] == '*') { if (s[i + (j - i) * 2] == '*' && s[i + (j - i) * 3] == '*' && s[i + (j - i) * 4] == '*') { cout << "yes\n"; return 0; } } } } } cout << "no\n"; }
#include <bits/stdc++.h> using namespace std; string s; int n; int ok = 0; int main() { ios::sync_with_stdio(false); cin >> n; cin >> s; for (int i = 0; i <= n - 5; i++) { if (s[i] == '*') { for (int j = 1; j <= n; j++) { int now = i, total = 0; while (now < n && s[now] == '*' && total < 5) { total++; now = now + j; } if (total == 5) { ok = 1; goto output; } } } } output: if (ok) { cout << "yes"; } else cout << "no"; return 0; }
#include <bits/stdc++.h> using namespace std; bool v[1100]; bool check(int p, int jump) { bool ret = true; for (int i = 0; i < 5; i++) { ret &= v[p + i * jump]; } return ret; } int main() { int n; scanf("%d", &n); for (int i = 0; i < n; i++) { char x; scanf(" %c", &x); if (x == '*') v[i] = true; else v[i] = false; } int flag = false; for (int i = 1; i <= 100; i++) { for (int j = 0; j < n; j++) { flag |= check(j, i); } } printf("%s\n", flag ? "yes" : "no"); return 0; }
#include <bits/stdc++.h> using namespace std; int n; char seg[105]; int main() { cin >> n; for (int i = 0; i < n; i++) cin >> seg[i]; for (int i = 0; i < n - 4; i++) { if (seg[i] == '*') { for (int j = 1; i + 4 * j < n; j++) { if (seg[i + j] == '*' && seg[i + 2 * j] == '*' && seg[i + 3 * j] == '*' && seg[i + 4 * j] == '*') { cout << "yes" << endl; return 0; } } } } cout << "no" << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; char s[150]; cin >> s; bool ans = false; for (int p = 0; p < n && !ans; p++) for (int d = 1; p + 4 * d < n && !ans; d++) { bool ok = true; for (int i = 0; i < 5 && ok; i++) if (s[p + d * i] != '*') ok = false; if (ok) ans = true; } if (ans) cout << "yes" << endl; else cout << "no" << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int i, j, k, n, count = 0; char a[120]; scanf("%d\n", &n); scanf("%s", a + 1); int flag; for (i = 1; i <= n; i++) if (a[i] == '*') for (j = i + 1; j <= (n - i + 1) / 4 + i; j++) if (a[j] == '*') { flag = 1; int num = j - i; for (k = 1; k <= 3; k++) { if (a[j + num * k] == '*') continue; flag = 0; } if (flag == 1) { printf("yes\n"); return 0; } } printf("no\n"); return 0; }
#include <bits/stdc++.h> using namespace std; int main() { bool ans = 0; int n; char a[200]; cin >> n; for (int i = 0; i < n; i++) cin >> a[i]; int t; for (int i = 0; i < n; i++) { if (a[i] == '.') continue; for (int j = 1; j < n; j++) { t = 0; for (int k = 1; k <= 4; k++) { if (i + j * k >= n) break; if (a[i + j * k] == '*') t++; } if (t == 4) { ans = 1; break; } } if (ans) break; } if (ans) cout << "yes\n"; else cout << "no\n"; }
#include <bits/stdc++.h> using namespace std; int N; char S[200]; int check(int j) { return S[j] == '*'; } int main(void) { scanf("%d\n", &N); gets(S); for (int i = 0; i < N; i++) if (check(i)) for (int j = 1; j < N; j++) if (check(i + j) && check(i + 2 * j) && check(i + 3 * j) && check(i + 4 * j)) { printf("yes"); return 0; } printf("no"); return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; string s; cin >> s; int ma = 0; for (int i = 1; i <= n; i++) { for (int j = 0; j < n; j++) { int le = 0; for (int k = j; k < n; k += i) { if (s[k] == '*') { le++; ma = max(le, ma); } else le = 0; } } } if (ma >= 5) cout << "yes" << endl; else cout << "no" << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n = ({ int x; scanf("%d", &x); x; }); string s; cin >> s; string ans = "no"; for (int d = (1); d < (30); d += (1)) { for (int i = (0); i < (n); i += (1)) { int g = 1; for (int j = (0); j < (5); j += (1)) { if (i + j * d >= n || s[i + j * d] == '.') { g = 0; } } if (g) { ans = "yes"; break; } } } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; int main() { ifstream ff("file.txt"); int n; cin >> n; char *A = new char[n]; int idxB = -1; int idxE; for (int i = 0; i < n; i++) { cin >> A[i]; if (A[i] == '*' && idxB == -1) { idxB = i; } if (A[i] == '*') { idxE = i; } } if (idxB == -1) { cout << "no" << endl; return 0; } for (int i = idxB; i <= idxE; i++) { if (A[i] == '.') { continue; } for (int j = 1; j < idxE; j++) { int z = i + j; if (A[z] == '*') { z += j; if (A[z] == '*') { z += j; if (A[z] == '*') { z += j; if (A[z] == '*') { cout << "yes" << endl; return 0; } } } } } } cout << "no" << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n; char a[200]; cin >> n; for (int i = 0; i < n; i++) cin >> a[i]; int jj, j; for (int k = 1; k < n; k++) for (int i = 0; i < n; i++) { jj = 0; j = i; while (j < n && a[j] == '*') { jj++; j += k; } if (jj > 4) { cout << "yes"; return 0; } } cout << "no"; return 0; }
#include <bits/stdc++.h> int main() { int num; scanf("%d", &num); char arr[num]; scanf("%s", &arr[0]); bool valid = false; for (int i = 1; i < num / 4.0; i++) { for (int j = 0; j < num; j++) { bool control = true; if (j + 4 * i >= num) { control = false; break; } if (arr[j] != '*' || arr[j + i] != '*' || arr[j + 2 * i] != '*' || arr[j + 3 * i] != '*' || arr[j + 4 * i] != '*') control = false; if (control) { valid = true; break; } } } if (valid) printf("yes\n"); else printf("no\n"); }
#include <bits/stdc++.h> using namespace std; string s; int main() { cin >> s >> s; for (int j = 0; j < s.size(); j++) if (s[j] == '*') for (int i = j + 1; i < s.size(); i++) if (s[i] == '*') { int dis = i - j; if (i + 3 * dis >= s.size()) continue; if (s[i + 2 * dis] == '*' && s[i + dis] == '*' && s[i + 3 * dis] == '*') { puts("yes"); return 0; } } puts("no"); }
#include <bits/stdc++.h> using namespace std; int main(void) { int n, i, step, start, levelLength; bool ans = false; string level; cin >> n; cin >> level; levelLength = level.length(); for (start = 0; start < levelLength; start++) if (level[start] == '*') for (step = 1; step <= (levelLength - start) / 4; step++) { ans = true; for (i = 1; i < 5 && start + step * i < levelLength && ans; i++) if (level[start + step * i] != level[start + step * (i - 1)]) ans = false; if (ans && i == 5) goto finish; else if (ans) ans = false; } finish: cout << (ans ? "yes" : "no"); }
#include <bits/stdc++.h> using namespace std; char s[110]; int main() { int n; scanf("%d%s", &n, s); int l = n / 4; for (int i = 0; i < n; i++) { if (s[i] == '.') continue; for (int j = 1; j <= l; j++) { int cnt = 0; for (int k = i; k < n; k += j) { if (s[k] == '*') cnt++; else cnt = 0; if (cnt >= 5) { puts("yes"); return 0; } } } } puts("no"); return 0; }
#include <bits/stdc++.h> using namespace std; string str; int jump(int start, int d) { int res = 0; for (int i = start; i < str.size() && str[i] == '*'; i += d, res++) ; return res; } int main() { int m; cin >> m; cin >> str; int n = str.size() / 2 + 1; int MAX = 0; for (int i = 0; i < str.size() && MAX < 5; i++) { for (int j = 1; j < n && MAX < 5; j++) { MAX = max(MAX, jump(i, j)); } } if (MAX >= 5) cout << "yes" << endl; else cout << "no" << endl; }
#include <bits/stdc++.h> using namespace std; int n, k; string s; int main() { cin >> n; cin >> s; for (int i = 1; i < n; ++i) { for (int j = 0; j < n; ++j) { for (int l = j; l < n; l += i) { if (s[l] == '*') k++; else { k = 0; break; } if (k == 5) { cout << "yes"; return 0; } } k = 0; } } cout << "no"; }
#include <bits/stdc++.h> using namespace std; char S[1005]; int main() { int n; scanf("%d\n", &n); gets(S + 1); int Ans = 0; bool Res = false; for (Ans = 1; Ans <= n; ++Ans) for (int i = 1; i <= n; ++i) { if (S[i] == '*' && S[i + Ans] == '*' && S[i + Ans * 2] == '*' && S[i + Ans * 3] == '*' && S[i + Ans * 4] == '*') { Res = true; } } puts(Res ? "yes" : "no"); return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; string x; cin >> x; for (int k = 1; k <= n; k++) { for (int i = 0; i <= n; i++) { if (x[i] == '*') { int cnt = 0; for (int j = i + k; j <= n; j += k) { if (x[j] == '*') cnt++; else break; } if (cnt == 4) { cout << "yes"; return 0; } } } } cout << "no"; return 0; }
#include <bits/stdc++.h> using namespace std; int solve(string s) { for (size_t i = 1; i <= s.size() / 4; i++) { for (size_t j = 0; j <= s.size() - 4 * i + 1; j++) { size_t k; for (k = 0; k < 5; k++) { if (j + i * k >= s.size() || s[j + i * k] == '.') break; } if (k == 5) return 1; } } return 0; } int main() { int n; string s; cin >> n >> s; cout << (solve(s) == 1 ? "yes" : "no"); }
#include <bits/stdc++.h> using namespace std; int n; char _end[100000]; int main() { scanf("%d", &n); scanf("%s", _end); for (int i = 0; i < n; ++i) { for (int d = 1; i + 4 * d < n; ++d) { bool ok = true; for (int j = 0; j < 5; ++j) { if (_end[i + j * d] == '.') ok = false; } if (ok) { puts("yes"); return 0; } } } puts("no"); return 0; }
#include <bits/stdc++.h> using namespace std; string s; int n; int main() { cin >> n >> s; for (int i = 1; i <= n; i++) { for (int j = 0; j < s.length(); j++) if (j + i * 4 < s.length()) if ((s[j] == '*') && (s[j + i] == '*') && (s[j + i * 2] == '*') && (s[j + i * 3] == '*') && (s[j + i * 4] == '*')) { cout << "yes"; return 0; } } cout << "no"; }
#include <bits/stdc++.h> using namespace std; const int LIM = 26; const int INF = 1e+9; struct str { int a[LIM]; str(string s) { fill(a, a + LIM, 0); for (int i = 0; i < (int)s.length(); ++i) ++a[s[i] - 'a']; } }; string sa, sb, sc; int check(str& a, int cur, str& b, str& c) { int ans = INF; for (int i = 0; i < LIM; ++i) { if (a.a[i] < b.a[i] * cur) ans = -1; else if (c.a[i] != 0) ans = min(ans, (a.a[i] - cur * b.a[i]) / c.a[i]); } if (ans != -1) return ans + cur; return ans; } void print(str& a, int cur, str& b, str& c) { for (int i = 0; i < cur; ++i) cout << sb; int sec = check(a, cur, b, c) - cur; for (int i = 0; i < sec; ++i) cout << sc; for (int i = 0; i < LIM; ++i) { a.a[i] -= b.a[i] * cur; a.a[i] -= c.a[i] * sec; for (int j = 0; j < a.a[i]; ++j) cout << (char)('a' + i); } } int main() { ios_base::sync_with_stdio(false); cin >> sa >> sb >> sc; str a(sa), b(sb), c(sc); int ans = -1, step = -1, cur = 0; while (true) { int cur_a = check(a, cur, b, c); if (cur_a == -1) break; if (ans == -1 || ans < cur_a) { ans = cur_a; step = cur; } ++cur; } print(a, step, b, c); return 0; }
#include <bits/stdc++.h> using namespace std; long long mod = 1e9 + 7; long long QPow(long long a, long long b) { long long ans = 1; while (b > 0) { if (b & 1) ans = ans % mod * a % mod; a = a % mod * a % mod; b >>= 1; } return ans; } long long gcd(long long x, long long y) { if (x == 1 || y == 1) return 1; else { if (x == 0) return y; if (y == 0) return x; if (x % y == 0) return y; if (y % x == 0) return x; if (x > y) return gcd(x % y, y); else return gcd(x, y % x); } } long long toInt(string str) { if (str == "?" || str == "+" || str == "-" || str == "=") return -1; long long ans = 0; for (int i = (str[0] == '-'); i < str.size(); i++) { ans *= 10; ans += str[i] - '0'; } if (str[0] == '-') ans = -ans; return ans; } string toString(long long a) { if (a == 0) return "0"; string temp = ""; if (a < 0) temp.push_back('-'); long long tp = a; while (tp) { temp.push_back('0' + tp % 10); tp /= 10; } string temp2 = temp; for (int ii = 0; ii < temp.size(); ii++) { temp[ii] = temp2[temp.size() - 1 - ii]; } return temp; } long long inf = (long long)1 << 30; const int maxn = 50 + 5; int cnta[maxn], cntb[maxn], cntc[maxn]; int tpcnt[maxn]; int main() { ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); ifstream in("Text.txt"); long long n, m, t, x, y, k = 1, d; string str, a, b, c; cin >> a >> b >> c; for (int i = 0; i < a.size(); i++) cnta[a[i] - 'a']++; for (int i = 0; i < b.size(); i++) cntb[b[i] - 'a']++; for (int i = 0; i < c.size(); i++) cntc[c[i] - 'a']++; int mx = 100000; for (int i = 0; i < 26; i++) if (cntb[i]) mx = min(mx, cnta[i] / cntb[i]); int ansb = 0, ansc = 0; int mx2 = 0; int mx1; for (int i = 0; i <= mx; i++) { for (int i = 0; i < 26; i++) tpcnt[i] = cnta[i]; for (int j = 0; j < 26; j++) tpcnt[j] -= i * cntb[j]; mx1 = 100000; for (int j = 0; j < 26; j++) if (cntc[j]) mx1 = min(tpcnt[j] / cntc[j], mx1); if (mx1 + i > mx2) ansb = i, ansc = mx1, mx2 = i + mx1; } for (int i = 0; i < ansb; i++) { cout << b; for (int i = 0; i < 26; i++) cnta[i] -= cntb[i]; } for (int i = 0; i < ansc; i++) { cout << c; for (int i = 0; i < 26; i++) cnta[i] -= cntc[i]; } for (int i = 0; i < 26; i++) while (cnta[i]-- > 0) cout << char('a' + i); return 0; }
#include <bits/stdc++.h> using namespace std; const int MAXN = 1E5 + 100, SIGMA = 26; const int INF = 0x7fffffff; char sa[MAXN], sb[MAXN], sc[MAXN]; int a[SIGMA], b[SIGMA], c[SIGMA]; void getCnt(int (&a)[SIGMA], char s[]) { memset(a, 0, sizeof(a)); scanf("%s", s); for (char *p = s; *p; ++p) ++a[*p - 'a']; } int main() { getCnt(a, sa); getCnt(b, sb); getCnt(c, sc); int ansb = 0, ansc = 0; for (int i = 0; true; ++i) { bool flag = true; for (int j = 0; j < SIGMA; ++j) if (a[j] < b[j] * i) flag = false; if (!flag) break; int t = INF; for (int j = 0; j < SIGMA; ++j) t = min(t, c[j] == 0 ? INF : (a[j] - b[j] * i) / c[j]); if (ansb + ansc < i + t) { ansb = i; ansc = t; } } for (int i = 0; i < ansb; ++i) printf("%s", sb); for (int i = 0; i < ansc; ++i) printf("%s", sc); for (int i = 0; i < SIGMA; ++i) for (int j = a[i] - b[i] * ansb - c[i] * ansc; j; --j) putchar('a' + i); return 0; }
#include <bits/stdc++.h> int main(void) { char str[3][100001] = {{0}}; int str_count[3][26] = {{0}}; int num_b_max = 0, num_c_max = 0, num_sum_max = 0, same = 0; { int i, j, str_i_len; for (i = 0; i < 3; i++) { scanf("%s", str[i]); str_i_len = strlen(str[i]); for (j = 0; j < str_i_len; j++) str_count[i][str[i][j] - 'a']++; } } { int num_b, num_c, b_out, c_out, i, j; if (strcmp(str[1], str[2]) == 0) same = 1; for (num_b = 0, b_out = 0; !b_out; num_b++) { for (i = 0; i < 26; i++) if (str_count[0][i] < str_count[1][i] * num_b) b_out = 1; for (num_c = num_sum_max - num_b, c_out = 0; !b_out && !c_out && !same; num_c++) { for (j = 0; j < 26; j++) if (str_count[0][j] < str_count[1][j] * num_b + str_count[2][j] * num_c) c_out = 1; if (!c_out) num_b_max = num_b, num_c_max = num_c, num_sum_max = num_b + num_c; } if (same && !b_out) num_b_max = num_b; } } { int i, j, k, l, num; for (i = 0; i < num_b_max; i++) printf("%s", str[1]); for (j = 0; j < num_c_max; j++) printf("%s", str[2]); for (k = 0; k < 26; k++) { num = str_count[0][k] - str_count[1][k] * num_b_max - str_count[2][k] * num_c_max; for (l = 0; l < num; l++) printf("%c", k + 'a'); } } return 0; }
#include <bits/stdc++.h> using namespace std; const int maxn = 1e6 + 10; int getint() { int t = 0, flag = 1; char c = getchar(); while (c < '0' || c > '9' || c == '-') { if (c == '-') flag = -1; c = getchar(); } while (c >= '0' && c <= '9') t = t * 10 + c - '0', c = getchar(); return t * flag; } int GCD(int m, int n) { return !m ? n : GCD(n % m, m); } template <typename T> string to_string(T value) { ostringstream os; os << value; return os.str(); } long long MultMod(long long a, long long b, long long MOD) { a %= MOD; b %= MOD; long long ret = 0; while (b) { if (b & 1) { ret += a; if (ret >= MOD) ret -= MOD; } a = a << 1; if (a >= MOD) a -= MOD; b = b >> 1; } return ret; } long long n, t, m; string a, b, c; long long ac[27], bc[27], cc[27]; int main() { while (cin >> a >> b >> c) { memset(ac, 0, sizeof ac); memset(bc, 0, sizeof bc); memset(cc, 0, sizeof cc); for (auto e : a) ac[e - 'a']++; for (auto e : b) bc[e - 'a']++; for (auto e : c) cc[e - 'a']++; long long maxans = 0, maxi = 0, maxci = 0; for (long long i = 100000; i >= 0; i--) { bool sat = 1; for (long long j = 0; j < 26; j++) if (bc[j] * i > ac[j]) { sat = 0; break; } if (!sat) continue; long long ci = INT_MAX; for (long long j = 0; j < 26; j++) { if (!cc[j]) continue; ci = min((ac[j] - i * bc[j]) / cc[j], ci); } if (i + ci > maxans) { maxans = i + ci; maxi = i; maxci = ci; } } for (long long i = 0; i < maxi; i++) cout << b; for (long long i = 0; i < maxci; i++) cout << c; for (long long i = 0; i < 26; i++) { ac[i] -= ((long long)maxi * bc[i] + (long long)maxci * cc[i]); } for (long long i = 0; i < 26; i++) { for (long long j = 0; j < ac[i]; j++) cout << char(i + 'a'); } cout << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; int a[26], b[26], c[26]; char tmpa[100005], tmpb[100005], tmpc[100005]; int get(int x) { int ret = 1000000; for (int i = 0; i < 26; i++) if (c[i]) ret = min(ret, (a[i] - x * b[i]) / c[i]); return ret; } int main() { scanf("%s", tmpa); int len = strlen(tmpa); for (int i = 0; i < len; i++) a[tmpa[i] - 'a']++; scanf("%s", tmpb); len = strlen(tmpb); for (int i = 0; i < len; i++) b[tmpb[i] - 'a']++; scanf("%s", tmpc); len = strlen(tmpc); for (int i = 0; i < len; i++) c[tmpc[i] - 'a']++; int Max = 1000000; for (int i = 0; i < 26; i++) if (b[i]) Max = min(Max, a[i] / b[i]); int y = 0, x = 0; for (int i = 0; i <= Max; i++) { if (i + get(i) > x + y) { x = i; y = get(i); } } for (int i = 0; i < x; i++) { printf("%s", tmpb); for (int j = 0; j < 26; j++) a[j] -= b[j]; } for (int i = 0; i < y; i++) { printf("%s", tmpc); for (int j = 0; j < 26; j++) a[j] -= c[j]; } for (int i = 0; i < 26; i++) for (int j = 0; j < a[i]; j++) printf("%c", i + 'a'); return 0; }
#include <bits/stdc++.h> using namespace std; int main() { char a[100005], b[100005], c[100005]; int A[32], B[32], C[32]; scanf("%s %s %s", a, b, c); int l1 = strlen(a); int l2 = strlen(b); int l3 = strlen(c); for (int i = 0; i < l1; i++) { A[a[i] - 'a']++; } for (int i = 0; i < l2; i++) { B[b[i] - 'a']++; } for (int i = 0; i < l3; i++) { C[c[i] - 'a']++; } int mx = 0; int cnt1 = 0, cnt2 = 0, y = 0, z = 0; for (int i = 0;; i++) { int fl = 0; for (int j = 0; j < 30; j++) { if (A[j] < B[j] * i) { fl = 1; break; } } if (fl) { break; } y = i; int m = 1000000000; for (int j = 0; j < 30; j++) { if (C[j] != 0) { int x = (A[j] - (i * B[j])) / C[j]; m = min(m, x); } } if (mx < m + i) { mx = m + i; cnt1 = i; cnt2 = m; } } for (int i = 0; i < cnt1; i++) { printf("%s", b); } for (int i = 0; i < cnt2; i++) { printf("%s", c); } for (int i = 0; i < 30; i++) { A[i] -= (B[i] * cnt1); A[i] -= (C[i] * cnt2); for (int j = 0; j < A[i]; j++) { printf("%c", i + 'a'); } } }
#include <bits/stdc++.h> using namespace std; int main() { string a, b, c; cin >> a >> b >> c; int lena = a.length(), lenb = b.length(), lenc = c.length(); int counta[26], countb[26], countc[26]; for (int i = 0; i < 26; i++) counta[i] = countb[i] = countc[i] = 0; for (int i = 0; i < lena; i++) counta[a[i] - 'a']++; for (int i = 0; i < lenb; i++) countb[b[i] - 'a']++; for (int i = 0; i < lenc; i++) countc[c[i] - 'a']++; int tmpcounta[26]; int maxi = 0; int numb, numc; for (int i = 0; i < 26; i++) tmpcounta[i] = counta[i]; for (int i = 0; i <= lena; i++) { for (int j = 0; j < 26; j++) tmpcounta[j] -= countb[j] * i; int occurc = 1e9; bool flag = false; for (int j = 0; j < 26; j++) if (tmpcounta[j] < 0) flag = true; if (flag) break; for (int j = 0; j < 26; j++) if (countc[j] > 0) occurc = min(occurc, tmpcounta[j] / countc[j]); if (occurc + i >= maxi) { numb = i; numc = occurc; maxi = occurc + i; } for (int j = 0; j < 26; j++) tmpcounta[j] = counta[j]; } for (int i = 0; i < numb; i++) { for (int j = 0; j < lenb; j++) { cout << b[j]; counta[b[j] - 'a']--; } } for (int i = 0; i < numc; i++) { for (int j = 0; j < lenc; j++) { cout << c[j]; counta[c[j] - 'a']--; } } for (int i = 0; i < 26; i++) { for (int j = 0; j < counta[i]; j++) { cout << (char)(i + 'a'); } } cout << endl; }
#include <bits/stdc++.h> using namespace std; int cnts[300], cnt[2][300], i, b = -1, ans[2], tans[2] = {100001}; string str, s[2]; int main() { cin >> str >> s[0] >> s[1]; for (; i < str.length(); ++i) ++cnts[str[i]]; for (i = 0; i < s[0].length(); ++i) ++cnt[0][s[0][i]]; for (i = 0; i < s[1].length(); ++i) ++cnt[1][s[1][i]]; for (i = 'a'; i <= 'z'; ++i) if (cnt[0][i]) tans[0] = min(tans[0], cnts[i] / cnt[0][i]); for (; tans[0] > -1; --tans[0]) { tans[1] = str.length(); for (i = 'a'; i <= 'z'; ++i) if (cnt[1][i]) tans[1] = min(tans[1], (cnts[i] - cnt[0][i] * tans[0]) / cnt[1][i]); if (ans[0] + ans[1] < tans[0] + tans[1]) ans[0] = tans[0], ans[1] = tans[1]; } while (++b < 2) { for (i = 0; i < ans[b]; ++i) cout << s[b]; for (i = 'a'; i <= 'z'; ++i) cnts[i] -= cnt[b][i] * ans[b]; } for (i = 'a'; i <= 'z'; ++i) while (cnts[i]--) cout << (char)i; return 0; }
#include <bits/stdc++.h> using namespace std; int acnt[255]; int bcnt[255]; int ccnt[255]; string a, b, c; bool can(int* cnt_arr) { for (char ch = 'a'; ch <= 'z'; ch++) { if (cnt_arr[ch] > acnt[ch]) return false; } return true; } void calc(const string& s, int* cnt_arr) { for (int i = 0; i < s.length(); i++) { cnt_arr[s[i]]++; } } void write(const string& s) { cout << s; for (int i = 0; i < s.length(); i++) { if (acnt[s[i]] <= 0) { cout << "LOL"; cout << s << endl; exit(0); } acnt[s[i]]--; } } int main() { cin >> a >> b >> c; if (b.length() > c.length()) { swap(b, c); } calc(a, acnt); calc(b, bcnt); calc(c, ccnt); int mx = 0; pair<int, int> ans; int col = 0; while (true) { for (char ch = 'a'; ch <= 'z'; ch++) { if (acnt[ch] < bcnt[ch] * col) goto end; } int mn = 1e9; for (char ch = 'a'; ch <= 'z'; ch++) { if (ccnt[ch] == 0) continue; int cnt = acnt[ch] - bcnt[ch] * col; mn = min(mn, cnt / ccnt[ch]); } if (col + mn > mx) { mx = col + mn; ans = make_pair(col, mn); } col++; } end: for (int i = 0; i < ans.first; i++) write(b); for (int i = 0; i < ans.second; i++) write(c); for (char ch = 'a'; ch <= 'z'; ch++) { for (int i = 0; i < acnt[ch]; i++) { cout << ch; } } return 0; }
#include <bits/stdc++.h> using namespace std; const int N = 100000; const int delt = 255; long long fa[N], fb[N], fc[N]; int main() { ios::sync_with_stdio(false); string a, b, c; cin >> a; cin >> b; cin >> c; for (int i = 0; i < a.size(); i++) { fa[a[i] + delt]++; } for (int i = 0; i < b.size(); i++) { fb[b[i] + delt]++; } for (int i = 0; i < c.size(); i++) { fc[c[i] + delt]++; } pair<long long, pair<long long, long long> > ans = {0, {0, 0}}; for (int j = 0; j <= a.size(); j++) { long long kb = j; bool was = 0; for (char i = 'a'; i <= 'z'; i++) { if (fa[i + delt] < kb * fb[i + delt]) { was = 1; break; } } if (was) continue; long long kc = (long long)1e15; for (char i = 'a'; i <= 'z'; i++) { if (fc[i + delt] > 0) kc = min(kc, (fa[i + delt] - kb * fb[i + delt]) / fc[i + delt]); } ans = max(ans, make_pair(kb + kc, make_pair(kb, kc))); } for (char i = 'a'; i <= 'z'; i++) { fa[i + delt] -= ans.second.first * fb[i + delt]; fa[i + delt] -= ans.second.second * fc[i + delt]; } string str = ""; for (int i = 0; i < ans.second.first; i++) { str += b; } for (int i = 0; i < ans.second.second; i++) { str += c; } for (char i = 'a'; i <= 'z'; i++) { while (fa[i + delt] > 0) { str += i; fa[i + delt]--; } } cout << str << "\n"; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int sum = 1e9, cnt, k1 = 0, k2 = 0, i; string a, b, c; map<char, int> ma, mb, mc; cin >> a >> b >> c; for (char ch : a) ++ma[ch]; for (char ch : b) ++mb[ch]; for (char ch : c) ++mc[ch]; for (auto it : mb) sum = min(sum, ma[it.first] / it.second); for (i = 0; i <= sum; ++i) { cnt = 1e9; for (auto it : mc) cnt = min(cnt, (ma[it.first] - mb[it.first] * i) / it.second); if (cnt + i > k1 + k2) k1 = i, k2 = cnt; } for (i = 0; i < k1; ++i) cout << b; for (i = 0; i < k2; ++i) cout << c; for (auto it : ma) { it.second -= mb[it.first] * k1 + mc[it.first] * k2; for (i = 0; i < it.second; ++i) cout << it.first; } cout << endl; return 0; }
#include <bits/stdc++.h> using namespace std; string a, b, c, ansStr; int cnt[26], nc[26], nb[26], aa = 987654321, bb = 98764321, ans, x, y; int main() { ios::sync_with_stdio(false); cin >> a >> b >> c; for (int i = 0; i < a.size(); i++) cnt[a[i] - 'a']++; for (int i = 0; i < b.size(); i++) nb[b[i] - 'a']++; for (int i = 0; i < c.size(); i++) nc[c[i] - 'a']++; for (int i = 0; i < 26; i++) if (nb[i]) aa = min(aa, cnt[i] / nb[i]); for (int i = 0; i <= aa; i++) { for (int j = 0; j < 26; j++) if (nb[j]) cnt[j] -= nb[j] * i; int k = 987654321; for (int j = 0; j < 26; j++) { if (nc[j]) k = min(k, cnt[j] / nc[j]); } if (ans < (i + k)) ans = i + k, x = i, y = k; for (int j = 0; j < 26; j++) if (nb[j]) cnt[j] += nb[j] * i; } for (int i = 0; i < x; i++) ansStr += b; for (int i = 0; i < y; i++) ansStr += c; for (int j = 0; j < 26; j++) if (nb[j]) cnt[j] -= nb[j] * x; for (int i = 0; i < 26; i++) if (nc[i]) cnt[i] -= nc[i] * y; for (int i = 0; i < 26; i++) for (int j = 0; j < cnt[i]; j++) ansStr += (char)(i + 'a'); cout << ansStr << endl; }
#include <bits/stdc++.h> using namespace std; int occursa[30], occursb[30], occursc[30], aux[30]; string a, b, c; int numb, numc, sum, subb, subc; int main() { cin >> a >> b >> c; for (char l : a) occursa[l - 'a']++; for (char l : b) occursb[l - 'a']++; for (char l : c) occursc[l - 'a']++; numb = a.size(); for (int i = 0; i < 26; i++) if (occursb[i]) numb = min(numb, occursa[i] / occursb[i]); for (int i = numb; i >= 0; i--) { for (int j = 0; j < 26; j++) aux[j] = occursa[j] - (occursb[j] * i); numc = a.size(); for (int j = 0; j < 26; j++) if (occursc[j]) numc = min(numc, aux[j] / occursc[j]); if (i + numc > sum) { sum = i + numc; subb = i; subc = numc; } } for (int i = 0; i < subb; i++) cout << b; for (int i = 0; i < subc; i++) cout << c; for (int i = 0; i < 26; i++) for (int j = 0; j < occursa[i] - (occursb[i] * subb) - (occursc[i] * subc); j++) { char l = i + 'a'; cout << l; } cout << "\n"; return 0; }
#include <bits/stdc++.h> using namespace std; const int N = 100010; char a[N], b[N], c[N]; int fa[26], fb[26], fc[26]; int main() { scanf("%s %s %s", a, b, c); for (int i = 0; a[i]; i++) fa[a[i] - 'a']++; for (int i = 0; b[i]; i++) fb[b[i] - 'a']++; for (int i = 0; c[i]; i++) fc[c[i] - 'a']++; while (true) { int bx = INT_MAX, cx = INT_MAX; for (int i = 0; i < 26; i++) { if (!fb[i]) continue; bx = min(bx, fa[i] / fb[i]); } for (int i = 0; i < 26; i++) { if (!fc[i]) continue; cx = min(cx, fa[i] / fc[i]); } if (!bx && !cx) break; if (bx > cx) { for (int i = 0; b[i]; i++) { printf("%c", b[i]); fa[b[i] - 'a']--; } } else { for (int i = 0; c[i]; i++) { printf("%c", c[i]); fa[c[i] - 'a']--; } } } for (int i = 0; i < 26; i++) while (fa[i]--) printf("%c", i + 'a'); return 0; }
#include <bits/stdc++.h> using namespace std; string a, b, c; int s, k, mx, mi, mz, sa[30], sb[30], sc[30], st[30]; int f(int p[], int q[]) { int i, mn = 9e9; for (i = 0; i < 26; i++) { if (q[i] != 0 && p[i] / q[i] < mn) mn = p[i] / q[i]; } return mn; } int main() { int i, j, z; cin >> a >> b >> c; for (i = 0; a[i]; i++) sa[a[i] - 'a']++; for (i = 0; b[i]; i++) sb[b[i] - 'a']++; for (i = 0; c[i]; i++) sc[c[i] - 'a']++; k = f(sa, sb); for (i = k; i >= 0; i--) { for (j = 0; j < 26; j++) st[j] = sa[j] - sb[j] * i; z = f(st, sc); if (i + z > mx) { mx = i + z; mi = i; mz = z; } } for (i = 0; i < mi; i++) cout << b; for (i = 0; i < mz; i++) cout << c; for (i = 0; i < 26; i++) st[i] = sa[i] - sb[i] * mi - sc[i] * mz; for (i = 0; i < 26; i++) { for (j = 0; j < st[i]; j++) { cout << char(i + 'a'); } } }
#include <bits/stdc++.h> using namespace std; string i2s(int x) { stringstream ss; ss << x; return ss.str(); } int s2i(string str) { istringstream ss(str); int nro; ss >> nro; return nro; } char a[100005], b[100005], c[100005]; int pa[26], push_back[26], pc[26]; int main() { scanf("%[^\n]\n", a); scanf("%[^\n]\n", b); scanf("%[^\n]\n", c); int sza = strlen(a); int szb = strlen(b); int szc = strlen(c); for (int i = 0; i < sza; i++) { pa[a[i] - 'a']++; } for (int i = 0; i < szb; i++) { push_back[b[i] - 'a']++; } for (int i = 0; i < szc; i++) { pc[c[i] - 'a']++; } int ans = 0; int i = 0; int cnt = 0, cnt2 = 0; while (true) { int j = 0; int sobra[26]; memset(sobra, 0, sizeof(sobra)); for (j = 0; j < 26; j++) { sobra[j] = pa[j] - push_back[j] * i; if (sobra[j] < 0) break; } if (j < 26) break; int x = (1 << 30); for (int k = 0; k < 26; k++) { if (pc[k] && sobra[k] / pc[k] < x) x = sobra[k] / pc[k]; } if (i + x > ans) { ans = i + x; cnt = i; cnt2 = x; } i++; } for (int k = 0; k < cnt; k++) { printf("%s", b); } for (int k = 0; k < cnt2; k++) { printf("%s", c); } for (int k = 0; k < 26; k++) { pa[k] -= (cnt * push_back[k] + cnt2 * pc[k]); } for (int k = 0; k < 26; k++) { if (pa[k] > 0) { while (pa[k]--) { putchar('a' + k); } } } putchar('\n'); return 0; }
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; char s1[100005], s2[100005], s3[100005]; int len1, len2, len3; int h1[30], h2[30], h3[30]; int cnt2, cnt3, cnt; int main() { int i, j, k; while (~scanf("%s%s%s", s1, s2, s3)) { len1 = strlen(s1); len2 = strlen(s2); len3 = strlen(s3); memset(h1, 0, sizeof(h1)); memset(h2, 0, sizeof(h2)); memset(h3, 0, sizeof(h3)); for (i = 0; i < len1; i++) h1[s1[i] - 'a']++; for (i = 0; i < len2; i++) h2[s2[i] - 'a']++; for (i = 0; i < len3; i++) h3[s3[i] - 'a']++; cnt = 0; for (i = 1;; i++) { int p = 100005; for (j = 0; j < 26; j++) { if (h1[j] - h2[j] * i < 0) { p = 0; break; } } if (!p) break; int p2 = 100005; for (j = 0; j < 26; j++) { if (h3[j]) { p2 = min(p2, (h1[j] - h2[j] * i) / h3[j]); } } if (i + p2 > cnt) { cnt = i + p2; cnt2 = i; cnt3 = p2; } } for (i = 1;; i++) { int p = 100005; for (j = 0; j < 26; j++) { if (h1[j] - h3[j] * i < 0) { p = 0; break; } } if (!p) break; int p2 = 100005; for (j = 0; j < 26; j++) { if (h2[j]) { p2 = min(p2, (h1[j] - h3[j] * i) / h2[j]); } } if (i + p2 > cnt) { cnt = i + p2; cnt3 = i; cnt2 = p2; } } for (i = 0; i < cnt2; i++) printf("%s", s2); for (i = 0; i < cnt3; i++) printf("%s", s3); for (i = 0; i < 26; i++) { for (j = 0; j < h1[i] - cnt2 * h2[i] - cnt3 * h3[i]; j++) printf("%c", i + 'a'); } printf("\n"); } return 0; }
#include <bits/stdc++.h> using namespace std; long long w, m, sz, i, n, k, j; string aa, bb, cc; long long a[500], d[500], b[500], c[500]; int main() { cin >> aa >> bb >> cc; for (i = 0; i < aa.size(); i++) a[aa[i]]++; for (i = 0; i < bb.size(); i++) b[bb[i]]++; for (i = 0; i < cc.size(); i++) c[cc[i]]++; long long min1 = ((long long)1e+15); for (i = 'a'; i <= 'z'; i++) if (b[i] != 0) min1 = min(min1, a[i] / b[i]); n = min1; long long max1 = -1; for (i = 0; i <= n; i++) { for (j = 'a'; j <= 'z'; j++) d[j] = a[j] - b[j] * i; long long tmp = ((long long)1e+15); for (j = 'a'; j <= 'z'; j++) if (c[j] != 0) tmp = min(tmp, d[j] / c[j]); if (i + tmp > max1) { max1 = i + tmp; k = i; m = tmp; } } for (i = 'a'; i <= 'z'; i++) a[i] -= b[i] * k; for (i = 'a'; i <= 'z'; i++) a[i] -= c[i] * m; for (i = 0; i < k; i++) cout << bb; for (i = 0; i < m; i++) cout << cc; for (i = 'a'; i <= 'z'; i++) for (j = 0; j < a[i]; j++) cout << (char)i; cout << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int charA[27], charB[27], charC[27]; void decByC() { for (int j = 0; j < 27; j++) charA[j] -= charC[j]; } void decByB() { for (int j = 0; j < 27; j++) charA[j] -= charB[j]; } int findCountC() { int tempCountC = 1000007; for (int j = 0; j < 27; j++) { if (charC[j] != 0) { if (charA[j] / charC[j] < tempCountC) tempCountC = charA[j] / charC[j]; } } return tempCountC; } int findCountB() { int tempCountB = 1000007; for (int j = 0; j < 27; j++) { if (charB[j] != 0) { if (charA[j] / charB[j] < tempCountB) tempCountB = charA[j] / charB[j]; } } return tempCountB; } void restartC(int countC) { for (int i = 0; i < 27; i++) charA[i] += charC[i] * countC; } void restartB(int countB) { for (int i = 0; i < 27; i++) charA[i] += charB[i] * countB; } int main() { string a, b, c; cin >> a >> b >> c; for (int i = 0; i < a.length(); i++) charA[a[i] - 'a']++; for (int i = 0; i < b.length(); i++) charB[b[i] - 'a']++; for (int i = 0; i < c.length(); i++) charC[c[i] - 'a']++; int maxAns = 0, maxCountB = 0, maxCountC = 0; int countB = findCountB(); for (int i = 1; i <= countB; i++) { decByB(); int tempCountC = findCountC(); if (maxAns < tempCountC + i) { maxAns = tempCountC + i; maxCountC = tempCountC; maxCountB = i; } } restartB(countB); int countC = findCountC(); for (int i = 1; i <= countC; i++) { decByC(); int tempCountB = findCountB(); if (maxAns < tempCountB + i) { maxAns = tempCountB + i; maxCountB = tempCountB; maxCountC = i; } } restartC(countC); for (int i = 0; i < maxCountB; i++) cout << b; for (int i = 0; i < maxCountC; i++) cout << c; for (int i = 0; i < 27; i++) charA[i] -= (charB[i] * maxCountB + charC[i] * maxCountC); for (int i = 0; i < 27; i++) { while (charA[i]) { cout << (char)(i + 'a'); charA[i]--; } } return 0; }