text
stringlengths
49
983k
#include <bits/stdc++.h> using namespace std; long long a[105] = { 0, 47, 74, 4477, 4747, 4774, 7447, 7474, 7744, 444777, 447477, 447747, 447774, 474477, 474747, 474774, 477447, 477474, 477744, 744477, 744747, 744774, 747447, 747474, 7...
#include <bits/stdc++.h> using namespace std; const int inf = (int)1e9; const int maxn = 200000; char s[maxn]; char w[maxn]; int n; bool go(int i, int dif, bool any) { if (n - i < abs(dif)) { return false; } if (i == n) { return true; } if (any || s[i] <= '4') { w[i] = '4'; bool can = false; ...
#include <bits/stdc++.h> using namespace std; int n; string s, ans; bool dfs(int st, int n4, int n7, bool flag) { if (st == n) return true; if (flag) { for (int i = 0; i < n4; i++) ans[st + i] = '4'; st += n4; for (int i = 0; i < n7; i++) ans[st + i] = '7'; return true; } if (n4 && s[st] <= '4')...
#include <bits/stdc++.h> using namespace std; string s; vector<char> v; int l, r; void print(int l, int r) { for (int i = 0; i < (int)v.size(); ++i) cout << v[i]; for (int i = 0; i < l; ++i) cout << '4'; for (int i = 0; i < r; ++i) cout << '7'; exit(0); } void flashback(int x) { --x; for (int i = x; i >= 0;...
#include <bits/stdc++.h> using namespace std; queue<pair<long long, int>> q; int main() { long long x, c, val; cin >> x; q.push(make_pair(0, 0)); while (!q.empty()) { val = q.front().first; c = q.front().second; q.pop(); if (x <= val && c == 0) { cout << val; return 0; } q.pu...
#include <bits/stdc++.h> using namespace std; char num[100010]; long long ans[100010]; long long f[10]; long long F(long long pos, long long isEq) { if (num[pos] == 0) return true; for (long long i = 4; i <= 7; i += 3) { if (f[i] == 0) continue; if (isEq && i < (num[pos] - '0')) continue; f[i]--; if...
#include <bits/stdc++.h> using namespace std; void __print(int x) { cerr << x; } void __print(float x) { cerr << x; } void __print(double x) { cerr << x; } void __print(long double x) { cerr << x; } void __print(char x) { cerr << '\'' << x << '\''; } void __print(const char *x) { cerr << '\"' << x << '\"'; } void __pri...
#include <bits/stdc++.h> using namespace std; string second; string smallest(int n) { string res; for (int i = 0; i < n; i++) res += '4'; for (int i = 0; i < n; i++) res += '7'; return res; } string largest(int n) { string res; for (int i = 0; i < n; i++) res += '7'; for (int i = 0; i < n; i++) res += '4'...
#include <bits/stdc++.h> char a[100005], b[100005]; int p4[100005], c[100005]; int main() { int i, j, c4 = 0, l, h, c7 = 0, f = 0; scanf("%s", a); l = strlen(a); if (l & 1) { h = (l + 1) >> 1; for (i = 0; i < h; i++) putchar(52); for (i = 0; i < h; i++) putchar(55); return 0; } else { h = ...
#include <bits/stdc++.h> using namespace std; int l; char s[(1 << 20)]; char z[(1 << 20)]; int go(int f, int k, int eq) { int t = l - k; if (!t) return !f; if (t < f) return 0; if (!eq) { if (f) { z[k] = '4'; return go(f - 1, k + 1, 0); } else { z[k] = '7'; return go(f, k + 1, 0)...
#include <bits/stdc++.h> using namespace std; char ans[100010], s[100010]; int len; bool dfs(int x, int y, int dep, bool same) { if (dep == len) { ans[len] = '\0'; printf("%s\n", ans); return (true); } if (!same) { if (x) { ans[dep] = '4'; return (dfs(x - 1, y, dep + 1, false)); } ...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); string s; cin >> s; int n = s.length(); if (n % 2 != 0) { int count1 = (n + 1) / 2; for (int i = 0; i < count1; i++) cout << "4"; for (int i = 0; i < count1; i++) cout << "7"; return 0...
#include <bits/stdc++.h> using namespace std; void simple(int each) { for (int i = 0; i < each; i++) printf("4"); for (int i = 0; i < each; i++) printf("7"); cout << endl; } char str[200000], res[200000]; int n7[200000], n4[200000]; int l; bool can(int cur, int r4, int r7) { if (cur == l) return true; if (r7 ...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long n; cin >> n; long long size = 0, nn = n; while (nn) { size++; nn /= 10; } if (!(size & 1)) { long long lim = 1 << size; for (long long i = 0; i < lim; i++) { if (__...
#include <bits/stdc++.h> using namespace std; char s[100005]; int n, a[100005]; int main() { scanf("%s", s); n = strlen(s); for (int i = (0); i < (n); i++) a[i] = s[i] - '0'; int carry = 0, last = n; for (int i = (n)-1; i >= (0); i--) { if (carry) last = i; a[i] += carry; if (a[i] >= 10) car...
#include <bits/stdc++.h> using namespace std; int main() { string n; string made; cin >> n; bool ls = false; for (int i = 0; i < n.length(); ++i) { if (ls) { made = made + "4"; } else if (n[i] <= '4') { made = made + "4"; if (n[i] < '4') ls = true; } else if (n[i] <= '7') { ...
#include <bits/stdc++.h> using namespace std; int main(void) { string n; cin >> n; if (((n).size()) % 2) n = '0' + n; string tmp(((n).size()), '7'); for (int i = (((n).size()) / 2); i < (((n).size())); ++i) tmp[i] = '4'; if (tmp < n) { for (int i = (0); i < ((((n).size()) / 2 + 1)); ++i) cout << '4'; ...
#include <bits/stdc++.h> using namespace std; long long n, i, t, k, j, m; int main() { vector<vector<long long> > v(10); v[0].push_back(4); v[0].push_back(7); for (i = 1; i < 10; i++) { for (j = 0; j < v[i - 1].size(); j++) { long long x = v[i - 1][j]; v[i].push_back(x * 10 + 4); v[i].push...
#include <bits/stdc++.h> using namespace std; const int INF = 1 << 27; const double EPS = 1e-10; const double PI = 3.1415926535897932384626433832795; const int CLK = CLOCKS_PER_SEC; string ans; string number; int n; void solve(int cnt, int f, int s, bool ok) { if (cnt == 0) { for (int i = 0; i < n; i++) cout << a...
#include <bits/stdc++.h> using namespace std; bool TtT(long long x) { int a = 0, b = 0; while (x > 0) { if (x % 10 == 4) a++; if (x % 10 == 7) b++; x /= 10; } return (a == b); } int main() { long long n; set<long long> s; cin >> n; int len = 0, buf = n; while (buf > 0) { len++; buf...
#include <bits/stdc++.h> using namespace std; const int N = 3e5 + 5, MOD = 1e9 + 7; long long int t, n, m, ans, c, sum, y, mn = 1e9; string s; vector<long long int> v; string x[10] = {"47", "4477", "444777", "44447777", "4444477777", "444444777777"}; void init() { for (int i = 0; i < 6; i+...
#include <bits/stdc++.h> using namespace std; string n; bool check(long long int pos, long long int four, long long int seven) { if (four < 0 || seven < 0) return false; if (n[pos] < '4') { for (long long int i = 0; i < four; i++) n[pos + i] = '4'; for (long long int i = 0; i < seven; i++) n[pos + four + i]...
#include <bits/stdc++.h> using namespace std; int main() { queue<pair<long long, long long> > q; long long x; cin >> x; q.push(make_pair(0, 0)); while (!q.empty()) { long long val, c; val = q.front().first; c = q.front().second; q.pop(); if ((val >= x) && (c == 0)) { cout << val; ...
#include <bits/stdc++.h> using namespace std; string vow = "aeiou"; const int dxhorse[] = {-2, -2, -1, -1, 1, 1, 2, 2}; const int dyhorse[] = {1, -1, 2, -2, 2, -2, 1, -1}; const int dx[] = {-1, 0, 0, 1}; const int dy[] = {0, -1, 1, 0}; const long double pie = 3.14159265358979; const long long mod = 1e9 + 7; long long a...
#include <bits/stdc++.h> using namespace std; int main() { vector<unsigned long long> v; char x2[] = "47"; do { v.push_back(stoi(x2)); } while (next_permutation(x2, x2 + 2)); char x4[] = "4477"; do { v.push_back(stoi(x4)); } while (next_permutation(x4, x4 + 4)); char x6[] = "444777"; do { ...
#include <bits/stdc++.h> using namespace std; const int oo = 1e9; const long long mod = 1e7; int main() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); long long n, i = 0ll, d = 0ll, c, f, s; cin >> n; while (1) { c = f = s = 0; for (int j = 0ll, t = 1ll; j < d; ++j, t *= 10ll) if (i & (1...
#include <bits/stdc++.h> using namespace std; string get(int n, int m) { string str; for (int i = 1; i <= n; i++) str.push_back('4'); for (int i = 1; i <= m; i++) str.push_back('7'); return str; } int32_t main() { ios_base ::sync_with_stdio(0); cin.tie(0); string str; cin >> str; int n = str.size(); ...
#include <bits/stdc++.h> using namespace std; string s, pre, nxt; int n; int isLucky() { for (int i = 0; i < (n); ++i) if (s[i] != '4' && s[i] != '7') return i; return n; } int main() { cin >> s; n = (int)(s).size(); int last = isLucky(); nxt = string(n / 2 + 1, '4') + string(n / 2 + 1, '7'); if (n % ...
#include <bits/stdc++.h> using namespace std; string s, t, ans; void f(int i, int x, int y, bool flag) { if (x > s.size() / 2 || y > s.size() / 2) return; if (i == s.size()) { ans = t; return; } if (flag) { t[i] = '4'; f(i + 1, x + 1, y, 1); if (ans != "") return; t[i] = '7'; f(i + 1...
#include <bits/stdc++.h> int lln(const char *line, char *output, int fours, int sevens) { int i, digit; if (*line == '\0') { *output = '\0'; return ((fours + sevens) != 0); } digit = *line - '0'; if (digit < 4 && fours) { *output = '4'; fours--; output++; } else if (digit == 4 && fours) ...
#include <bits/stdc++.h> using namespace std; char str[100005]; int flag[100005]; void print(int len) { for (int i = 0; i < len / 2; i++) { printf("4"); } for (int j = len / 2; j < len; j++) { printf("7"); } printf("\n"); } int main() { scanf("%s", str); int len = strlen(str); memset(flag, 0, si...
#include <bits/stdc++.h> using namespace std; char ans[100005]; string st; int n; int main() { ios::sync_with_stdio(false); while (cin >> st) { n = st.size(); string tmps = ""; for (int i = 0; i < n / 2; i++) { tmps += '7'; } for (int i = 0; i < n / 2; i++) { tmps += '4'; } i...
#include <bits/stdc++.h> using namespace std; const long long N = 1e3 + 5; vector<long long> v; void lucky(long long n) { if (n > 1e8) { return; } v.push_back(10 * n + 4); v.push_back(10 * n + 7); lucky(10 * n + 4); lucky(10 * n + 7); } long long SL(long long n) { string s = to_string(n); long long ...
#include <bits/stdc++.h> using namespace std; struct print { template <typename T> print& operator,(const T& v) { std::cout << v << " "; return *this; } }; int main() { long long a[] = {47, 74, 4477, 4747, 4774, 7447, 7474, 7744}; vector<long long> v(a, a + 8); long long n; scanf("%lld", &n); st...
#include <bits/stdc++.h> using namespace std; const long long MOD = 1e9 + 7; const long long INF = 1e9 + 9; signed main(void) { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cout.precision(10); cout << fixed; long long n; cin >> n; long long d = floor(log10(n) + 1); vector<long long> v; ...
#include <bits/stdc++.h> using namespace std; const int N = 100005; int len; char s[N], ans[N]; void print(int k) { for (int i = 1; i <= k / 2; i++) cout << '4'; for (int i = 1; i <= k / 2; i++) cout << '7'; } bool search(int k, int c4, int c7, int f) { if (k == len) return 1; if (f) { for (int i = 0; i + k...
#include <bits/stdc++.h> using namespace std; static const double EPS = 1e-9; string make_least_47(int n) { string ret; for (int i = 0; i < (int)(n); i++) { ret += '4'; } for (int i = 0; i < (int)(n); i++) { ret += '7'; } return ret; } string make_least_47_2(int r4, int r7) { string ret; for (in...
#include <bits/stdc++.h> using namespace std; const int MAXN = 111111; char s[MAXN]; int a[MAXN]; int o[MAXN], z[MAXN]; int l[MAXN]; int n; int main() { gets(s); n = strlen(s); reverse(s, s + n); for (int i = 0; i < n; i++) a[i] = s[i] - '0'; for (int i = n - 1; i >= 0; i--) { if (a[i] == 4 || a[i] == 7) ...
#include <bits/stdc++.h> using namespace std; string n; int ans[100005]; int l; int luck(int t) { if (t == l) { return 1; } if (n[t] < '4') { ans[t] = 4; for (int i = t; i < l; i++) { ans[i] = 4; } return 1; } else if (n[t] == '4') { if (luck(t + 1)) { ans[t] = 4; } else ...
#include <bits/stdc++.h> using namespace std; const long long MOD = 1e9 + 7; const long double PI = 3.141592653589793238462643383279502884197; priority_queue<int, vector<int>, greater<int> > pq; vector<int> v; char s[100003]; int n; void pr(int len) { for (int i = 0; i < len / 2; i++) printf("4"); for (int i = 0; i...
#include <bits/stdc++.h> int N, four[100005], svn[100005]; char buf[100005]; int main() { int i, j, k, a = 0, b = 0; scanf("%s", buf), N = strlen(buf); if (N & 1) { for (i = N; i; i--) buf[i] = buf[i - 1]; buf[0] = '0'; buf[++N] = 0; } for (i = 0; i < N; i++) { four[i] = a, svn[i] = b; if ...
#include <bits/stdc++.h> using namespace std; string st; long n, s[200000][3], ap, av; bool nice(string st) { long s1, s2; s1 = s2 = 0; for (int i = 0; i < st.size(); i++) if (st[i] == '4') ++s1; else if (st[i] == '7') ++s2; if (s1 == s2 && s1 + s2 == st.size()) return true; return false; ...
#include <bits/stdc++.h> using namespace std; vector<char> s, ans; ostream& operator<<(ostream& out, vector<char>& t) { for (int i = 0; i < t.size(); i++) printf("%c", t[i]); return out; } void genSuff(int ind, int fr, int sv, vector<char>& a) { while (a.size() > ind) a.pop_back(); for (int i = 0; i < fr; i++) ...
#include <bits/stdc++.h> using namespace std; char str1[1000000]; char ans[1000000]; int n; bool chek() { int c1, c2; c1 = 0; c2 = 0; for (int i = 0; i < n; i++) { if (str1[i] == '4') c1++; else if (str1[i] == '7') c2++; else return false; } return (c1 == c2); } bool banano(int...
#include <bits/stdc++.h> using namespace std; int main() { string s; int n; cin >> n; int k = 0; int h = 0; if (n > 77774444) { cout << 4444477777; return 0; } for (int i = n; i <= 1000000000; i++) { int j = i; h = 0; k = 0; while (j > 0) { if (j % 10 != 4 && j % 10 != 7) {...
#include <bits/stdc++.h> using namespace std; int main() { string n; cin >> n; int l = n.length(); vector<long long> superl; for (int len = l; len <= 10; len++) { if (len % 2) continue; for (int mask = 0; mask < 1 << len; mask++) { if (__builtin_popcount(mask) != len / 2) continue; string ...
#include <bits/stdc++.h> using namespace std; const int INF = 1000000100; const int MAXN = 1000100; string s; int gr[] = {0, 4, 5, 7, 8, 10}; int last[10], n; int ost[MAXN][5]; int czy_mniejsze_od_7(int p, int k) { int mini = INF; for (int i = 0; i < 3; i++) { mini = min(mini, ost[p][i]); } if (mini > k && ...
#include <bits/stdc++.h> using namespace std; const int MAXN = 100010; const int MAXM = 300010; const int INF = 0x7fffffff; const int MOD = 1e9 + 7; const double eps = 1e-6; const long double pi = acos(-1.0); char ans[100010], st[100010]; void fuck(int i, int j) { while (ans[j]) { swap(ans[j], ans[i]); i++; ...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; if (n > 77774444) { cout << "4444477777"; return 0; } for (int i = n;; i++) { int flag4 = 0; int flag7 = 0; int flag = 1; int x = i; while (x > 0) { if (x % 10 == 4) { flag4++; } else if...
#include <bits/stdc++.h> using namespace std; int len; string s; char ans[100005]; bool dfs(int pos, int cnt4, int cnt7, bool flag) { if (pos == len) return true; if (flag) { for (int i = 0; i < cnt4; i++) ans[pos++] = '4'; for (int i = 0; i < cnt7; i++) ans[pos++] = '7'; return true; } if (s[pos] <...
#include <bits/stdc++.h> using namespace std; string s; int n; void printMin(int sz) { for (int i = 0; i < sz / 2; i++) { cout << 4; } for (int i = sz / 2; i < sz; i++) { cout << 7; } cout << endl; } inline bool ok() { for (int i = 0; i < n / 2; i++) { if (s[i] == '4') return true; } return ...
#include <bits/stdc++.h> using namespace std; string s, ans; int n; bool Try(int j, int n4, int n7, bool flag) { if (j == n) return true; if (flag) { for (int i = 0; i < n4; i++) ans[i + j] = '4'; j += n4; for (int i = 0; i < n7; i++) ans[i + j] = '7'; return true; } if (n4 > 0 && s[j] <= '4') {...
#include <bits/stdc++.h> using namespace std; char s[100005]; int n; int main() { while (~scanf("%s", s)) { n = strlen(s); if (n & 1) { n = (n + 1) / 2; for (int i = 0; i < n; i++) putchar('4'); for (int i = 0; i < n; i++) putchar('7'); puts(""); continue; } int c4 = 0, c...
#include <bits/stdc++.h> using namespace std; long long max(long long a, long long b) { if (a > b) return a; else return b; } long long min(long long a, long long b) { if (a < b) return a; else return b; } long long mod = 1000000007; string s; int n; map<int, int> f; int calc(int i, char ans[]) ...
#include <bits/stdc++.h> using namespace std; string a; string out; int main() { cin >> a; if (a.size() % 2 == 1) { int k = a.size() + 1; for (int i = 0; i < k / 2; i++) cout << 4; for (int i = 0; i < k / 2; i++) cout << 7; cout << endl; return 0; } for (int i = 0; i < a.size() / 2; i++) { ...
#include <bits/stdc++.h> using namespace std; string x, y; bool gao(int i, int a, int b) { if (a == 0 && b == 0) { return true; } if (a > 0) { y += '4'; if (x[i] < '4') { y.insert(y.length(), a - 1, '4'); y.insert(y.length(), b, '7'); return true; } else if (x[i] == '4' && gao(i ...
#include <bits/stdc++.h> using namespace std; void func(vector<string>& v, int a, int b, int n, int total, string s) { if (total == n && a == b) { v.push_back(s); return; } if (total == n) return; func(v, a + 1, b, n, total + 1, s + "4"); func(v, a, b + 1, n, total + 1, s + "7"); } int main() { stri...
#include <bits/stdc++.h> using namespace std; string n, minx, maxn, ans; int len; int Dfs(int now, int num4, int num7, int flag) { int i; if (now >= len) return 1; if (flag) { for (i = 1; i <= num4; i++) ans.push_back('4'); for (i = 1; i <= num7; i++) ans.push_back('7'); return 1; } if (num4 && n[...
#include <bits/stdc++.h> using namespace std; struct Nodo { string txt; int c_4; int c_7; Nodo() {} Nodo(string texto, int C1, int C2) { txt = texto; c_4 = C1; c_7 = C2; } bool operator<(const Nodo &refe) const { if (txt.size() != refe.txt.size()) { return (txt.size() > refe.txt.size...
#include <bits/stdc++.h> using namespace std; const int M = 100050; char s[M], tmp[M]; int pos[M], ct[M], cnt1, cnt2; int main() { scanf("%s", s); int len = strlen(s); bool flag = 0; if (len & 1) { for (int i = 0; i < (len + 1) >> 1; i++) printf("4"); for (int i = 0; i < (len + 1) >> 1; i++) printf("7")...
#include <bits/stdc++.h> using namespace std; int len; string s; char ans[100005]; bool dfs(int pos, int cnt4, int cnt7, bool flag) { if (pos == len) return true; if (flag) { for (int i = 0; i < cnt4; i++) ans[pos++] = '4'; for (int i = 0; i < cnt7; i++) ans[pos++] = '7'; return true; } if (s[pos] <...
#include <bits/stdc++.h> using namespace std; long long n, s; void dfs(long long x, int s4, int s7) { if ((x >= n) && (s4 == s7) && ((x < s) || (s == 0))) s = x; if (x < n * 100) { dfs(x * 10 + 4, s4 + 1, s7); dfs(x * 10 + 7, s4, s7 + 1); } } int main() { cin >> n; dfs(0, 0, 0); if (n == 0) s = 47; ...
#include <bits/stdc++.h> using namespace std; void print(char* t, int k) { for (int i = 0; i < k; i++) t[i] = '4'; for (int i = 0; i < k; i++) t[i + k] = '7'; t[k + k] = 0; } void go2(char* s, int idx) { int n = strlen(s); int k = n / 2; int se = 0; int fo = 0; for (int i = 0; i < idx; i++) { if (s[...
#include <bits/stdc++.h> using namespace std; char num[100010]; int cnt[100010], four[100010], seven[100010]; int main() { scanf("%s", num + 1); int len = strlen(num + 1), dl = len; if (dl & 1) dl++; else { for (int i = 1; i <= dl; i++) { int digit = (i <= dl / 2 ? 7 : 4); if (digit < num[i]...
#include <bits/stdc++.h> using namespace std; char str[100100], ans[100100]; int len, num4, num7; bool solve(int i) { if (num4 == 0 && num7 == 0) { ans[i] == '\0'; return true; } if (str[i] < '4' && num4 > 0) { ans[i] = '4', num4--; ans[i + 1] = '\0'; return true; } if (str[i] == '4' && nu...
#include <bits/stdc++.h> using namespace std; string s; char res[100010]; int len; int func(int cur, int n4, int n7, int prev) { if (cur == len) { for (int i = (0), _n = (len); i < _n; i++) printf("%c", res[i]); cout << endl; return 1; } else { if (prev) { if (n4) { res[cur] = '4'; ...
#include <bits/stdc++.h> using namespace std; const int ml = 100005; string n; int len, len2; bool go1() { for (int i = 0; i < len2; i++) { if (n[i] < '7') return 1; if (n[i] > '7') return 0; } for (int i = len2; i < len; i++) { if (n[i] < '4') return 1; if (n[i] > '4') return 0; } return 1; }...
#include <bits/stdc++.h> using namespace std; set<long long> num; void f(int x, int a, int b, long long now) { if (x == 0) { num.insert(now); return; } if (a) f(x - 1, a - 1, b, now * 10 + 4); if (b) f(x - 1, a, b - 1, now * 10 + 7); } void init() { int i; for (i = 1; i <= 5; i++) f(i * 2, i, i, 0LL...
#include <bits/stdc++.h> using namespace std; vector<long long> lucky; void nums(long long number, int fours, int sevens) { if (number > 1e10) return; if (fours == sevens) lucky.push_back(number); nums(number * 10 + 7, fours, sevens + 1); nums(number * 10 + 4, fours + 1, sevens); } int main() { nums(4, 1, 0);...
#include <bits/stdc++.h> using namespace std; vector<long long> v; void lucky(long long z) { if (z > 1e10) return; if (z) v.push_back(z); lucky(z * 10 + 4); lucky(z * 10 + 7); } int main() { lucky(0); sort(v.begin(), v.end()); long long n; cin >> n; for (long long i = 0; i < v.size(); i++) { if (v...
#include <bits/stdc++.h> using namespace std; const int maxn = 100100; int n; char a[maxn], b[maxn]; bool dfs(int step, int n4, int n7, bool large) { if (step == n) return puts(b), true; if (large) if (n4) return b[step] = '4', dfs(step + 1, n4 - 1, n7, large); else return b[step] = '7', dfs(ste...
#include <bits/stdc++.h> using namespace std; bool flag; int len; string ori, tmp, ans; void dfs(string s, int req, int cnt) { if (flag) return; if (s.length() == req) { if (cnt == s.length() / 2) { if (s.length() > ori.length() || s >= ori) { ans = s; flag = 1; } } return; ...
#include <bits/stdc++.h> using namespace std; long long int tt; vector<long long int> ans; vector<long long int> a; long long int x, y; bool fun(long long int idx, bool check) { if (idx >= a.size()) { return true; } if (check) { if (x > 0) { ans.push_back(4); x--; return fun(idx + 1, che...
#include <bits/stdc++.h> using namespace std; const int inf(1010101010); int le; string s; bool kan_gelijk(int cnt) { string t; int r4(le / 2), r7(le / 2); for (int i(0); i < (cnt); i++) { if (s[i] != '4' && s[i] != '7') return false; if (s[i] == '4') t += '4', r4--; if (s[i] == '7') t += '7', r7--; ...
#include <bits/stdc++.h> using namespace std; string a; string ans = "", x = ""; bool Judge() { if (a.size() % 2) { return false; } string temp = ""; for (int i = 0; i < a.size(); i++) { if (i < a.size() / 2) { temp += "7"; } else { temp += "4"; } } return temp >= a; } void Deal(...
#include <bits/stdc++.h> using namespace std; vector<int> next_p(vector<int> s) { vector<int> ss = s; int I = -1, J = -1; for (int i = s.size() - 1; i >= 0; i--) { if (s[i] == 7) { I = i; break; } } for (int j = I - 1; j >= 0; j--) { if (s[j] == 4) { J = j; break; } }...
#include <bits/stdc++.h> const int N = 1e5 + 50; char s[N]; int lens, ok; int ws[N]; void dfs(int now, int _4, int _7) { if (now == lens) { for (int i = 0; i < lens; i++) putchar(ws[i] + 48); ok = 1; return; } if (!ok) if (s[now] < '4') { if (_4) ws[now] = 4, _4--; else ...
#include <bits/stdc++.h> using namespace std; long long int n; long long int res = 1000000000000000; int ass[16]; void check(int c1, int c2, long long int prev) { if (prev < 9000000000000) { if (c1 == c2) { if (prev >= n) res = min(res, prev); } long long int val1 = (prev * (long long int)10) + (lon...
#include <bits/stdc++.h> using namespace std; char s[100100]; char A[100100]; int f[100100], g[100100], ff[100100], gg[100100]; int n; void print(int a, int b, int p) { for (int i = a; i < n / 2; i++) A[p++] = '4'; for (int i = b; i < n / 2; i++) A[p++] = '7'; A[p] = 0; puts(A); } bool can(int a, int b, int p) ...
#include <bits/stdc++.h> using namespace std; const int N = 100500; const unsigned long long PW = 337; unsigned long long pw[N], hs[N], ht[N]; void calcPW() { pw[0] = 1; for (int i = 1; i < N; i++) { pw[i] = pw[i - 1] * PW; } } void calcH(char* s, unsigned long long* h, int n) { h[0] = 0; for (int i = 1; ...
#include <bits/stdc++.h> using namespace std; long long ma = 0, f = 100000000000, x; long long creat(short d, bool x) { long long nu = 0; short i; for (i = 0; i < d / 2; i++) nu *= 10, nu += (4 * !x + 7 * x); for (i = 0; i < d / 2; i++) nu *= 10, nu += (4 * x + 7 * !x); return nu; } void re(short d, short d4,...
#include <bits/stdc++.h> using namespace std; string s, t, ans; void f(int d, int x, int y, bool g) { if (x > s.size() / 2 || y > s.size() / 2) return; if (d == s.size()) { ans = t; return; } if (g) { t[d] = '4'; f(d + 1, x + 1, y, 1); if (ans != "") return; t[d] = '7'; f(d + 1, x, y...
#include <bits/stdc++.h> using namespace std; inline bool eq(double a, double b) { return fabs(a - b) < 1e-9; } const long long int inf = 1e15; inline int two(int n) { return 1 << n; } inline int test(int n, int b) { return (n >> b) & 1; } inline void set_bit(int& n, int b) { n |= two(b); } inline void unset_bit(int& n...
#include <bits/stdc++.h> using namespace std; bool cmp(long long a, long long b) { return (a > b); } long long ceil(const long long &a, const long long &b) { if (a % b == 0) return a / b; return a / b + 1; } long long mod = 1000000007; const long long N = 200005; long long go(string s) { stringstream geek(s); l...
#include <bits/stdc++.h> using namespace std; char str[100005]; int flag[100005]; void print(int len) { for (int i = 0; i < len / 2; i++) { printf("4"); } for (int j = len / 2; j < len; j++) { printf("7"); } printf("\n"); } int main() { scanf("%s", str); int len = strlen(str); memset(flag, 0, si...
#include <bits/stdc++.h> using namespace std; char s[100105], out[100105]; int a, b; int l; void print(int n) { int i; for (i = 1; i <= n / 2; i++) printf("4"); for (i = 1; i <= n / 2; i++) printf("7"); cout << endl; } int solve(int p) { if (p >= l) return 1; int i, j, k; int flag = 1; if (s[p] > '7') {...
#include <bits/stdc++.h> using namespace std; char n[100005]; char ans[100005]; int len; bool dfs(int pos, int cnt4, int cnt7, bool toup) { if (pos == len) return true; if (toup) { for (int i = 0; i < cnt4; i++) ans[pos++] = '4'; for (int i = 0; i < cnt7; i++) ans[pos++] = '7'; return true; } if (n[...
#include <bits/stdc++.h> using namespace std; char s[1000000]; int l, i, f[1100000]; bool bo; void dfs(int a, int b, int c) { if (bo) return; if (c > l) { for (i = 1; i <= l; i++) cout << f[i]; bo = true; return; } if (bo) return; if (int(s[c - 1]) - 48 < 4 && a) { for (i = 1; i < c; i++) cout...
#include <bits/stdc++.h> using namespace std; char str[100005]; int flag[100005]; void print(int len) { for (int i = 0; i < len / 2; i++) { printf("4"); } for (int j = len / 2; j < len; j++) { printf("7"); } printf("\n"); } int main() { while (~scanf("%s", str)) { int flag1 = 0; int len = st...
#include <bits/stdc++.h> using namespace std; inline int D() { int t; scanf("%d", &t); return t; } inline long long LLD() { long long t; scanf("%lld", &t); return t; } bool super(long long n) { int cnt4 = 0, cnt7 = 0; while (n > 0) { if (n % 10 == 4) cnt4++; else cnt7++; n /= 10;...
#include <bits/stdc++.h> using namespace std; const int MX = (1 << 19); string str; void jd(int n) { for (int j = 1; j <= n; j += 2) cout << '4'; for (int j = 1; j <= n; j += 2) cout << '7'; cout << endl; } int n; bool check(int pos) { int rf = n / 2, rs = n / 2; for (int j = 0; j <= pos; j++) { if (str[j...
#include <bits/stdc++.h> using namespace std; string s; int len, bagi2; int cnt4 = 0, cnt7 = 0; const int N = 100005; int ar[N]; bool masih = false; void rek(int pos) { if (cnt4 > bagi2 || cnt7 > bagi2) return; if (pos == len) { masih = true; return; } if (s[pos] < '4') { int k = pos; for (int i...
#include <bits/stdc++.h> using namespace std; const long long MAXN = 1010, INF = 100000000000; long long a[100], n, k, ans = INF; void check() { long long res = 0, p = 1, k1 = 0, k2 = 0; for (int i = 0; i < k; i++) { res = res * 10 + a[i]; k1 += (a[i] == 4); k2 += (a[i] == 7); } if (k1 == k2 && res ...
#include <bits/stdc++.h> using namespace std; void err(istream_iterator<string> it) {} template <typename T, typename... Args> void err(istream_iterator<string> it, T a, Args... args) { cerr << *it << " = " << a << endl; err(++it, args...); } long long n, ans = -1; void DFS(long long m, int c) { if (m >= n) { ...
#include <bits/stdc++.h> char s[100024], an[100024]; int len; bool f() { int k1, k2; k1 = k2 = len / 2; int i, j; for (i = 0; i < len; i++) { if (s[i] != '4' && s[i] != '7') break; if (s[i] == '4') { k1--; if (k1 < 0) { for (j = 0; j < i; j++) printf("%c", s[j]); for (; j < l...
#include <bits/stdc++.h> using namespace std; const int Maxn = 100005; int sum[Maxn]; int need; string s, res; void tryGet() { if (s.length() % 2) { need = s.length() + 1; return; } for (int i = s.length() - 1; i >= 0; i--) if (s[i] > '7') sum[i] = -1; else if (s[i] == '7') if (sum[i +...
#include <bits/stdc++.h> using namespace std; int main() { long long N; int tam; long long res; cin >> N; for (tam = 1;; tam++) { for (res = 0LL; res < (1LL << tam); res++) { long long w = 0LL; int carg = 0; for (long long i = 0LL, pot = 1LL; i < tam; i++, pot *= 10LL) { if (res ...
#include <bits/stdc++.h> using namespace std; string inp; string str(int a, char b) { if (a < 0) { cout << inp << endl; exit(0); } return string(a, b); } bool av(string a) { int c1 = 0, c2 = 0; for (int i = 0; i < a.size(); i++) { if (a[i] != '4' && a[i] != '7') return 0; if (a[i] == '4') ...
#include <bits/stdc++.h> using namespace std; int l; string s; char ret[100005]; bool f; bool isOk(const string& s) { bool f = true; for (int i = 0; i < l / 2; ++i) { if (s[i] - '0' != 7) { if (s[i] - '0' > 7) return false; else return true; } } for (int i = l / 2; i < l; ++i...
#include <bits/stdc++.h> using namespace std; long long n, ans = 1ll << 60; void F(long long x, int cnt_4, int cnt_7) { if (x >= n) { if (cnt_4 == cnt_7) { ans = min(ans, x); } } if (x > n * 100) return; F(x * 10 + 4, cnt_4 + 1, cnt_7); F(x * 10 + 7, cnt_4, cnt_7 + 1); } int main() { cin >> n;...