{"raw_statement":[{"iden":"statement","content":"Maxim wants to buy an apartment in a new house at Line Avenue of Metropolis. The house has _n_ apartments that are numbered from 1 to _n_ and are arranged in a row. Two apartments are adjacent if their indices differ by 1. Some of the apartments can already be inhabited, others are available for sale.\n\nMaxim often visits his neighbors, so apartment is _good_ for him if it is available for sale and there is at least one already inhabited apartment adjacent to it. Maxim knows that there are exactly _k_ already inhabited apartments, but he doesn't know their indices yet.\n\nFind out what could be the minimum possible and the maximum possible number of apartments that are good for Maxim."},{"iden":"input","content":"The only line of the input contains two integers: _n_ and _k_ (1 ≤ _n_ ≤ 109, 0 ≤ _k_ ≤ _n_)."},{"iden":"output","content":"Print the minimum possible and the maximum possible number of apartments good for Maxim."},{"iden":"example","content":"Input\n\n6 3\n\nOutput\n\n1 3"},{"iden":"note","content":"In the sample test, the number of good apartments could be minimum possible if, for example, apartments with indices 1, 2 and 3 were inhabited. In this case only apartment 4 is good. The maximum possible number could be, for example, if apartments with indices 1, 3 and 5 were inhabited. In this case all other apartments: 2, 4 and 6 are good."}],"translated_statement":[{"iden":"statement","content":"Maxim 想要在 Metropolis 的 Line Avenue 的一栋新楼中购买一套公寓。这栋楼有 #cf_span[n] 套公寓，编号从 #cf_span[1] 到 #cf_span[n]，呈一行排列。如果两套公寓的编号相差 #cf_span[1]，则称它们相邻。有些公寓已经有人居住，其余的可供出售。\n\nMaxim 经常拜访他的邻居，因此一套公寓对他来说是 _good_ 的，当且仅当它可供出售，且至少有一套相邻的公寓已被占用。Maxim 知道恰好有 #cf_span[k] 套公寓已被占用，但他还不知道它们的编号。\n\n请找出对 Maxim 来说可能的最少和最多的好公寓数量。\n\n输入仅有一行，包含两个整数：#cf_span[n] 和 #cf_span[k]（#cf_span[1 ≤ n ≤ 109]，#cf_span[0 ≤ k ≤ n]）。\n\n请输出对 Maxim 来说可能的最少和最多的好公寓数量。\n\n在样例测试中，好公寓的数量可能最少的情况是，例如，编号为 #cf_span[1]、#cf_span[2] 和 #cf_span[3] 的公寓已被占用。此时只有公寓 #cf_span[4] 是好的。好公寓数量可能最多的情况是，例如，编号为 #cf_span[1]、#cf_span[3] 和 #cf_span[5] 的公寓已被占用。此时所有其他公寓：#cf_span[2]、#cf_span[4] 和 #cf_span[6] 都是好的。"},{"iden":"input","content":"输入仅有一行，包含两个整数：#cf_span[n] 和 #cf_span[k]（#cf_span[1 ≤ n ≤ 109]，#cf_span[0 ≤ k ≤ n]）。"},{"iden":"output","content":"请输出对 Maxim 来说可能的最少和最多的好公寓数量。"},{"iden":"note","content":"在样例测试中，好公寓的数量可能最少的情况是，例如，编号为 #cf_span[1]、#cf_span[2] 和 #cf_span[3] 的公寓已被占用。此时只有公寓 #cf_span[4] 是好的。好公寓数量可能最多的情况是，例如，编号为 #cf_span[1]、#cf_span[3] 和 #cf_span[5] 的公寓已被占用。此时所有其他公寓：#cf_span[2]、#cf_span[4] 和 #cf_span[6] 都是好的。"}],"sample_group":[],"show_order":[],"formal_statement":"Let $ n $ be the total number of apartments, numbered $ 1 $ to $ n $, arranged in a row. Let $ k $ be the number of already inhabited apartments ($ 0 \\leq k \\leq n $).\n\nAn apartment is *good* if:\n- It is **available** for sale (i.e., not inhabited),\n- And it has **at least one adjacent** apartment that is inhabited.\n\n---\n\n### Definitions:\n\nLet $ H \\subseteq \\{1, 2, \\dots, n\\} $ be the set of inhabited apartments, with $ |H| = k $.\n\nLet $ G(H) $ be the set of good apartments given $ H $.\n\nWe seek:\n- $ \\min_{|H| = k} |G(H)| $\n- $ \\max_{|H| = k} |G(H)| $\n\n---\n\n### Constraints:\n\n- Apartments at positions $ 1 $ and $ n $ have only one neighbor each.\n- Apartments $ 2 $ to $ n-1 $ have two neighbors.\n- A good apartment must be **uninhabited** and adjacent to **at least one** inhabited apartment.\n\n---\n\n## Minimum Number of Good Apartments\n\nTo **minimize** the number of good apartments, cluster the $ k $ inhabited apartments together in a single contiguous block.\n\n- If $ k = 0 $: No inhabited apartments → 0 good apartments.\n- If $ k = n $: No available apartments → 0 good apartments.\n- Otherwise, place all $ k $ inhabited apartments consecutively, say from position $ a $ to $ a+k-1 $.\n\nThen, the only available apartments adjacent to inhabited ones are:\n- The one immediately before the block (if $ a > 1 $),\n- The one immediately after the block (if $ a+k-1 < n $).\n\nThus, maximum 2 good apartments.\n\nBut if the block touches an end (e.g., starts at 1 or ends at $ n $), then only one side is adjacent.\n\nSo:\n- If the block is placed at one end (e.g., apartments $ 1 $ to $ k $), then only apartment $ k+1 $ is good (if $ k < n $).\n- Similarly, if placed at the other end, only $ n-k $ is good.\n\nHence, **minimum** number of good apartments is:\n\n$$\n\\min_{|H|=k} |G(H)| = \n\\begin{cases}\n0 & \\text{if } k = 0 \\text{ or } k = n \\\\\n1 & \\text{if } 1 \\leq k \\leq n-1 \\text{ and the block is placed at an end} \\\\\n\\end{cases}\n$$\n\nBut even if we place the block in the middle, we get 2 good apartments. To **minimize**, we place it at the end → only 1 good apartment.\n\n**However**, if $ k = 1 $ and $ n = 1 $, then $ k = n $ → 0.\n\nSo general formula:\n\n- If $ k = 0 $ or $ k = n $: **0**\n- Else: **1** (achieved by placing the block at one end)\n\n> **But wait**: What if $ k = 1 $ and $ n = 2 $? Then the single inhabited apartment has one neighbor — which is available → 1 good apartment. Still 1.\n\n> What if $ k = 2 $, $ n = 3 $? Inhabited: [1,2] → good: [3]. Or [2,3] → good: [1]. Still 1.\n\n> What if $ k = 2 $, $ n = 4 $? Inhabited: [1,2] → good: [3]. Only one.\n\nSo yes — **minimum is always 0 if k=0 or k=n, else 1**.\n\nWait — what if $ k = n-1 $? Then only one apartment is available. It must be adjacent to at least one inhabited one (since only one is missing, and the rest are filled). So the single available apartment is adjacent to at least one inhabited → 1 good apartment.\n\nSo **minimum is always 1 when $ 1 \\leq k \\leq n-1 $**.\n\n✅ **Minimum = $ \\max(0, \\min(2, k)) $**? No.\n\nActually: **Minimum = 0 if k=0 or k=n, else 1**\n\n---\n\n## Maximum Number of Good Apartments\n\nTo **maximize** the number of good apartments, we want to **maximize the number of available apartments that are adjacent to at least one inhabited apartment**.\n\nEach inhabited apartment can \"cover\" up to 2 adjacent available apartments (left and right), **but**:\n- If two inhabited apartments are adjacent, the space between them is not available → no gain.\n- If they are separated by at least one available apartment, then each can cover their own neighbors.\n\nTo maximize coverage, **space out the inhabited apartments** so that no two are adjacent.\n\nThat is, place inhabited apartments with **at least one gap** between them.\n\nIn this case, each inhabited apartment can contribute **two** good apartments — unless it is at the boundary.\n\nBut if we place them with exactly one gap between them (i.e., pattern: I - I - I - ...), then:\n\n- Each inhabited apartment (except possibly at ends) has two neighbors, both available → contributes 2 good apartments.\n- But the available apartments between them are shared? No — if we have:\n\nPositions: I - I - I\n\nThen apartments: 1 (I), 2 (available), 3 (I), 4 (available), 5 (I)\n\nGood apartments: 2, 4 → only 2 good apartments for 3 inhabited.\n\nWait — apartment 2 is adjacent to 1 and 3 → both inhabited → still only counted once.\n\nApartment 4 is adjacent to 3 and 5 → both inhabited → still one apartment.\n\nSo each **gap** between two inhabited apartments (i.e., a single available apartment between two inhabited) becomes **one good apartment**.\n\nAlso, if an inhabited apartment is at the end, it can make its single neighbor good.\n\nSo if we place $ k $ inhabited apartments with **at least one gap** between each pair, then:\n\n- Number of gaps between inhabited apartments: $ k - 1 $\n- Each such gap is a single available apartment between two inhabited → contributes 1 good apartment.\n- Additionally, if the first inhabited is not at position 1, then position 1 is available and adjacent to the first inhabited → good.\n- Similarly, if the last inhabited is not at position $ n $, then position $ n $ is good.\n\nSo total good apartments = \n- $ k - 1 $ (gaps between inhabited)\n- + 1 if the first inhabited is not at 1\n- + 1 if the last inhabited is not at n\n\nTo **maximize**, we want to **maximize the number of available apartments adjacent to inhabited ones**, so we should **minimize overlap** of coverage.\n\nBest strategy: **place inhabited apartments as isolated as possible**, i.e., with **exactly one available apartment between them**, and **not touching the ends** if possible.\n\nBut we can also choose to **place them at the ends** to get extra coverage.\n\nActually, the optimal configuration is to **space them with single gaps**, and **extend as far as possible**.\n\nLet’s think differently.\n\nEach inhabited apartment can \"cover\" up to 2 available neighbors.\n\nBut if two inhabited apartments are adjacent, they share a boundary and cover fewer total available apartments.\n\nTo maximize total good apartments, we want **no two inhabited apartments adjacent**, and we want to **avoid placing them at the ends**? No — actually, placing at ends gives **one** good neighbor each, same as internal ones give two.\n\nWait — if an inhabited apartment is at position 1, it can only cover position 2.\n\nIf it’s at position 2, it can cover 1 and 3.\n\nSo **internal** inhabited apartments can cover **two** good apartments; **end** ones cover **one**.\n\nSo to maximize, we should **avoid placing inhabited apartments at the ends**, so that each can cover two neighbors.\n\nBut we have only $ k $ inhabited apartments.\n\nSuppose we place all $ k $ inhabited apartments in the interior, each separated by at least one available apartment.\n\nThen, each inhabited apartment contributes 2 good apartments → total $ 2k $.\n\nBut can we do that?\n\nWe need to place $ k $ inhabited apartments with **at least one gap** between them.\n\nMinimum space required: each inhabited apartment takes 1 spot, and between each pair, we need 1 gap → total length = $ k + (k - 1) = 2k - 1 $\n\nSo if $ 2k - 1 \\leq n $, we can place them all internally with gaps → each contributes 2 good apartments → total good apartments = $ 2k $\n\nBut if $ 2k - 1 > n $, then we cannot space them all with gaps → some must be adjacent.\n\nBut also, if we place them at the ends, we get less coverage.\n\nWait — here's a better way.\n\nIn the optimal configuration for **maximum** good apartments:\n\n- Place inhabited apartments with **exactly one available apartment between each pair**.\n- Place the first inhabited apartment at position 2, then 4, 6, ..., so that they are not at the ends.\n\nThen:\n- Each inhabited apartment is surrounded by two available apartments → contributes 2 good apartments.\n- The available apartments at the ends (1 and n) are not adjacent to any inhabited → not good.\n\nBut if we shift the entire block to the left, putting the first inhabited at position 1, then we lose one good apartment (no left neighbor), but we might be able to fit more?\n\nActually, the maximum number of good apartments is bounded by the number of available apartments that are adjacent to at least one inhabited.\n\nEach inhabited apartment can be adjacent to at most 2 available apartments.\n\nBut if two inhabited apartments are adjacent, they share a boundary — the apartment between them is inhabited, so no good apartment there.\n\nSo the **maximum** number of good apartments is achieved when **no two inhabited apartments are adjacent**, and **we use as many available apartments as possible as neighbors**.\n\nIn that case, each inhabited apartment contributes **2** good apartments, **except** if it is at the end.\n\nSo to maximize, we want **no inhabited apartment at the ends** → then all $ k $ inhabited apartments are internal and each contributes 2 → total $ 2k $\n\nBut we can only do that if the total length required is $ \\leq n $\n\nTo place $ k $ non-adjacent inhabited apartments, we need at least $ k $ positions for them and $ k-1 $ gaps between them → total $ 2k - 1 $\n\nSo if $ 2k - 1 \\leq n $, then we can place them all internally (e.g., positions 2, 4, ..., 2k) → then the good apartments are positions 1, 3, 5, ..., 2k+1 — but wait, position 1 is adjacent to 2 → good, position 3 is adjacent to 2 and 4 → good, etc.\n\nActually, if we place inhabited at positions $ 2, 4, 6, \\dots, 2k $, then:\n\n- Good apartments: 1 (adj to 2), 3 (adj to 2 and 4), 5 (adj to 4 and 6), ..., $ 2k - 1 $, and $ 2k + 1 $ (if $ 2k + 1 \\leq n $)\n\nBut we only have $ k $ inhabited apartments → the good ones are:\n\n- Left of first: 1\n- Between each pair: 3,5,..., up to $ 2k-1 $ → $ k-1 $ of them\n- Right of last: $ 2k+1 $\n\nSo total good apartments = $ 1 + (k - 1) + 1 = k + 1 $\n\nWait — this contradicts.\n\nAlternative approach:\n\nLet’s model the maximum number of good apartments as the number of available apartments that are adjacent to at least one inhabited.\n\nLet $ A $ be the set of available apartments.\n\nEach inhabited apartment can \"cover\" its left and right neighbors, if they are available.\n\nThe total number of \"adjacent pairs\" between inhabited and available is at most $ 2k $, but each good apartment is counted once, even if adjacent to two inhabited.\n\nSo the maximum number of good apartments is **min(n - k, 2k)**\n\nWhy?\n\n- There are $ n - k $ available apartments → can't have more than that many good apartments.\n- Each inhabited apartment can contribute to at most 2 good apartments → total coverage capacity is $ 2k $\n- So total good apartments ≤ $ \\min(n - k, 2k) $\n\nAnd this bound is **achievable**:\n\n- If $ 2k \\leq n - k $ → $ 3k \\leq n $, then we can place $ k $ inhabited apartments, each separated by at least two available apartments → each inhabited apartment has two available neighbors, and no overlap → total good = $ 2k $\n- If $ 2k > n - k $ → $ 3k > n $, then we have more coverage capacity than available apartments → we can make **all** available apartments good → total = $ n - k $\n\nSo:\n\n✅ **Maximum = $ \\min(n - k, 2k) $**\n\nBut wait — what if $ k = 0 $? Then $ \\min(n, 0) = 0 $ → correct.\n\nWhat if $ k = n $? Then $ \\min(0, 2n) = 0 $ → correct.\n\nWhat if $ n = 6, k = 3 $: $ \\min(3, 6) = 3 $\n\nCan we get 3 good apartments? Yes — e.g., inhabit 1,3,5 → good: 2,4,6 → 3 good → matches.\n\nIf $ n = 5, k = 3 $: $ \\min(2, 6) = 2 $\n\nCan we get 2 good? Inhabit 1,3,5 → available: 2,4 → both adjacent to inhabited → 2 good → yes.\n\nIf $ n = 4, k = 2 $: $ \\min(2, 4) = 2 $\n\nInhabit 1 and 4 → good: 2 and 3 → 2 good → yes.\n\nInhabit 2 and 3 → adjacent → good: 1 and 4 → still 2.\n\nSo yes.\n\n✅ So maximum = $ \\min(n - k, 2k) $\n\n---\n\n## Final Answer:\n\n$$\n\\boxed{\n\\begin{array}{c}\n\\text{Minimum} = \\\\\n\\begin{cases}\n0 & \\text{if } k = 0 \\text{ or } k = n \\\\\n1 & \\text{otherwise}\n\\end{cases}\n\\\\\n\\\\\n\\text{Maximum} = \\min(n - k, 2k)\n\\end{array}\n}\n$$","simple_statement":null,"has_page_source":false}