{"problem":{"name":"C. Looking for Order","description":{"content":"Girl Lena likes it when everything is in order, and looks for order everywhere. Once she was getting ready for the University and noticed that the room was in a mess — all the objects from her handbag","description_type":"Markdown"},"platform":"Codeforces","limit":{"time_limit":4000,"memory_limit":524288},"difficulty":"None","is_remote":true,"is_sync":true,"sync_url":null,"sign":"CF8C"},"statements":[{"statement_type":"Markdown","content":"Girl Lena likes it when everything is in order, and looks for order everywhere. Once she was getting ready for the University and noticed that the room was in a mess — all the objects from her handbag were thrown about the room. Of course, she wanted to put them back into her handbag. The problem is that the girl cannot carry more than two objects at a time, and cannot move the handbag. Also, if he has taken an object, she cannot put it anywhere except her handbag — her inherent sense of order does not let her do so.\n\nYou are given the coordinates of the handbag and the coordinates of the objects in some Сartesian coordinate system. It is known that the girl covers the distance between any two objects in the time equal to the squared length of the segment between the points of the objects. It is also known that initially the coordinates of the girl and the handbag are the same. You are asked to find such an order of actions, that the girl can put all the objects back into her handbag in a minimum time period.\n\n## Input\n\nThe first line of the input file contains the handbag's coordinates _x__s_, _y__s_. The second line contains number _n_ (1 ≤ _n_ ≤ 24) — the amount of objects the girl has. The following _n_ lines contain the objects' coordinates. All the coordinates do not exceed 100 in absolute value. All the given positions are different. All the numbers are integer.\n\n## Output\n\nIn the first line output the only number — the minimum time the girl needs to put the objects into her handbag.\n\nIn the second line output the possible optimum way for Lena. Each object in the input is described by its index number (from 1 to _n_), the handbag's point is described by number 0. The path should start and end in the handbag's point. If there are several optimal paths, print any of them.\n\n[samples]","is_translate":false,"language":"English"},{"statement_type":"Markdown","content":"[{\"iden\":\"statement\",\"content\":\"女孩 Lena 喜欢一切井然有序，并处处寻找秩序。一次她准备上大学时，发现房间乱七八糟——她包里的所有物品都散落在各处。当然，她想把这些物品放回包里。但问题是，女孩一次最多只能拿两个物品，且不能移动手包。此外，一旦她拿起一个物品，就只能将其放回手包，不能放在其他任何地方——她内在的秩序感不允许她这样做。\\n\\n给定手包的坐标和若干物品在某个笛卡尔坐标系中的坐标。已知女孩在任意两个物品之间移动所需的时间等于两点间线段长度的平方。同时，已知女孩初始位置与手包位置相同。你需要找出一种行动顺序，使得女孩能以最小的时间将所有物品放回手包。\\n\\n输入文件的第一行包含手包的坐标 $[x_s, y_s]$。第二行包含数字 $n$（$1 \\\\le n \\\\le 24$）——女孩拥有的物品数量。接下来的 $n$ 行包含每个物品的坐标。所有坐标绝对值不超过 100，所有给定位置互不相同，所有数字均为整数。\\n\\n第一行输出一个数字——女孩将所有物品放回手包所需的最短时间。\\n\\n第二行输出 Lena 可能的最优路径。输入中的每个物品用其索引编号（从 1 到 $n$）表示，手包的位置用数字 0 表示。路径必须从手包位置开始并结束于手包位置。如果有多个最优路径，输出任意一个即可。 \"},{\"iden\":\"input\",\"content\":\"输入文件的第一行包含手包的坐标 $[x_s, y_s]$。第二行包含数字 $n$（$1 \\\\le n \\\\le 24$）——女孩拥有的物品数量。接下来的 $n$ 行包含每个物品的坐标。所有坐标绝对值不超过 100，所有给定位置互不相同，所有数字均为整数。\"},{\"iden\":\"output\",\"content\":\"第一行输出一个数字——女孩将所有物品放回手包所需的最短时间。第二行输出 Lena 可能的最优路径。输入中的每个物品用其索引编号（从 1 到 $n$）表示，手包的位置用数字 0 表示。路径必须从手包位置开始并结束于手包位置。如果有多个最优路径，输出任意一个即可。 \"},{\"iden\":\"examples\",\"content\":\"输入\\n0 0\\n2\\n1 1\\n-1 1\\n输出\\n8\\n0 1 2 0 \\n\\n输入\\n1 1\\n3\\n4 3\\n3 4\\n0 0\\n输出\\n32\\n0 1 2 0 3 0 \"}]}","is_translate":true,"language":"Chinese"},{"statement_type":"Markdown","content":"**Definitions:**\n\nLet $H = (x_0, y_0)$ denote the coordinates of the handbag (index $0$).\nLet $N = \\{1, 2, \\dots, n\\}$ be the set of indices for the objects.\nFor each $i \\in N$, let $P_i = (x_i, y_i)$ denote the coordinates of the $i$-th object.\n\nLet $d: \\{0\\} \\cup N \\times \\{0\\} \\cup N \\to \\mathbb{Z}_{\\ge 0}$ be the cost function defined as the squared Euclidean distance between two points:\n$$ d(i, j) = (x_i - x_j)^2 + (y_i - y_j)^2 $$\n\n**Optimization Model:**\n\nThe problem is modeled as finding a partition of the set $N$ into $k$ disjoint subsets $\\{S_1, S_2, \\dots, S_k\\}$ such that:\n1.  $\\bigcup_{m=1}^k S_m = N$\n2.  $S_p \\cap S_q = \\emptyset, \\quad \\forall p \\neq q$\n3.  $1 \\le |S_m| \\le 2, \\quad \\forall m \\in \\{1, \\dots, k\\}$\n\nFor a given subset $S_m$, the trip cost $C(S_m)$ is defined as:\n$$ C(S_m) = \\begin{cases} 2d(0, i) & \\text{if } S_m = \\{i\\} \\\\ d(0, i) + d(i, j) + d(j, 0) & \\text{if } S_m = \\{i, j\\}, i \\neq j \\end{cases} $$\n\n**Objective:**\n\nMinimize the total time $T$:\n$$ \\min T = \\sum_{m=1}^k C(S_m) $$\n\n**Output Requirements:**\n\n1.  The minimum value of $T$.\n2.  A sequence of indices $V = (v_1, v_2, \\dots, v_L)$ representing the optimal path, satisfying:\n    *   $v_1 = v_L = 0$\n    *   The sequence consists of a concatenation of cycles corresponding to the partition sets $S_m$.\n    *   For a subset $S_m = \\{i\\}$, the subsequence is $(0, i, 0)$.\n    *   For a subset $S_m = \\{i, j\\}$, the subsequence is $(0, i, j, 0)$ or $(0, j, i, 0)$.","is_translate":false,"language":"Formal"}],"meta":{"iden":"CF8C","tags":["bitmasks","dp"],"sample_group":[["0 0\n2\n1 1\n-1 1","8\n0 1 2 0"],["1 1\n3\n4 3\n3 4\n0 0","32\n0 1 2 0 3 0"]],"created_at":"2026-03-03 11:00:39"}}