{"problem":{"name":"B. Lucky Numbers (easy)","description":{"content":"Petya loves lucky numbers. Everybody knows that positive integers are lucky if their decimal representation doesn't contain digits other than 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, ","description_type":"Markdown"},"platform":"Codeforces","limit":{"time_limit":2000,"memory_limit":262144},"difficulty":"None","is_remote":true,"is_sync":true,"sync_url":null,"sign":"CF96B"},"statements":[{"statement_type":"Markdown","content":"Petya loves lucky numbers. Everybody knows that positive integers are lucky if their decimal representation doesn't contain digits other than 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.\n\nLucky number is super lucky if it's decimal representation contains equal amount of digits 4 and 7. For example, numbers 47, 7744, 474477 are super lucky and 4, 744, 467 are not.\n\nOne day Petya came across a positive integer _n_. Help him to find the least super lucky number which is not less than _n_.\n\n## Input\n\nThe only line contains a positive integer _n_ (1 ≤ _n_ ≤ 109). This number doesn't have leading zeroes.\n\n## Output\n\nOutput the least super lucky number that is more than or equal to _n_.\n\nPlease, do not use the %lld specificator to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specificator.\n\n[samples]","is_translate":false,"language":"English"},{"statement_type":"Markdown","content":"Petya 喜欢幸运数字。众所周知，正整数如果其十进制表示中不包含除 #cf_span[4] 和 #cf_span[7] 以外的数字，则被称为 #cf_span(class=[tex-font-style-underline], body=[lucky])。例如，数字 #cf_span[47]、#cf_span[744]、#cf_span[4] 是幸运的，而 #cf_span[5]、#cf_span[17]、#cf_span[467] 则不是。\n\n如果一个幸运数的十进制表示中包含相等数量的数字 #cf_span[4] 和 #cf_span[7]，则称其为 #cf_span(class=[tex-font-style-underline], body=[super lucky])。例如，数字 #cf_span[47]、#cf_span[7744]、#cf_span[474477] 是超级幸运的，而 #cf_span[4]、#cf_span[744]、#cf_span[467] 则不是。\n\n一天，Petya 遇到了一个正整数 #cf_span[n]。请帮他找出不小于 #cf_span[n] 的最小超级幸运数。\n\n输入仅包含一行，一个正整数 #cf_span[n]（#cf_span[1 ≤ n ≤ 109]）。该数不包含前导零。\n\n请输出不小于 #cf_span[n] 的最小超级幸运数。\n\n请注意，在 C++ 中不要使用 %lld 特定格式符来读写 64 位整数。推荐使用 cin、cout 流，或使用 %I64d 特定格式符。\n\n## Input\n\n输入仅包含一行，一个正整数 #cf_span[n]（#cf_span[1 ≤ n ≤ 109]）。该数不包含前导零。\n\n## Output\n\n请输出不小于 #cf_span[n] 的最小超级幸运数。请注意，在 C++ 中不要使用 %lld 特定格式符来读写 64 位整数。推荐使用 cin、cout 流，或使用 %I64d 特定格式符。\n\n[samples]","is_translate":true,"language":"Chinese"},{"statement_type":"Markdown","content":"**Definitions**  \nLet $ S $ be the set of *super lucky* numbers:  \n$$ S = \\left\\{ m \\in \\mathbb{Z}^+ \\mid \\text{decimal representation of } m \\text{ contains only digits } 4 \\text{ and } 7, \\text{ and } \\#_4(m) = \\#_7(m) \\right\\} $$  \nwhere $ \\#_d(m) $ denotes the count of digit $ d $ in the decimal representation of $ m $.\n\n**Constraints**  \nGiven $ n \\in \\mathbb{Z}^+ $ such that $ 1 \\leq n \\leq 10^9 $.\n\n**Objective**  \nFind the minimum $ m \\in S $ such that $ m \\geq n $.","is_translate":false,"language":"Formal"}],"meta":{"iden":"CF96B","tags":["binary search","bitmasks","brute force"],"sample_group":[["4500","4747"],["47","47"]],"created_at":"2026-03-03 11:00:39"}}