text
stringlengths
49
983k
#include <bits/stdc++.h> using namespace std; inline void Add(int &a, int b) { a += b; a >= 1000000007 ? a -= 1000000007 : 1; } inline void Sub(int a, int b) { a -= b; a < 0 ? a += 1000000007 : 1; } inline int add(int a, int b) { a += b; return a >= 1000000007 ? a - 1000000007 : a; } const int Q = 1 << 20; ...
#include <bits/stdc++.h> using namespace std; char c[2000010], a[2000010]; const int mod = 1e9 + 7; int n, tot, last, top[2000010], diff[2000010], ans[2000010], f[2000010]; struct PT { int ch[26], len, fa; } tr[2000010]; void init() { tr[++tot].len = -1; tr[0].fa = tr[1].fa = 1; top[0] = 1; } void insert(int no...
#include <bits/stdc++.h> using namespace std; int n; char s[1000006], origin[1000006]; int ch[1000006][27], fail[1000006], diff[1000006], anc[1000006], len[1000006], total, last; int f[1000006], g[1000006]; const int mod = 1e9 + 7; void init() { s[0] = '#'; len[1] = -1; fail[0] = total = 1; } int getfail(int ...
#include <bits/stdc++.h> using namespace std; const int MAXN = 1000005; const int MOD = 1e9 + 7; template <typename T> inline void read(T &AKNOI) { T x = 0, flag = 1; char ch = getchar(); while (!isdigit(ch)) { if (ch == '-') flag = -1; ch = getchar(); } while (isdigit(ch)) { x = x * 10 + ch - '0'...
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; const int maxn = 1000000 + 5; inline int add(int x, int y) { x += y; return x >= mod ? x -= mod : x; } namespace pam { int sz, tot, last; int ch[maxn][26], len[maxn], fail[maxn]; int cnt[maxn], dep[maxn], dif[maxn], slink[maxn]; char s[maxn]; in...
#include <bits/stdc++.h> using namespace std; const int N = 1000010, Mo = 1000000007; int cnt = 1, la; char a[N], s[N]; int fa[N], l[N], ch[N][26], f[N], w[N], g[N], fr[N]; inline int insert(int i) { int c = s[i] - 'a'; while (s[i] != s[i - l[la] - 1]) la = fa[la]; if (!ch[la][c]) { int x = fa[la]; l[++cn...
#include <bits/stdc++.h> using namespace std; char s[1000005], t[1000005]; int f[1000005], g[1000005], n; int ch[1000005][26], len[1000005], fa[1000005], cnt, lst, anc[1000005], diff[1000005]; void init() { cnt = 1; len[1] = -1, fa[0] = fa[1] = anc[0] = 1; } void extend(int x, int n, char *s) { int p = lst, n...
#include <bits/stdc++.h> using namespace std; long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); } const int MAXLEN = 1000000; const int MOD = 1000000007; const int MAXALPH = 26; struct ETNode { int len, suff, idx, diff, slink; int nxt[MAXALPH]; ETNode(int len, int suff, int idx) : len(l...
#include <bits/stdc++.h> using namespace std; inline int gi() { int data = 0, m = 1; char ch = 0; while (ch != '-' && (ch < '0' || ch > '9')) ch = getchar(); if (ch == '-') { m = 0; ch = getchar(); } while (ch >= '0' && ch <= '9') { data = (data << 1) + (data << 3) + (ch ^ 48); ch = getchar(...
#include <bits/stdc++.h> namespace QiShiBuShiTaoLuTi2333 { const int N = 1000100, INF = 1000000007, MOD = 1000000007; inline void inc(int a, int &b) { b = (a + b) % MOD; } struct node { int pos, delta, k; int lastpos() { return pos + delta * (k - 1); } node(int a = 0, int b = 0, int c = 0) : pos(a), delta(b), k(c...
#include <bits/stdc++.h> using namespace std; const int N = 1000010, mod = 1e9 + 7; int ch[N][26], fa[N], g[N], f[N], tot, lst, nxt[N], l[N], s[N], dif[N], pos[N]; char t[N]; int read() { int x = 0; char c = getchar(), flag = '+'; while (!isdigit(c)) flag = c, c = getchar(); while (isdigit(c)) x = x * 10 + c - ...
#include <bits/stdc++.h> using namespace std; inline int read() { char c = getchar(); int x = 0; bool f = 0; for (; !isdigit(c); c = getchar()) f ^= !(c ^ 45); for (; isdigit(c); c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48); if (f) x = -x; return x; } struct modint { int x; modint(int o = 0) { x ...
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 7; const int mod = 1e9 + 7; int n; mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count() * ((uint64_t) new char | 1)); uniform_int_distribution<int> distr(0.1 * mod, 0.9 * mod); const array<int, 2> base = {distr(rng), distr...
#include <bits/stdc++.h> using namespace std; const int p = 1e9 + 7; char ch[1000012], s[1000012]; int cz[1000012][27], fl[1000012], len[1000012], la, js, n, dp[1000012], dif[1000012], slink[1000012], g[1000012]; void ada(char c, int wh) { int p = la; while (ch[wh - len[p] - 1] != c) p = fl[p]; if (!cz[p][c -...
#include <bits/stdc++.h> const int mxN(1000233), p(1000000007), sta(0), debug(0); int n, str[mxN]; inline void init() { if (sta == 1 || sta == 2) freopen("a.in", "r", stdin); static char s[mxN]; scanf("%s", s); n = strlen(s); if (n & 1) { puts("0"); exit(0); } for (int i = 0, j = n - 1; i < j; ++i...
#include <bits/stdc++.h> using namespace std; inline int read() { int s = 0, w = 1; char ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-') w = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') s = s * 10 + ch - '0', ch = getchar(); return s * w; } const int inf = 2e9 + 7; double eps =...
#include <bits/stdc++.h> using namespace std; template <typename T> inline bool cmax(T& x, T y) { return y > x ? x = y, true : false; } template <typename T> inline bool cmin(T& x, T y) { return y < x ? x = y, true : false; } const int MAXN = 1e6 + 5; const int oo = 0x3f3f3f3f; const int mod = 1e9 + 7; inline int a...
#include <bits/stdc++.h> using namespace std; int in() { int32_t x; scanf("%d", &x); return x; } inline long long lin() { long long x; scanf("%lld", &x); return x; } inline void read(int *a, int n) { for (int i = 0; i < n; i++) a[i] = in(); } inline void readL(int *a, int n) { for (int i = 0; i < n; i++...
#include <bits/stdc++.h> using namespace std; const int N = 1000010, mo = 1000000007; int n; char s[N]; char t[N]; int diff[N]; int anc[N]; int g[N]; int f[N]; struct PAM { int last, tot; struct node { int son[26]; int ff, len; } t[N]; void init() { last = 0; tot = 1; t[1].len = -1; t[0]...
#include <bits/stdc++.h> using namespace std; const int maxn = 1000005, maxk = 27, mod = 1000000007; int n; int f[maxn]; string s, ss; struct Palindrome_AutoMaton { int slen, tot, last; int chd[maxn][maxk], fail[maxn], len[maxn], dif[maxn], slink[maxn], sum[maxn]; string s; int getfail(int x, int i) { while...
#include <bits/stdc++.h> using namespace std; namespace fast_io { char buf[1 << 12], *p1 = buf, *p2 = buf, sr[1 << 23], z[23], nc; int C = -1, Z = 0, Bi = 0, ny; inline char gc() { return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 12, stdin), p1 == p2) ? EOF : *p1++; } inline long lon...
#include <bits/stdc++.h> using namespace std; struct palindromic_tree { int n, act; vector<map<char, int> > list; vector<int> link, slink, diff, len; string s; void add_node() { n++; list.emplace_back(); link.emplace_back(); slink.emplace_back(); diff.emplace_back(); len.emplace_back()...
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; const int maxn = 1e6 + 5; char s[maxn], ss[maxn]; int n; long long f[maxn], ans[maxn]; int len[maxn], fail[maxn], ch[maxn][26], last = 1, tot = 1, fa[maxn], cha[maxn]; int getfail(int x, int i) { while (i - len[x] - 1 < 0 || s[i - len[x] - 1] != s...
#include <bits/stdc++.h> using namespace std; namespace zzc { const int mod = 1e9 + 7; const int maxn = 1e6 + 5; int len[maxn], fail[maxn], g[maxn], f[maxn], slink[maxn], dif[maxn], trans[maxn][26]; int n, tot, lst, le; char ch[maxn], s[maxn]; inline void init() { len[0] = 0; len[1] = -1; fail[0] = 1; fail[...
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 5; char s[N], t[N]; int n; void Init() { scanf("%s", t + 1); n = strlen(t + 1); int l = 1, r = n; int s0 = 0; while (l <= r) { s[++s0] = t[l++]; if (l <= r) s[++s0] = t[r--]; } } const int mo = 1e9 + 7; long long f[N]; struct hwt { ...
#include <bits/stdc++.h> using namespace std; const int INF = 2e9; const long long LINF = 2e16; const int magic = 348; const int MOD = 1e9 + 7; const double eps = 1e-10; const double pi = acos(-1); template <typename T> inline void Get(T &first) { bool f; char ch; T res; while (!isdigit(ch = getchar()) && ch !=...
#include <bits/stdc++.h> using namespace std; template <typename T> inline bool cmin(T& a, const T& b) { return a > b ? a = b, 1 : 0; } template <typename T> inline bool cmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; } int read() { int x = 0, f = 1; char ch; for (ch = getchar(); !isdigit(ch); ch = getc...
#include <bits/stdc++.h> using namespace std; const int MOD = 1000000007; template <typename T> struct modular { constexpr modular() : val(0) {} constexpr modular(const modular<T>& _m) : val(_m.val) {} template <typename U> constexpr modular(const U& _r = U()) { val = -MOD <= _r && _r < MOD ? _r : _r % MOD;...
#include <bits/stdc++.h> inline int fmo(int x) { return x + ((x >> 31) & 1000000007); } int n; char str[1000005], s[1000005]; struct node { int len, dif, f; node *fa, *top, *ch[26]; } t[1000005], *rt = t, *lst = t; int tot; inline node *nw(int len) { node *p = t + (++tot); p->len = len; p->fa = p->top = rt; ...
#include <bits/stdc++.h> #pragma GCC optimize("no-stack-protector") #pragma GCC optimize("-funroll-loops") #pragma GCC target("avx,sse4") using namespace std; const int N = 1000005, P = 1e9 + 7; int S[N], n, fail[N], e[N][26], len[N], ec, last, anc[N], diff[N], m, dp[N], val[N]; char s[N]; inline int newnode(int l)...
#include <bits/stdc++.h> using namespace std; const int inf = 1e9; const long long inf64 = 1e18; const int mod = inf + 7; inline int _sum(int a, int b) { return a + b < mod ? a + b : a + b - mod; } inline int _mul(int a, int b) { return (1ll * a * b) % mod; } inline int _sub(int a, int b) { return a >= b ? a - b : a - ...
#include <bits/stdc++.h> using namespace std; const int maxn = 1000010; const int ALP = 26; struct PAM { int next[maxn][ALP]; int fail[maxn]; int len[maxn]; int s[maxn]; int last; int n; int p; int diff[maxn], anc[maxn]; int newnode(int l) { for (int i = 0; i < ALP; i++) next[p][i] = 0; len[p]...
#include <bits/stdc++.h> using namespace std; long long gi() { long long ret = 0; char ch = getchar(); while ((ch < '0' || ch > '9') && ch != '-') ch = getchar(); char c = ch == '-' ? getchar() : ch; while (c >= '0' && c <= '9') ret = ret * 10 + c - '0', c = getchar(); return ch == '-' ? -ret : ret; } const...
#include <bits/stdc++.h> using namespace std; const int alpha = 26; typedef class TrieNode { public: int len, dif, g; TrieNode *ch[alpha]; TrieNode *fail, *slink; } TrieNode; typedef class PalindromeTree { public: int len; TrieNode *pool; TrieNode *top; TrieNode *odd, *even; TrieNode *last; char *st...
#include <bits/stdc++.h> using namespace std; const int N = 1000003, mod = 1e9 + 7; char str[N], tmp[N]; int n, ch[N][26], fa[N], len[N], f[N], g[N], dif[N], anc[N], lst, cnt; void qmo(int &x) { x += x >> 31 & mod; } void insert(int c, int pos) { int p = lst; while (str[pos] != str[pos - len[p] - 1]) p = fa[p]; i...
#include <bits/stdc++.h> using namespace std; const int MAXN = 1000005; const int CN = 26; int nxt[MAXN][CN]; int fail[MAXN]; int cnt[MAXN]; int num[MAXN]; int len[MAXN]; int s[MAXN]; int diff[MAXN]; int slink[MAXN]; int sans[MAXN]; int last; int n; int p; int newnode(int l) { for (int i = 0; i < CN; ++i) nxt[p][i] =...
#include <bits/stdc++.h> using namespace std; int n, f[1000005], g[1000005]; char S[1000005], T[1000005]; int rt0, rt1, ch[1000005][26]; int cnt = 1, lst, len[1000005], dif[1000005], lnk[1000005], slk[1000005]; void Extend(int p) { int w = lst; while (T[p - len[w] - 1] != T[p]) w = lnk[w]; if (!ch[w][T[p] - 'a'])...
#include <bits/stdc++.h> using namespace std; const int N = 1000005, M = 1e9 + 7; int len[N], fail[N], dp[N], ne[N][26], diff[N], pre[N], tot, last, f[N]; char s1[N], s[N]; inline int getfail(int x, int y) { while (s1[y] != s1[y - len[x] - 1]) x = fail[x]; return x; } inline void insert(int x, int y) { int now = ...
#include <bits/stdc++.h> using namespace std; template <typename T> inline void read(T &x) { x = 0; char c = getchar(); bool flag = false; while (!isdigit(c)) { if (c == '-') flag = true; c = getchar(); } while (isdigit(c)) { x = (x << 1) + (x << 3) + (c ^ 48); c = getchar(); } if (flag)...
#include <bits/stdc++.h> using namespace std; const long long MOD = 1e9 + 7; const double eps = 1e-10; const int INF = 0x3f3f3f3f; const long long INFLL = 0x3f3f3f3f3f3f3f3f; const int MAXN = 1e6 + 5; char s[MAXN]; char str[MAXN]; long long f[MAXN]; long long g[MAXN]; const int N = 26; struct Palindromic_Tree { int n...
#include <bits/stdc++.h> using namespace std; const int maxn = (int)1e6 + 1, maxl = 25, mod = (int)1e9 + 7; int n, m, sta[maxl], dif[maxl], cnt[maxl], f[maxn], g[maxn]; char buf[maxn], str[maxn]; inline void mod_inc(int &x, int y) { (x += y) >= mod && (x -= mod); } int main() { scanf("%s", buf + 1); n = strlen(buf ...
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 10; const int mod = 1e9 + 7; char s[N], t[N], S[N]; int n, go[N][26], len[N], par[N], top, last; int New(int L) { len[++top] = L; return top; } int diff[N], slink[N]; void extend(int n) { int w = S[n], p = last; while (S[n - len[p] - 1] != w) p =...
#include <bits/stdc++.h> using namespace std; inline void Add(int &a, int b) { a += b; a >= 1000000007 ? a -= 1000000007 : 1; } inline void Sub(int a, int b) { a -= b; a < 0 ? a += 1000000007 : 1; } inline int add(int a, int b) { a += b; return a >= 1000000007 ? a - 1000000007 : a; } const int Q = 1 << 20; ...
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; char str[1000005], a[1000005]; int n, lst, ch[1000005][30], s[1000005], fail[1000005], len[1000005], tot, cnt, f[1000005]; int slink[1000005], sum[1000005], diff[1000005], smallen[1000005]; int N(int x) { return len[++cnt] = x, cnt; } void Clear...
#include <bits/stdc++.h> char s[2000005], ss[2000005]; int n, ans[2000005]; int read() { char c = getchar(); int ans = 0; while (c < '0' || c > '9') c = getchar(); while (c >= '0' && c <= '9') ans = ans * 10 + c - '0', c = getchar(); return ans; } void Write(int x) { if (x < 10) putchar(x ^ 48); else ...
#include <bits/stdc++.h> using namespace std; const int LETTER = 26, MOD = 1000000007; int add(int x, int y) { return x + y >= MOD ? x + y - MOD : x + y; } struct PAMNode { int fail, len, go[LETTER], slink, diff; PAMNode(int f = 0, int l = 0) : fail(f), len(l), go{}, slink(0), diff(0) {} }; struct PAM { vector<PA...
#include <bits/stdc++.h> using namespace std; string func(int c4, int c7) { string res; while (c4--) res += '4'; while (c7--) res += '7'; return res; } int main() { string s; while (cin >> s) { int n = s.size(); if (n % 2 == 1) { cout << string((n + 1) / 2, '4') << string((n + 1) / 2, '7') << ...
#include <bits/stdc++.h> using namespace std; int N; long long result = 200000000000; void add(long long x, int d) { if (x < result) { if (d == 0 && x >= N) { result = x; } else { add(x * 10 + 4, d + 1); add(x * 10 + 7, d - 1); } } } int main() { cin >> N; add(4, 1); add(7, -1); ...
#include <bits/stdc++.h> using namespace std; char num[1000010]; int dp[1000010]; int num4[1000010]; int num7[1000010]; int ps4 = 0; bool is = 1; int cao = 0; int hehe = 0; int main() { gets(num); int len = strlen(num); for (int i = len; i >= 1; i--) num[i] = num[i - 1]; if (len % 2) { len++; len /= 2; ...
#include <bits/stdc++.h> using namespace std; const long long int INF = 2e18; const long long int N = 1e6; bool isPrime(long long int n) { if (n <= 1) return false; if (n <= 3) return true; if (n % 2 == 0 || n % 3 == 0) return false; for (long long int i = 5; i * i <= n; i = i + 6) { if (n % i == 0 || n % (...
#include <bits/stdc++.h> using namespace std; const long long MOD = 1e9 + 7; const int N = 1e6 + 20; int n, l0, l; char f[N]; char g[N]; void init() { scanf("%s", &f); n = strlen(f); } bool pd() { for (int i = 0; i < n / 2; i++) if (f[i] != '7') { if (f[i] > '7') return false; return true; } ...
#include <bits/stdc++.h> using namespace std; int flag, n; void f(int a, int b, long long c) { if (flag || a < 0 || a > b) return; if (a == 0 && b == 0 && c >= n) { flag = 1; cout << c << endl; return; } f(a - 1, b - 1, c * 10 + 4); f(a, b - 1, c * 10 + 7); } int main() { cin >> n; int l, t = ...
#include <bits/stdc++.h> using namespace std; const int N = 110000; char txt[N]; int czworki[N], siodemki[N]; int main() { scanf("%s", txt); int n = strlen(txt); if (n % 2 == 1) { for (int i = (n - 1); i >= (0); --i) txt[i + 1] = txt[i]; txt[0] = '0'; n++; txt[n] = 0; } int a = 0, b = 0; for...
#include <bits/stdc++.h> using namespace std; vector<long long> vec; void func(long long x, long long f, long long s) { if (x > 1e10) return; if (f == s) vec.push_back(x); func(x * 10 + 4, f + 1, s); func(x * 10 + 7, f, s + 1); } int main() { func(0, 0, 0); sort(vec.begin(), vec.end()); long long n; cin...
#include <bits/stdc++.h> using namespace std; const double pi = 3.141592653589793238462643383279502884; int arr[8][8]; vector<long long int> v; void solve(long long int x) { if (x > 1e12) return; v.push_back(x + 4), v.push_back(x + 7); solve((x + 4) * 10); solve((x + 7) * 10); } bool check(long long int x) { ...
#include <bits/stdc++.h> using namespace std; #pragma comment(linker, "/STACK:10240000000,10240000000") char str[1000000]; char ans[1000000]; int n; bool dfs(int pos, int num4, int num7, bool flag) { if (pos == n) { ans[n] = '\0'; return true; } else { if (flag) { ans[pos] = '4'; if (num4 > ...
#include <bits/stdc++.h> using namespace std; set<long long> s; void solve(long long i) { s.insert(i); if (i >= 1e9) { return; } solve(i * 10 + 4); solve(i * 10 + 7); } bool can(long long t) { int c = 0, c1 = 0; while (t) { if (t % 10 == 4) c++; else c1++; t /= 10; } if (c ...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; queue<pair<long long, int> > q; q.push(make_pair(4, 1)); q.push(make_pair(7, -1)); pair<long long, int> u; while (!q.empty()) { u = q.front(); q.pop(); if (u.first >= n && u.second == 0) { cout << u.first << endl...
#include <bits/stdc++.h> const int c = 100500; char tmp[c]; int len; int a[c]; int b[c]; int c4, c7; bool w; int main() { gets(tmp); len = strlen(tmp); int i, j, k; for (i = 0; i < len; ++i) a[i] = tmp[i] - '0'; if (len & 1) { len++; for (i = len - 1; i >= 1; --i) a[i] = a[i - 1]; a[0] = 0; } ...
#include <bits/stdc++.h> using namespace std; string a; string b; int t; int main() { cin >> a; t = a.size(); int x = t / 2; while (x--) b += '7'; x = t / 2; while (x--) b += '4'; if (t % 2) { reverse(b.begin(), b.end()); cout << "4" << b << "7"; return 0; } int update = 0; for (int i = ...
#include <bits/stdc++.h> using namespace std; const int MAX = 100001; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long int 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; string ss, st; cin >> ss; st = ss; stringstream qq; qq << st; qq...
#include <bits/stdc++.h> using namespace std; char s[100005]; char ans[100005]; int len; bool dfs(int pos, int n4, int n7, bool tag) { if (pos >= len) return true; if (tag) { for (int i = 0; i < n4; i++) ans[i + pos] = '4'; for (int i = 0; i < n7; i++) ans[i + pos + n4] = '7'; return true; } if (s[p...
#include <bits/stdc++.h> using namespace std; char str[15]; int tot; long long num[10000]; void dfs(long long n, int n4, int n7) { if ((n4 + n7) % 2 == 0 && n4 == n7 && n4 > 0 && n7 > 0) { num[++tot] = n; } if (n4 + n7 < 10) { dfs(n * 10 + 4, n4 + 1, n7); dfs(n * 10 + 7, n4, n7 + 1); } } int main() ...
#include <bits/stdc++.h> using namespace std; vector<long long> ourLuckyNumbers; long long n; void genPossibleValues(long long value, int numberSevens, int numberFours) { if (value > 10000000000LL) { return; } if (numberFours == numberSevens) { ourLuckyNumbers.push_back(value); } genPossibleValues(val...
#include <bits/stdc++.h> using namespace std; int main() { int i = 0, n; cin >> n; long long arr[] = { 47, 74, 4477, 4747, 4774, 7447, 7474, 7744, 444777, 447477, 447747, 447774, 474477, 474747, 474774, 477447, 477474, 477744, 744477, 744747...
#include <bits/stdc++.h> using namespace std; const int maxn = 1000000 + 5; char ans[maxn]; char s[maxn]; int len; bool dfs(int pos, int n4, int n7, int flag) { int i; if (pos >= len) return true; if (flag) { for (i = n4 - 1; i >= 0; i--) ans[i + pos] = '4'; for (i = n7 - 1; i >= 0; i--) ans[i + n4 + pos]...
#include <bits/stdc++.h> using namespace std; char second[1000010], res[1000010]; int n; bool flag; void sol(int p, int fst, int sed, bool e) { if (p == n) { flag = true; res[n] = '\0'; return; } if (e) { int i; for (i = p; fst * 2 < n; i++, fst++) res[i] = '4'; for (; i < n; i++) res[i] =...
#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; const int N = 100005; char str[N]; char ans[N]; int main() { scanf("%s", str); int len = strlen(str); if (len % 2) { len++; for (int i = 0; i < len / 2; i++) str[i] = '4'; for (int i = len / 2; i < len; i++) str[i] = '7'; str[len] = 0; cout << str ...
#include <bits/stdc++.h> using namespace std; string n; char ans[100005]; int four; int seven; bool vec; bool danger; void dfs(int x) { if (vec == true) return; if (four == seven && x == (int)n.length()) { vec = true; return; } if (x == (int)n.length()) return; if (danger == true) { if (n[x] > '7'...
#include <bits/stdc++.h> using namespace std; char s[100]; int main() { int N; scanf("%d", &N); sprintf(s, "%d", N); int C = strlen(s); if (C % 2) C++; long long A; long long ret = 1e12; for (int i = 0; i < (1 << C); i++) { string h; int a = 0, b = 0; for (int j = 0; j < C; j++) { if (...
#include <bits/stdc++.h> using namespace std; char ch[100010]; int len, cnt = 0; char temp[100010]; void out(int len) { for (int i = 0; i < len; i++) printf("4"); for (int i = 0; i < len; i++) printf("7"); puts(""); } bool dfs(int p, int a, int b, int yes) { if (p == 2 * len) { temp[p] = 0; return true;...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); ; long long int k, i, j, n, x, sze; cin >> n; string s, t, r, ans, ch; s = to_string(n); sze = s.size(); r = s; for (i = 1; i <= sze; i++) { if (i <= (sze / 2)) { t += '4'; ...
#include <bits/stdc++.h> using namespace std; string s, ans; long n, i, res; long n4, n7, j; bool ok, flag; char ch; string t, mp; int main() { cin >> s; n = s.size(); if (s.size() % 2) { for (i = 0; i <= (s.size() / 2); i++) cout << "4"; for (i = 0; i <= (s.size() / 2); i++) cout << "7"; return 0; ...
#include <bits/stdc++.h> using namespace std; void print(int n) { for (int i = 0; i < n / 2; ++i) cout << 4; for (int i = n / 2; i < n; ++i) cout << 7; } int main() { string a; cin >> a; if (a.size() % 2) print(a.size() + 1); else { string ans; int i, cnt4 = 0, cnt7 = 0; vector<int> p; f...
#include <bits/stdc++.h> using namespace std; int N; vector<long long> lucky; void solve(int i, int n, int number, int four, int seven) { if (four < 0 || seven < 0) return; if (i == n) { lucky.push_back(number); return; } for (int j = 0; j < 2; j++) solve(i + 1, n, number * 10 + (j == 0 ? 4 : 7), j ...
#include <bits/stdc++.h> using namespace std; const long long M = 1e12; set<long long> s; void generate_lucky(long long nr, int balance) { if (nr > M) return; if (balance == 0) s.insert(nr); generate_lucky(10 * nr + 4, balance + 1); generate_lucky(10 * nr + 7, balance - 1); } int main() { std::ios::sync_with_...
#include <bits/stdc++.h> using namespace std; void printopt(int p) { for (int i = p / 2; i; i--) printf("4"); for (int i = p / 2; i; i--) printf("7"); } char s[100000 + 2]; char s47[100000 + 2]; int n; bool fopt(int i, int ddif47) { if (abs(ddif47) > n - i) return 0; int j = i; for (; j < i + (n - i - ddif47)...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); ; long long a; cin >> a; queue<pair<long long, long long>> q; q.push(make_pair(0, 0)); while (!q.empty()) { long long d, c; d = q.front().first; c = q.front().second; q.pop(); ...
#include <bits/stdc++.h> using namespace std; char s[100010]; int n; bool v[100010]; char a[100010]; int t = 0; void tle() { while (1) ; } bool ff() { for (int i = 0; i < t / 2; i++) if (a[i] < '7') return 1; for (int i = t / 2; i < t; i++) if (a[i] > '4') return 0; return 1; } int main() { scanf(...
#include <bits/stdc++.h> using namespace std; int len; char ans[100001], s[100001]; inline bool judge(int pos, int flag, int sev, int four) { if (pos >= len) return 1; if (flag) { for (register int i = 0; i < four; ++i) ans[i + pos] = '4'; for (register int i = four + pos; i < len; ++i) ans[i] = '7'; re...
#include <bits/stdc++.h> using namespace std; int main() { std::vector<long long int> v; v = {47, 74, 4477, 4747, 4774, 7447, 7474, 7744, 444777, 447477, 447747, 447774, 474477, 474747, 474774, 477447, 477474, 477744, 744477, 744747, 744774, ...
#include <bits/stdc++.h> using namespace std; const int OO = (int)2e9; const double eps = 1e-9; int main() { std::ios_base::sync_with_stdio(false); string str; cin >> str; int i, n = ((int)(str).size()), k = (n + 1) / 2, a4 = 0, a7 = 0, rem = 0; string tmp = string(k, '7') + string(k, '4'); if ((n & 1) || (...
#include <bits/stdc++.h> using namespace std; int main() { vector<long long> numbers{47, 74, 4477, 4747, 4774, 7447, 7474, 7744}; for (int i = 0; i < 4; i++) { for (int j = i + 1; j < 5; j++) { for (int k = j + 1; k < 6; k++) { string s = ""; for (int l = 0; l < 6; l++) { if ((l ...
#include <bits/stdc++.h> using namespace std; int s4[100002], s7[100002]; int o4[100002], o7[100002]; void print(int n) { string ans = ""; for (int i = 0; i < n / 2; i++) { ans += '4'; } for (int i = 0; i < n / 2; i++) { ans += '7'; } cout << ans << "\n"; } int poss(string s) { int n = s.size(); ...
#include <bits/stdc++.h> using namespace std; int main() { string n; cin >> n; int len = n.length(); string n_max(len, '?'); for (int i = 0; i < (len); i++) n_max[i] = (i < len / 2 ? '7' : '4'); if (len % 2 == 1 || (len % 2 == 0 && n > n_max)) { cout << string(len / 2 + 1, '4') << string(len / 2 + 1, '7...
#include <bits/stdc++.h> using namespace std; char num[100005], ans[100005]; int main() { scanf("%s", num); int a = 0, b = 0, n, c, pos, poss; bool k = false, f = false; int kk = 0; n = strlen(num); c = n / 2; if (n % 2 == 0) { for (int i = 0; i < n; i++) { if (i < n / 2) { if (num[i] > ...
#include <bits/stdc++.h> using namespace std; char s[1000005]; int dp[1000005]; int main() { int a, b; while (~scanf("%s", s)) { int fl = 1; int k = strlen(s); if (k % 2 == 1) { fl = 0; for (int i = 0; i <= k / 2; i++) printf("4"); for (int i = 0; i <= k / 2; i++) printf("7"); } el...
#include <bits/stdc++.h> using namespace std; int len7, len4, cnt7[1000000], cnt4[1000000]; char second[10000000]; void print() { for (int i = 0; i < len4; ++i) putchar('4'); for (int i = 0; i < len7; ++i) putchar('7'); exit(0); } int main() { gets(second); int len = strlen(second); len7 = (len + 1) / 2; ...
#include <bits/stdc++.h> using namespace std; template <class T> void check_max(T& a, T b) { if (a < b) a = b; } template <class T> void check_min(T& a, T b) { if (a > b) a = b; } const int MAXL = 100000 + 10; char d[MAXL]; int l; int main() { scanf("%s", d); l = strlen(d); if (l % 2 == 1) { l++; for ...
#include <bits/stdc++.h> using namespace std; const int inf = 100005; int len; char num[inf], ans[inf]; bool dfs(int pos, int a, int b, int k) { if (pos >= len) return 1; if (k) { int i; for (i = 0; i < a; i++) { ans[i + pos] = '4'; } for (; i < len; i++) { ans[i + pos] = '7'; } ...
#include <bits/stdc++.h> using namespace std; char a[1100000]; int b[1100000]; int main() { scanf("%s", a); int l = strlen(a); if (l & 1) { l /= 2; l++; for (int i = 0; i < l; i++) printf("4"); for (int i = 0; i < l; i++) printf("7"); printf("\n"); return 0; } int p = -1; int q = -1;...
#include <bits/stdc++.h> using namespace std; int main() { long long int n; vector<long long int> v; string s; long long int m = 47, k; s = to_string(m); stringstream geek(s); geek >> k; v.push_back(k); while (s.size() <= 10) { if (next_permutation(s.begin(), s.end())) { stringstream geek(s)...
#include <bits/stdc++.h> using namespace std; long long n, k, d; bool check(long long x) { string y = to_string(x); long long z = 0, z1 = 0; for (long long i = 0; i < y.size(); i++) { if (y[i] != '4' && y[i] != '7') return false; else if (y[i] == '4') z++; else z1++; } if (z == z...
#include <bits/stdc++.h> using namespace std; long long n, s; void dfs(long long x, long long s4, long long s7) { if (n <= x && (x < s || s == 0) && s4 == s7) 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 <= 47) s ...
#include <bits/stdc++.h> using namespace std; long long int x, x2 = 1, e = 0, ans = 100000000000; void mnum(int i, long long int t, int x4, int x7) { if (i == e) { if (t < ans && t >= x && x4 == x7) ans = t; return; } long long int v = 1; for (int z = 1; z <= i; z++) v *= 10; mnum(i + 1, t + (v * 4), ...
#include <bits/stdc++.h> using namespace std; template <typename T, typename T1> T amax(T &a, T1 b) { if (b > a) a = b; return a; } template <typename T, typename T1> T amin(T &a, T1 b) { if (b < a) a = b; return a; } bool isPrime(long long x) { if (x == 1) return false; for (long long i = 2; i * i <= x; i+...
#include <bits/stdc++.h> using namespace std; template <class T> inline T lowbit(T n) { return (n ^ (n - 1)) & n; } template <class T> inline int countbit(T n) { return (n == 0) ? 0 : (1 + countbit(n & (n - 1))); } template <class T> T gcd(T a, T b) { return b == 0 ? a : gcd(b, a % b); } template <typename T> T l...
#include <bits/stdc++.h> using namespace std; using ll = long long; using vll = vector<ll>; int solve() { string t; cin >> t; ll a = 0, flag = 1, r = 0, b = 0; vector<int> data(t.size()); if (t.size() % 2 == 1) flag = 0; vector<ll> s; for (ll j = 0; j < t.size(); j++) { if (t[j] - 0 == 52) { dat...
#include <bits/stdc++.h> using namespace std; const int nmax = 100100; char s[nmax]; char t[nmax]; int n; void madeTemplate(int pos, int c4, int c7) { if (pos < 0) { while (true) ; } t[pos + c4 + c7] = 0; while (c4) { t[pos] = '4'; ++pos; --c4; } while (c7) { t[pos] = '7'; ++po...