{"problem":{"name":"B. Maximize Sum of Digits","description":{"content":"Anton has the integer _x_. He is interested what positive integer, which doesn't exceed _x_, has the maximum sum of digits. Your task is to help Anton and to find the integer that interests him. If t","description_type":"Markdown"},"platform":"Codeforces","limit":{"time_limit":1000,"memory_limit":262144},"difficulty":"None","is_remote":true,"is_sync":true,"sync_url":null,"sign":"CF770B"},"statements":[{"statement_type":"Markdown","content":"Anton has the integer _x_. He is interested what positive integer, which doesn't exceed _x_, has the maximum sum of digits.\n\nYour task is to help Anton and to find the integer that interests him. If there are several such integers, determine the biggest of them.\n\n## Input\n\nThe first line contains the positive integer _x_ (1 ≤ _x_ ≤ 1018) — the integer which Anton has.\n\n## Output\n\nPrint the positive integer which doesn't exceed _x_ and has the maximum sum of digits. If there are several such integers, print the biggest of them. Printed integer must not contain leading zeros.\n\n[samples]","is_translate":false,"language":"English"},{"statement_type":"Markdown","content":"Anton 有一个整数 #cf_span[x]。他想知道一个不超过 #cf_span[x] 的正整数，其各位数字之和最大。\n\n你的任务是帮助 Anton 找到这个整数。如果有多个这样的整数，请找出其中最大的一个。\n\n第一行包含一个正整数 #cf_span[x]（#cf_span[1 ≤ x ≤ 1018]）——Anton 拥有的整数。\n\n请输出一个不超过 #cf_span[x] 且各位数字之和最大的正整数。如果有多个这样的整数，请输出其中最大的一个。输出的整数不能包含前导零。\n\n## Input\n\n第一行包含一个正整数 #cf_span[x]（#cf_span[1 ≤ x ≤ 1018]）——Anton 拥有的整数。 \n\n## Output\n\n请输出一个不超过 #cf_span[x] 且各位数字之和最大的正整数。如果有多个这样的整数，请输出其中最大的一个。输出的整数不能包含前导零。\n\n[samples]","is_translate":true,"language":"Chinese"},{"statement_type":"Markdown","content":"**Definitions**  \nLet $ x \\in \\mathbb{Z} $ with $ 1 \\leq x \\leq 10^{18} $.  \nLet $ S(n) = \\sum_{i=0}^{k} d_i $ denote the sum of digits of a positive integer $ n $, where $ n = \\sum_{i=0}^{k} d_i \\cdot 10^i $ and $ d_i \\in \\{0,1,\\dots,9\\} $, $ d_k \\neq 0 $.  \n\n**Constraints**  \nFind $ n \\in \\mathbb{Z} $ such that:  \n1. $ 1 \\leq n \\leq x $  \n2. $ S(n) $ is maximized over all such $ n $  \n3. If multiple $ n $ achieve the maximum $ S(n) $, choose the largest such $ n $  \n\n**Objective**  \nDetermine $ \\max \\left\\{ n \\in \\mathbb{Z} \\mid 1 \\leq n \\leq x \\text{ and } S(n) = \\max_{1 \\leq m \\leq x} S(m) \\right\\} $","is_translate":false,"language":"Formal"}],"meta":{"iden":"CF770B","tags":["implementation","math"],"sample_group":[["100","99"],["48","48"],["521","499"]],"created_at":"2026-03-03 11:00:39"}}