{"problem":{"name":"156. Closest Houses","description":{"content":"For this problem, you will be tasked with sorting a series of houses by how close they are to a given house. The rules for house distances are as follows: houses on the same street will have have a di","description_type":"Markdown"},"platform":"Codeforces","limit":{"time_limit":1000,"memory_limit":262144},"difficulty":"None","is_remote":true,"is_sync":true,"sync_url":null,"sign":"CF10269156"},"statements":[{"statement_type":"Markdown","content":"For this problem, you will be tasked with sorting a series of houses by how close they are to a given house. The rules for house distances are as follows: houses on the same street will have have a distance of the difference between their house numbers, and houses on different streets will experience a distance equal to the difference between their house numbers times the difference between their street numbers. Houses will be each provided with a unique name, such as \"h1\", and will also have a street number that represents which street they live on as well as a house number that represents their position on the street. For this problem, you will be given a series of houses and their respective values and you will need to determine which house is the closest to a specified house. For example, you may be given h1,h2,h3,h4,h5, then asked to find the closest house to h3.\n\nThe first line of input contains a single integer $n$ that represents the number of houses that are contained in the set. The next $n$ lines each contain information about a different house in the format: \"name streetnum housenum\". After $n$ lines, there will be one line that lists the name of the house that should be used in the nearest house computation.\n\nA single string that represents the house that is closest to the given house name.\n\n## Input\n\nThe first line of input contains a single integer $n$ that represents the number of houses that are contained in the set. The next $n$ lines each contain information about a different house in the format: \"name streetnum housenum\". After $n$ lines, there will be one line that lists the name of the house that should be used in the nearest house computation.\n\n## Output\n\nA single string that represents the house that is closest to the given house name.\n\n[samples]","is_translate":false,"language":"English"},{"statement_type":"Markdown","content":"**Definitions**  \nLet $ H = \\{ ( \\text{name}_i, s_i, h_i ) \\mid i \\in \\{1, \\dots, n\\} \\} $ be the set of houses, where:  \n- $ \\text{name}_i \\in \\mathbb{S} $ is the unique name of house $ i $,  \n- $ s_i \\in \\mathbb{Z}^+ $ is the street number,  \n- $ h_i \\in \\mathbb{Z}^+ $ is the house number on the street.  \n\nLet $ q \\in \\mathbb{S} $ be the query house name, and let $ (s_q, h_q) $ be its street and house numbers.\n\n**Distance Function**  \nFor two houses $ i $ and $ j $:  \n$$\nd(i, j) = \n\\begin{cases}\n|h_i - h_j| & \\text{if } s_i = s_j, \\\\\n|h_i - h_j| \\cdot |s_i - s_j| & \\text{if } s_i \\ne s_j.\n\\end{cases}\n$$\n\n**Constraints**  \n1. $ 1 \\le n \\le 100 $  \n2. All names are unique.  \n3. $ s_i, h_i \\ge 1 $ for all $ i $.\n\n**Objective**  \nFind the house $ \\text{name}_k \\in H \\setminus \\{q\\} $ such that:  \n$$\nk = \\arg\\min_{i: \\text{name}_i \\ne q} d(i, q)\n$$  \nIf multiple houses achieve the minimum distance, return any one of them.","is_translate":false,"language":"Formal"}],"meta":{"iden":"CF10269156","tags":[],"sample_group":[],"created_at":"2026-03-03 11:00:39"}}