andylizf commited on
Commit
7bb9648
·
verified ·
1 Parent(s): 2da8cfa

Update dataset

Browse files
Files changed (2) hide show
  1. README.md +2 -2
  2. data/test-00000-of-00001.json +10 -0
README.md CHANGED
@@ -19,8 +19,8 @@ A benchmark dataset for evaluating AI systems on challenging computer science pr
19
 
20
  ## Dataset Description
21
 
22
- This dataset contains 244 problems across two categories:
23
- - **Algorithmic**: 178 competitive programming problems with automated judging
24
  - **Research**: 66 open-ended research problems
25
 
26
  ## Dataset Structure
 
19
 
20
  ## Dataset Description
21
 
22
+ This dataset contains 254 problems across two categories:
23
+ - **Algorithmic**: 188 competitive programming problems with automated judging
24
  - **Research**: 66 open-ended research problems
25
 
26
  ## Dataset Structure
data/test-00000-of-00001.json CHANGED
@@ -129,6 +129,16 @@
129
  {"problem_id": "303", "category": "algorithmic", "statement": "```markdown\n# Manhattan Compass Prospecting (Optimization)\n\n## Problem\nThere are **N** distinct pinholes on the 2D plane. The *i*-th pinhole is at integer coordinates \\((x_i, y_i)\\) and has a nonnegative integer value \\(w_i\\).\n\nYou operate a peculiar instrument, the **Manhattan Compass**, which always touches **exactly two distinct pinholes** at a time. The two legs are indistinguishable: the state “touching \\((p,q)\\)” is the same as “touching \\((q,p)\\)”.\n\nLet the Manhattan distance be:\n\\[\nd(i,j) = |x_i-x_j| + |y_i-y_j|.\n\\]\n\n### Allowed move\nSuppose the compass currently touches pinholes \\(\\{p,q\\}\\) with \\(p \\neq q\\).\n\nYou may perform one move to change the state to \\(\\{p,r\\}\\) **(keeping \\(p\\) fixed and moving the other leg)** if and only if:\n- \\(r \\neq p\\), and\n- \\(d(p,q) = d(p,r)\\).\n\nSimilarly, you may move to \\(\\{q,r\\}\\) if \\(d(p,q)=d(q,r)\\).\n\n### Collecting value and paying cost\n- You **collect** the value \\(w_i\\) of a pinhole \\(i\\) the **first time** it is touched by either leg at any time (including initially).\n- Each move has a fixed **time cost** \\(c\\) (given in input).\n- You are allowed to make at most **L** moves.\n\nYou start with the compass touching pinholes \\(\\{a,b\\}\\).\n\nYour task is to output **any valid sequence of moves** (possibly empty) to **maximize profit**.\n\n---\n\n## Input\n```\nN L a b c\nx_1 y_1 w_1\nx_2 y_2 w_2\n:\nx_N y_N w_N\n```\n\n### Constraints\n- \\(2 \\le N \\le 200000\\)\n- \\(0 \\le L \\le 200000\\)\n- \\(1 \\le a < b \\le N\\)\n- \\(1 \\le x_i, y_i \\le 10^9\\)\n- \\(0 \\le w_i \\le 10^6\\)\n- \\(0 \\le c \\le 10^6\\)\n- All \\((x_i,y_i)\\) are distinct.\n\n---\n\n## Output\nOutput a move sequence in the following format:\n```\nS\nu_1 v_1\nu_2 v_2\n:\nu_S v_S\n```\nwhere:\n- \\(S\\) is the number of moves, and must satisfy \\(0 \\le S \\le L\\).\n- Each line \\(u_t, v_t\\) denotes the **unordered** pair of pinholes touched **after** the \\(t\\)-th move.\n- Feasibility requirements:\n - \\(1 \\le u_t, v_t \\le N\\), \\(u_t \\ne v_t\\).\n - Let the initial state be \\(\\{u_0,v_0\\}=\\{a,b\\}\\).\n - For each \\(t \\ge 1\\), the transition from \\(\\{u_{t-1},v_{t-1}\\}\\) to \\(\\{u_t,v_t\\}\\) must be achievable by **one allowed move** (i.e., the two pairs share exactly one pinhole, and the Manhattan distances from the shared pinhole to the moved endpoints are equal as defined above).\n\nIf the output violates any feasibility rule, the submission is invalid for that test case.\n\n---\n\n## Objective\nFor a feasible output, define:\n- \\(T\\) = the set of pinholes that appear in any touched pair, i.e.\n \\[\n T = \\{a,b\\} \\cup \\bigcup_{t=1}^{S} \\{u_t, v_t\\}.\n \\]\n- Collected value:\n \\[\n V = \\sum_{i \\in T} w_i.\n \\]\n- Profit:\n \\[\n P = V - c \\cdot S.\n \\]\n\n**Maximize** \\(P\\).\n\n---\n\n## Scoring\nThis is an optimization problem with continuous scoring.\n\nFor each test case, the judge computes:\n- Your profit \\(P\\).\n- A deterministic internal reference profit \\(P_0\\), computed by the judge from the same test case.\n\nThe per-test score ratio is:\n\\[\n\\text{ratio} =\n\\begin{cases}\n0 & \\text{if } P \\le 0 \\\\\n\\mathrm{clamp}\\left(\\dfrac{P - P_0}{P},\\, 0,\\, 1\\right) & \\text{otherwise}\n\\end{cases}\n\\]\nwhere \\(\\mathrm{clamp}(x,0,1)=\\min(1,\\max(0,x))\\).\n\nThe final score is the sum of per-test ratios, scaled to the total points configured for this problem.\n\n---\n\n## Constraints\n- Time limit: 2 seconds\n- Memory limit: 1024 MB\n\n---\n\n## Example\n### Sample input\n```\n6 5 1 2 3\n1 1 10\n4 1 8\n7 1 7\n4 4 100\n1 4 6\n7 4 6\n```\n\n### Sample output\n```\n3\n1 3\n3 6\n6 4\n```\n\n### Explanation (high level)\n- Start touching \\(\\{1,2\\}\\); collected so far: \\(w_1+w_2=18\\).\n- Each printed pair must be reachable by one allowed move (equal-distance rule around the shared pinhole).\n- The judge computes the set of touched pinholes \\(T\\), sums their values to get \\(V\\), subtracts \\(c \\cdot S\\) to get profit \\(P\\), then compares \\(P\\) against the judge's deterministic reference profit \\(P_0\\) using the normalized ratio above.\n```\n", "config": "checker: chk.cc\nmemory: 1024m\nsubtasks:\n- n_cases: 8\n score: 100\ntime: 2s\ntype: default\n"}
130
  {"problem_id": "304", "category": "algorithmic", "statement": "```markdown\n# Forest Mycelium Delay Tour (Optimization Challenge)\n\n## Problem\nVasya is mapping a forest trail network with **mushroom clearings**.\n\nThe forest is modeled as an undirected connected graph with `N` clearings (vertices) and `M` trails (edges). \nAt clearing `i`, mushrooms grow at a constant rate `r[i]` grams per minute, starting from **0 grams at time 0**.\n\n- Vasya starts at clearing `1` at time `t = 0`.\n- Each minute, Vasya **must** traverse exactly one trail to an adjacent clearing (no waiting).\n- When Vasya **first arrives** at a clearing `i` at time `t`, he instantly collects **all mushrooms grown there so far**, equal to `r[i] * t` grams.\n- After the first collection at clearing `i`, that clearing becomes barren and yields **0** on future visits.\n- Vasya will walk for exactly `K` minutes (i.e., traverse exactly `K` edges), ending anywhere.\n- To be feasible, his walk must visit **every clearing at least once** during times `0..K`.\n\nYour goal is to output a feasible walk that **maximizes the total collected mushroom weight**.\n\nThis is an open-ended optimization task: many solutions are valid, and they receive different scores.\n\n## Input\n```\nN M K\nr1 r2 ... rN\nu1 v1\nu2 v2\n...\nuM vM\n```\n\n- `1 ≤ N ≤ 20000`\n- `N-1 ≤ M ≤ 60000`\n- `2·(N-1) ≤ K ≤ 200000`\n- `1 ≤ r[i] ≤ 10^6`\n- `1 ≤ uj, vj ≤ N`, `uj != vj`\n- The graph is connected.\n- Multiple edges may appear; self-loops do not appear.\n\nThe constraints guarantee that a walk of length `K` visiting all vertices exists.\n\n## Output\nOutput exactly `K` integers:\n```\nx1 x2 ... xK\n```\nwhere `xt` is the clearing Vasya is at **after** minute `t` (after the `t`-th move).\n\nFeasibility requirements:\n- Vasya starts at clearing `1` at time `0`.\n- For each `t = 1..K`, the move from the previous clearing to `xt` must follow an existing trail (edge).\n- Every clearing `1..N` must appear at least once among the visited clearings at times `0..K` (including the start at time 0).\n\nIf the output is infeasible, the solution receives **0 score for that test**.\n\n## Objective\nLet `pos(t)` be Vasya’s clearing at time `t` (`pos(0)=1`, `pos(t)=xt` for `t≥1`).\n\nFor each clearing `i`, define its first-visit time:\n- `T[i] = min { t ∈ [0..K] | pos(t) = i }`\n\nTotal collected weight:\n\\[\nV = \\sum_{i=1}^{N} r[i] \\cdot T[i]\n\\]\n(Notice `T[1]=0`, so clearing 1 contributes `0`.)\n\nYou must **maximize** `V`.\n\n## Scoring\nScoring is computed **per test**.\n\n### Reference value `B`\nFor each test, the judge computes a deterministic internal reference walk from the same instance, and lets `B` be the objective value of that walk.\n\n### Per-test score\nIf `V = 0`, the per-test ratio is defined as `0`.\n\nOtherwise, for your solution value `V`, the per-test ratio is:\n\\[\n\\mathrm{ratio} = \\mathrm{clamp}\\left(\\frac{V - B}{V},\\, 0,\\, 1\\right)\n\\]\nwhere `clamp(x,0,1)=min(1,max(0,x))`.\n\n### Total score\nThe final score is the sum of per-test ratios, scaled to the total points configured for this problem.\n\n## Constraints\n- Time limit: 2 seconds\n- Memory limit: 256 MB\n\n## Example\nSample input:\n```\n4 4 6\n5 1 4 10\n1 2\n2 3\n3 4\n1 4\n```\n\nOne valid sample output:\n```\n2 3 2 1 4 3\n```\n\nExplanation (high level):\n- Path: time 0 at 1, time 1 at 2, time 2 at 3, time 3 at 2, time 4 at 1, time 5 at 4, time 6 at 3.\n- First-visit times: `T[1]=0, T[2]=1, T[3]=2, T[4]=5`.\n- Objective value: `V = 5·0 + 1·1 + 4·2 + 10·5 = 59`.\n- The judge also computes the baseline value `B` for this test, then assigns a normalized ratio using the formula above.\n```\n", "config": "checker: chk.cc\nmemory: 256m\nsubtasks:\n- n_cases: 10\n score: 100\ntime: 2s\ntype: default\n"}
131
  {"problem_id": "305", "category": "algorithmic", "statement": "```markdown\n# Cascading Flip Schedule on a Power Grid Tree\n\n## Problem\nYou operate a power grid shaped as a tree with **N** substations (vertices) and **N−1** transmission lines (edges). \nEach substation has a reversible breaker with two states:\n\n- `W` (white) = **safe to service**\n- `B` (black) = **unsafe to service**\n\nInitially, the states are given by a string **S** of length **N**.\n\nYou must **service every substation exactly once** by choosing an order and performing a cascade operation. However, servicing a substation may destabilize nearby substations by flipping breaker states.\n\n### Cascade Service Operation\nYou perform **N rounds**. In round **t** you choose a substation **P_t** that has not been serviced yet, and you:\n1. **Pay cost** equal to the number of currently-unsafe breakers (`B`) among **unserviced** substations (including the chosen one if it is `B`).\n2. **Service** substation **P_t** (it becomes “removed” and is never flipped again).\n3. For every **unserviced neighbor** of **P_t**, **flip** its breaker state (`W ↔ B`).\n\nServiced substations are removed from the system:\n- They no longer contribute to future costs.\n- Their breakers are no longer flipped.\n\n### Feasibility\nAny permutation of vertices is a valid schedule (you may service a `B` substation; it just tends to be expensive). \nYour goal is not feasibility but **minimizing total instability cost**.\n\n## Input\n```\nN\nA_1 B_1\nA_2 B_2\n…\nA_{N-1} B_{N-1}\nS\n```\n- The graph is a tree.\n- Edge `i` connects vertices `A_i` and `B_i`.\n- `S[i]` is `W` or `B`, the initial breaker state at vertex `i`.\n\n## Output\nOutput a permutation of `1..N`:\n```\nP_1 P_2 … P_N\n```\nThis is your service order.\n\nA submission is invalid if:\n- It does not contain each vertex exactly once, or\n- It contains an out-of-range index.\n\nInvalid submissions receive the worst possible score for that test.\n\n## Objective\nLet `U_t` be the set of **unserviced** vertices just before round `t` (so `U_1` is all vertices, `U_{N+1}` is empty).\n\nLet `B_t` be the number of vertices in `U_t` whose breaker is `B` at that moment.\n\nYour **total cost** is:\n\\[\nC = \\sum_{t=1}^{N} B_t\n\\]\nYou must **minimize** `C`.\n\nNotes:\n- Breaker flips happen **after** paying `B_t`.\n- Only **unserviced neighbors** are flipped.\n\n## Scoring\nThis is an **optimization** problem; lower cost is better.\n\nFor each test case, the judge computes:\n- `C_out`: cost of your output schedule.\n- `C_base`: cost of a deterministic internal reference schedule computed from that test case.\n\nYour per-test ratio is:\n\\[\ns =\n\\begin{cases}\n0 & \\text{if } C_{\\text{base}} = 0 \\\\\n\\mathrm{clamp}\\!\\left(\\frac{C_{\\text{base}} - C_{\\text{out}}}{C_{\\text{base}}},\\, 0,\\, 1\\right) & \\text{otherwise}\n\\end{cases}\n\\]\nwhere `clamp(x,0,1)=min(1,max(0,x))`.\n\nSpecial cases:\n- Invalid output: `s = 0`.\n\n### Reference cost `C_base`\n`C_base` is the cost of a deterministic internal reference schedule computed by the judge from the same test case.\n\nThe exact construction of this internal reference schedule is intentionally not part of the contestant-facing specification. For solving the problem, you should optimize `C_out` directly according to the objective above.\n\n### Total score\nThe per-test ratio `s` is scaled to the total points configured for this problem in the judge configuration; the final score is the sum of these scaled per-test contributions across all test cases.\n\n## Why this is hard\nThe cascade flips create long-range dependencies: choosing a vertex changes future states of its neighbors, which changes future costs. Minimizing the integral of “how many unsafe breakers remain over time” is closely related to difficult sequencing problems on graphs; under these constraints, exact optimization is computationally infeasible in practice, so heuristics matter.\n\nMultiple strategies can work well:\n- Greedy selection by estimated marginal impact on future `B_t`\n- Tree decompositions with local dynamic programming + recombination\n- Large neighborhood search / simulated annealing on permutations\n- Beam search over partial schedules\n- Hybrid methods (greedy initialization + local swap/2-opt/segment moves + repair)\n\n## Constraints\n- `1 ≤ N ≤ 2×10^5`\n- `1 ≤ A_i, B_i ≤ N`\n- The input graph is a tree.\n- `S` consists only of `B` and `W`.\n- Time limit: **2 seconds**\n- Memory limit: **1024 MB**\n\n## Example\nSample input:\n```\n4\n1 2\n2 3\n3 4\nWBWW\n```\n\nOne possible output:\n```\n1 2 4 3\n```\n\nExplanation (high level):\n- The judge simulates your order.\n- Each round adds the current count of `B` among remaining vertices, then flips unserviced neighbors of the chosen vertex.\n- The resulting total `C_out` is compared against the judge's deterministic reference cost `C_base`, producing a ratio `s ∈ [0, 1]` for this test which is then scaled to the configured per-test point budget.\n```\n", "config": "checker: chk.cc\nmemory: 1024m\nsubtasks:\n- n_cases: 8\n score: 100\ntime: 2s\ntype: default\n"}
 
 
 
 
 
 
 
 
 
 
132
  {"problem_id": "33", "category": "algorithmic", "statement": "Permutation (Modified Version)\n\nTime Limit: 5 s\nMemory Limit: 1024 MB\n\nThe Pharaohs use the relative movement and gravity of planets to accelerate their spaceships. Suppose a spaceship will pass by some planets with orbital speeds in order. For each planet, the Pharaohs' scientists can choose whether to accelerate the spaceship using this planet or not. To save energy, after accelerating by a planet with orbital speed p[i], the spaceship cannot be accelerated using any planet with orbital speed p[j] < p[i]. In other words, the chosen planets form an increasing subsequence of p.\n\nThe scientists have identified that there are exactly k different ways a set of planets can be chosen to accelerate the spaceship. They have lost their record of all the orbital speeds (even the value of n). However, they remember that p is a permutation of {0, 1, …, n−1}. Your task is to find one possible permutation of sufficiently small length.\n\nInput\nThe first line contains an integer q (1 ≤ q ≤ 100), the number of spaceships.\nThe second line contains q integers k1, k2, …, kq (2 ≤ ki ≤ 10^18).\n\nOutput\nFor each ki, output two lines:\n- The first line contains an integer n (the length of the permutation).\n- The second line contains n integers: a valid permutation of {0, 1, …, n−1} having exactly ki increasing subsequences.\n\nScoring\nLet m be the maximum permutation length you used across all queries.\nYour score for the test file will be determined as follows:\n\nm ≤ 90 → 100 points\n\n90 < m < 2000 -> linear function\n\nm >= 2000 -> 0\n\nExample\nInput\n2\n3 8\n\nOutput\n2\n1 0\n3\n0 1 2\n\nExplanation\nFor k = 3, one valid permutation is [1, 0], which has exactly 3 increasing subsequences: [], [0], [1].\nFor k = 8, one valid permutation is [0, 1, 2], which has exactly 8 increasing subsequences: [], [0], [1], [2], [0, 1], [0, 2], [1, 2], [0, 1, 2].\n", "config": "type: default\ntime: 5s\nmemory: 1024m\nsubtasks:\n - score: 100\n n_cases: 3\nchecker: checker.cpp\nchecker_type: testlib"}
133
  {"problem_id": "35", "category": "algorithmic", "statement": "Language: C++ only\n\nTime limit per test: 5 seconds\nMemory limit per test: 1024 megabytes\n\nThis is an interactive problem.\n\nThere is a hidden array a containing all the numbers from 1 to n, and all of them appear twice except one (which only appears once).\n\nYou can ask queries in the following format, where S is a subset of {1,2,…,2n−1} and x is an integer in [1,n]:\n\n? x |S| S1 S2 ... S|S|\n\nThe answer to this query is: does there exist i ∈ S such that a_i = x ?\n\nYour task is to find the number appearing exactly once, using at most 5000 queries. You don’t need to find its position.\n\nNote that the interactor is not adaptive, which means that the hidden array does not depend on the queries you make.\n\nInput\nEach test contains multiple test cases.\nThe first line contains the number of test cases t (1 ≤ t ≤ 20).\n\nThe description of the test cases follows.\n\nThe first line of each test case contains a single integer n (n = 300) — the maximum value in the hidden array.\n\nInteraction\nFor each test case, first read a single integer. If the integer you read is -1, it means that the answer to the previous test case was wrong, and you should exit immediately.\n\nYou may ask up to 5000 queries in each test case.\n\nTo ask a query, print a line in the format described above.\nAs a response to the query, you will get:\n\n1 if the answer is yes,\n\n0 if the answer is no,\n\n-1 if you made an invalid query. In this case you should exit immediately.\n\nTo output an answer, print:\n! y\nwhere y is the number that appears exactly once.\nPrinting the answer doesn’t count as a query.\n\nIf you ask too many queries, you ask a malformed query, or your answer is wrong, you will get -1.\n\nAfter printing a query, do not forget to output the end of line and flush the output. Otherwise, you will get Idleness limit exceeded.\nIn C++, you can use:\nfflush(stdout);\ncout.flush();\n\nScoring\n\nIf you solve the problem with at most 500 queries, you get 100 points.\n\nIf you solve it with 5000 queries, you get 0 points.\n\nFor values in between, the score decreases linearly.\n\nExample\nInput\n1\n300\n0\n\nExplanation\nIn the first test case, n = 300, so the hidden array has length 2n − 1 = 599.\n\nContestant prints / Interactor replies\n? 187 1 1\n0\n! 187\n\nQuery: does a1 = 187? → No.\nWe then output ! 187.\nFortunately, the answer is correct.\n\nWe have asked 1 query (printing the answer does not count as a query), which is less than the maximum allowed number of queries (5000).", "config": "# Set the problem type to interactive\ntype: interactive\n\n# Specify the interactor source file\ninteractor: interactor.cpp\n\n# Time and memory limits still apply to the contestant's solution\ntime: 5s\nmemory: 1024m\n\n# The subtasks section works the same way\nsubtasks:\n - score: 100\n n_cases: 3 # Looks for 1.in, 2.in, ... 5.in"}
134
  {"problem_id": "36", "category": "algorithmic", "statement": "Hack!\n\nThis is an I/O interactive problem. I/O interaction refers to interactive problems, where the program communicates with a special judge during execution instead of producing all output at once. In these problems, the program sends queries (output) to the judge and must immediately read responses (input) before continuing. The solution must strictly follow the input-output protocol defined in the problem statement, because any extra output, missing flush, or incorrect format can cause a wrong answer. Unlike standard problems, interactive problems require careful handling of I/O, synchronization, and flushing to ensure smooth communication between the contestant’s code and the judge.\n\nYou know that unordered_set uses a hash table with n buckets, which are numbered from 0 to\nn − 1. Unfortunately, you do not know the value of n and wish to recover it.\nWhen you insert an integer x into the hash table, it is inserted to the (x mod n) -th bucket. If\nthere are b elements in this bucket prior to the insertion, this will cause b hash collisions to occur.\n\nBy giving k distinct integers x[0],x[1],…,x[k − 1] to the interactor, you can find out the total\nnumber of hash collisions that had occurred while creating an unordered_set containing the\nnumbers. However, feeding this interactor k integers in one query will incur a cost of k.\nFor example, if n = 5, feeding the interactor with x = [2, 15, 7, 27, 8, 30] would cause 4 collisions in\ntotal:\n\nOperation New collisions Buckets\ninitially − [],[],[],[],[]\ninsert x[0] = 2 0 [],[],[2],[],[]\ninsert x[1] = 15 0 [15],[],[2],[],[]\ninsert x[2] = 7 1 [15],[],[2, 7],[],[]\ninsert x[3] = 27 2 [15],[],[2, 7, 27],[],[]\ninsert x[4] = 8 0 [15],[],[2, 7, 27],[8],[]\ninsert x[5] = 30 1 [15, 30],[],[2, 7, 27],[8],[]\n\nNote that the interactor creates the hash table by inserting the elements in order into an initially empty unordered_set, and a new empty unordered_set will be created for each query. In other words, all queries are independent.\n\nYour task is to find the number of buckets n (2<=n<=10^9) using total cost of at most 1 000 000. Total cost is the total length of your queries. You have to minimize total cost as much as possible. Your final score will be calculated as the average of 100 * clamp(log_50(10^6 / (your_total_cost - 9 * 10^4)), 0, 1) across all cases.\n\nInput\n\nThere is no input in this problem.\n\nInteraction\n\nTo ask a query, output one line. First output 0 followed by a space, then output an positive integer m, the number of elements in this query, then print a sequence of m integers ranging from 1 to 10^18 separated by a space. After flushing your output, your program should read a single integer x indicating the number of collisions created by inserting the elements in order to an unordered_set.\n\nIf you want to guess n, output one line. First output 1 followed by a space, then print the n you guess. After flushing your output, your program should exit immediately.\n\nNote that the answer for each test case is pre-determined. That is, the interactor is not adaptive. Also note that your guess does not count as a query.\n\nTo flush your output, you can use:\n\n fflush(stdout) (if you use printf) or cout.flush() (if you use cout) in C and C++.\n\n System.out.flush() in Java.\n\n stdout.flush() in Python.\n\nNote\n\nPlease note that if you receive a Time Limit Exceeded verdict, it is possible that your query is invalid or the number of queries exceeds the limit.\n\nConstraints \n- Time limit: 3 seconds\n- Memory Limit: 1024 MB\n- Let Q be the query cost you make.\n - If your program exceeds time limit, memory limit, or returns incorrect answer → score=0.\n - Otherwise, your score depends on Q:\n - score(Q) = 1000001 / (Q + 1)\n - In other words, a solution with Q <= 1000000 is awarded the full score.\n\nExample input (you to interactor):\n0 6 2 15 7 27 8 30\n\n0 3 1 2 3\n\n0 5 10 20 30 40 50\n\n1 5\n\nExample output (interactor to you):\n\n4\n\n0\n\n10", "config": "# Set the problem type to interactive\ntype: interactive\n\n# Specify the interactor source file\ninteractor: interactor.cpp\n\n# Time and memory limits still apply to the contestant's solution\ntime: 3s\nmemory: 1024m\n\n# The subtasks section works the same way\nsubtasks:\n - score: 100\n n_cases: 3 # Looks for 1.in, 2.in, ... 5.in"}
 
129
  {"problem_id": "303", "category": "algorithmic", "statement": "```markdown\n# Manhattan Compass Prospecting (Optimization)\n\n## Problem\nThere are **N** distinct pinholes on the 2D plane. The *i*-th pinhole is at integer coordinates \\((x_i, y_i)\\) and has a nonnegative integer value \\(w_i\\).\n\nYou operate a peculiar instrument, the **Manhattan Compass**, which always touches **exactly two distinct pinholes** at a time. The two legs are indistinguishable: the state “touching \\((p,q)\\)” is the same as “touching \\((q,p)\\)”.\n\nLet the Manhattan distance be:\n\\[\nd(i,j) = |x_i-x_j| + |y_i-y_j|.\n\\]\n\n### Allowed move\nSuppose the compass currently touches pinholes \\(\\{p,q\\}\\) with \\(p \\neq q\\).\n\nYou may perform one move to change the state to \\(\\{p,r\\}\\) **(keeping \\(p\\) fixed and moving the other leg)** if and only if:\n- \\(r \\neq p\\), and\n- \\(d(p,q) = d(p,r)\\).\n\nSimilarly, you may move to \\(\\{q,r\\}\\) if \\(d(p,q)=d(q,r)\\).\n\n### Collecting value and paying cost\n- You **collect** the value \\(w_i\\) of a pinhole \\(i\\) the **first time** it is touched by either leg at any time (including initially).\n- Each move has a fixed **time cost** \\(c\\) (given in input).\n- You are allowed to make at most **L** moves.\n\nYou start with the compass touching pinholes \\(\\{a,b\\}\\).\n\nYour task is to output **any valid sequence of moves** (possibly empty) to **maximize profit**.\n\n---\n\n## Input\n```\nN L a b c\nx_1 y_1 w_1\nx_2 y_2 w_2\n:\nx_N y_N w_N\n```\n\n### Constraints\n- \\(2 \\le N \\le 200000\\)\n- \\(0 \\le L \\le 200000\\)\n- \\(1 \\le a < b \\le N\\)\n- \\(1 \\le x_i, y_i \\le 10^9\\)\n- \\(0 \\le w_i \\le 10^6\\)\n- \\(0 \\le c \\le 10^6\\)\n- All \\((x_i,y_i)\\) are distinct.\n\n---\n\n## Output\nOutput a move sequence in the following format:\n```\nS\nu_1 v_1\nu_2 v_2\n:\nu_S v_S\n```\nwhere:\n- \\(S\\) is the number of moves, and must satisfy \\(0 \\le S \\le L\\).\n- Each line \\(u_t, v_t\\) denotes the **unordered** pair of pinholes touched **after** the \\(t\\)-th move.\n- Feasibility requirements:\n - \\(1 \\le u_t, v_t \\le N\\), \\(u_t \\ne v_t\\).\n - Let the initial state be \\(\\{u_0,v_0\\}=\\{a,b\\}\\).\n - For each \\(t \\ge 1\\), the transition from \\(\\{u_{t-1},v_{t-1}\\}\\) to \\(\\{u_t,v_t\\}\\) must be achievable by **one allowed move** (i.e., the two pairs share exactly one pinhole, and the Manhattan distances from the shared pinhole to the moved endpoints are equal as defined above).\n\nIf the output violates any feasibility rule, the submission is invalid for that test case.\n\n---\n\n## Objective\nFor a feasible output, define:\n- \\(T\\) = the set of pinholes that appear in any touched pair, i.e.\n \\[\n T = \\{a,b\\} \\cup \\bigcup_{t=1}^{S} \\{u_t, v_t\\}.\n \\]\n- Collected value:\n \\[\n V = \\sum_{i \\in T} w_i.\n \\]\n- Profit:\n \\[\n P = V - c \\cdot S.\n \\]\n\n**Maximize** \\(P\\).\n\n---\n\n## Scoring\nThis is an optimization problem with continuous scoring.\n\nFor each test case, the judge computes:\n- Your profit \\(P\\).\n- A deterministic internal reference profit \\(P_0\\), computed by the judge from the same test case.\n\nThe per-test score ratio is:\n\\[\n\\text{ratio} =\n\\begin{cases}\n0 & \\text{if } P \\le 0 \\\\\n\\mathrm{clamp}\\left(\\dfrac{P - P_0}{P},\\, 0,\\, 1\\right) & \\text{otherwise}\n\\end{cases}\n\\]\nwhere \\(\\mathrm{clamp}(x,0,1)=\\min(1,\\max(0,x))\\).\n\nThe final score is the sum of per-test ratios, scaled to the total points configured for this problem.\n\n---\n\n## Constraints\n- Time limit: 2 seconds\n- Memory limit: 1024 MB\n\n---\n\n## Example\n### Sample input\n```\n6 5 1 2 3\n1 1 10\n4 1 8\n7 1 7\n4 4 100\n1 4 6\n7 4 6\n```\n\n### Sample output\n```\n3\n1 3\n3 6\n6 4\n```\n\n### Explanation (high level)\n- Start touching \\(\\{1,2\\}\\); collected so far: \\(w_1+w_2=18\\).\n- Each printed pair must be reachable by one allowed move (equal-distance rule around the shared pinhole).\n- The judge computes the set of touched pinholes \\(T\\), sums their values to get \\(V\\), subtracts \\(c \\cdot S\\) to get profit \\(P\\), then compares \\(P\\) against the judge's deterministic reference profit \\(P_0\\) using the normalized ratio above.\n```\n", "config": "checker: chk.cc\nmemory: 1024m\nsubtasks:\n- n_cases: 8\n score: 100\ntime: 2s\ntype: default\n"}
130
  {"problem_id": "304", "category": "algorithmic", "statement": "```markdown\n# Forest Mycelium Delay Tour (Optimization Challenge)\n\n## Problem\nVasya is mapping a forest trail network with **mushroom clearings**.\n\nThe forest is modeled as an undirected connected graph with `N` clearings (vertices) and `M` trails (edges). \nAt clearing `i`, mushrooms grow at a constant rate `r[i]` grams per minute, starting from **0 grams at time 0**.\n\n- Vasya starts at clearing `1` at time `t = 0`.\n- Each minute, Vasya **must** traverse exactly one trail to an adjacent clearing (no waiting).\n- When Vasya **first arrives** at a clearing `i` at time `t`, he instantly collects **all mushrooms grown there so far**, equal to `r[i] * t` grams.\n- After the first collection at clearing `i`, that clearing becomes barren and yields **0** on future visits.\n- Vasya will walk for exactly `K` minutes (i.e., traverse exactly `K` edges), ending anywhere.\n- To be feasible, his walk must visit **every clearing at least once** during times `0..K`.\n\nYour goal is to output a feasible walk that **maximizes the total collected mushroom weight**.\n\nThis is an open-ended optimization task: many solutions are valid, and they receive different scores.\n\n## Input\n```\nN M K\nr1 r2 ... rN\nu1 v1\nu2 v2\n...\nuM vM\n```\n\n- `1 ≤ N ≤ 20000`\n- `N-1 ≤ M ≤ 60000`\n- `2·(N-1) ≤ K ≤ 200000`\n- `1 ≤ r[i] ≤ 10^6`\n- `1 ≤ uj, vj ≤ N`, `uj != vj`\n- The graph is connected.\n- Multiple edges may appear; self-loops do not appear.\n\nThe constraints guarantee that a walk of length `K` visiting all vertices exists.\n\n## Output\nOutput exactly `K` integers:\n```\nx1 x2 ... xK\n```\nwhere `xt` is the clearing Vasya is at **after** minute `t` (after the `t`-th move).\n\nFeasibility requirements:\n- Vasya starts at clearing `1` at time `0`.\n- For each `t = 1..K`, the move from the previous clearing to `xt` must follow an existing trail (edge).\n- Every clearing `1..N` must appear at least once among the visited clearings at times `0..K` (including the start at time 0).\n\nIf the output is infeasible, the solution receives **0 score for that test**.\n\n## Objective\nLet `pos(t)` be Vasya’s clearing at time `t` (`pos(0)=1`, `pos(t)=xt` for `t≥1`).\n\nFor each clearing `i`, define its first-visit time:\n- `T[i] = min { t ∈ [0..K] | pos(t) = i }`\n\nTotal collected weight:\n\\[\nV = \\sum_{i=1}^{N} r[i] \\cdot T[i]\n\\]\n(Notice `T[1]=0`, so clearing 1 contributes `0`.)\n\nYou must **maximize** `V`.\n\n## Scoring\nScoring is computed **per test**.\n\n### Reference value `B`\nFor each test, the judge computes a deterministic internal reference walk from the same instance, and lets `B` be the objective value of that walk.\n\n### Per-test score\nIf `V = 0`, the per-test ratio is defined as `0`.\n\nOtherwise, for your solution value `V`, the per-test ratio is:\n\\[\n\\mathrm{ratio} = \\mathrm{clamp}\\left(\\frac{V - B}{V},\\, 0,\\, 1\\right)\n\\]\nwhere `clamp(x,0,1)=min(1,max(0,x))`.\n\n### Total score\nThe final score is the sum of per-test ratios, scaled to the total points configured for this problem.\n\n## Constraints\n- Time limit: 2 seconds\n- Memory limit: 256 MB\n\n## Example\nSample input:\n```\n4 4 6\n5 1 4 10\n1 2\n2 3\n3 4\n1 4\n```\n\nOne valid sample output:\n```\n2 3 2 1 4 3\n```\n\nExplanation (high level):\n- Path: time 0 at 1, time 1 at 2, time 2 at 3, time 3 at 2, time 4 at 1, time 5 at 4, time 6 at 3.\n- First-visit times: `T[1]=0, T[2]=1, T[3]=2, T[4]=5`.\n- Objective value: `V = 5·0 + 1·1 + 4·2 + 10·5 = 59`.\n- The judge also computes the baseline value `B` for this test, then assigns a normalized ratio using the formula above.\n```\n", "config": "checker: chk.cc\nmemory: 256m\nsubtasks:\n- n_cases: 10\n score: 100\ntime: 2s\ntype: default\n"}
131
  {"problem_id": "305", "category": "algorithmic", "statement": "```markdown\n# Cascading Flip Schedule on a Power Grid Tree\n\n## Problem\nYou operate a power grid shaped as a tree with **N** substations (vertices) and **N−1** transmission lines (edges). \nEach substation has a reversible breaker with two states:\n\n- `W` (white) = **safe to service**\n- `B` (black) = **unsafe to service**\n\nInitially, the states are given by a string **S** of length **N**.\n\nYou must **service every substation exactly once** by choosing an order and performing a cascade operation. However, servicing a substation may destabilize nearby substations by flipping breaker states.\n\n### Cascade Service Operation\nYou perform **N rounds**. In round **t** you choose a substation **P_t** that has not been serviced yet, and you:\n1. **Pay cost** equal to the number of currently-unsafe breakers (`B`) among **unserviced** substations (including the chosen one if it is `B`).\n2. **Service** substation **P_t** (it becomes “removed” and is never flipped again).\n3. For every **unserviced neighbor** of **P_t**, **flip** its breaker state (`W ↔ B`).\n\nServiced substations are removed from the system:\n- They no longer contribute to future costs.\n- Their breakers are no longer flipped.\n\n### Feasibility\nAny permutation of vertices is a valid schedule (you may service a `B` substation; it just tends to be expensive). \nYour goal is not feasibility but **minimizing total instability cost**.\n\n## Input\n```\nN\nA_1 B_1\nA_2 B_2\n…\nA_{N-1} B_{N-1}\nS\n```\n- The graph is a tree.\n- Edge `i` connects vertices `A_i` and `B_i`.\n- `S[i]` is `W` or `B`, the initial breaker state at vertex `i`.\n\n## Output\nOutput a permutation of `1..N`:\n```\nP_1 P_2 … P_N\n```\nThis is your service order.\n\nA submission is invalid if:\n- It does not contain each vertex exactly once, or\n- It contains an out-of-range index.\n\nInvalid submissions receive the worst possible score for that test.\n\n## Objective\nLet `U_t` be the set of **unserviced** vertices just before round `t` (so `U_1` is all vertices, `U_{N+1}` is empty).\n\nLet `B_t` be the number of vertices in `U_t` whose breaker is `B` at that moment.\n\nYour **total cost** is:\n\\[\nC = \\sum_{t=1}^{N} B_t\n\\]\nYou must **minimize** `C`.\n\nNotes:\n- Breaker flips happen **after** paying `B_t`.\n- Only **unserviced neighbors** are flipped.\n\n## Scoring\nThis is an **optimization** problem; lower cost is better.\n\nFor each test case, the judge computes:\n- `C_out`: cost of your output schedule.\n- `C_base`: cost of a deterministic internal reference schedule computed from that test case.\n\nYour per-test ratio is:\n\\[\ns =\n\\begin{cases}\n0 & \\text{if } C_{\\text{base}} = 0 \\\\\n\\mathrm{clamp}\\!\\left(\\frac{C_{\\text{base}} - C_{\\text{out}}}{C_{\\text{base}}},\\, 0,\\, 1\\right) & \\text{otherwise}\n\\end{cases}\n\\]\nwhere `clamp(x,0,1)=min(1,max(0,x))`.\n\nSpecial cases:\n- Invalid output: `s = 0`.\n\n### Reference cost `C_base`\n`C_base` is the cost of a deterministic internal reference schedule computed by the judge from the same test case.\n\nThe exact construction of this internal reference schedule is intentionally not part of the contestant-facing specification. For solving the problem, you should optimize `C_out` directly according to the objective above.\n\n### Total score\nThe per-test ratio `s` is scaled to the total points configured for this problem in the judge configuration; the final score is the sum of these scaled per-test contributions across all test cases.\n\n## Why this is hard\nThe cascade flips create long-range dependencies: choosing a vertex changes future states of its neighbors, which changes future costs. Minimizing the integral of “how many unsafe breakers remain over time” is closely related to difficult sequencing problems on graphs; under these constraints, exact optimization is computationally infeasible in practice, so heuristics matter.\n\nMultiple strategies can work well:\n- Greedy selection by estimated marginal impact on future `B_t`\n- Tree decompositions with local dynamic programming + recombination\n- Large neighborhood search / simulated annealing on permutations\n- Beam search over partial schedules\n- Hybrid methods (greedy initialization + local swap/2-opt/segment moves + repair)\n\n## Constraints\n- `1 ≤ N ≤ 2×10^5`\n- `1 ≤ A_i, B_i ≤ N`\n- The input graph is a tree.\n- `S` consists only of `B` and `W`.\n- Time limit: **2 seconds**\n- Memory limit: **1024 MB**\n\n## Example\nSample input:\n```\n4\n1 2\n2 3\n3 4\nWBWW\n```\n\nOne possible output:\n```\n1 2 4 3\n```\n\nExplanation (high level):\n- The judge simulates your order.\n- Each round adds the current count of `B` among remaining vertices, then flips unserviced neighbors of the chosen vertex.\n- The resulting total `C_out` is compared against the judge's deterministic reference cost `C_base`, producing a ratio `s ∈ [0, 1]` for this test which is then scaled to the configured per-test point budget.\n```\n", "config": "checker: chk.cc\nmemory: 1024m\nsubtasks:\n- n_cases: 8\n score: 100\ntime: 2s\ntype: default\n"}
132
+ {"problem_id": "306", "category": "algorithmic", "statement": "```markdown\n# Scorched Bridges Campaign\n\n## Problem\n\nThe enemy controls an archipelago of islands connected by bridges. Their headquarters is on island `1`.\n\nYou have obtained a forecast of the next `m` days. On day `i`, several islands will contain energy depots. If an island with a depot is still connected to island `1`, the enemy harvests its energy that day. If it is disconnected from island `1`, that depot is denied.\n\nYou may prepare a long-term demolition campaign:\n\n- A bridge can be **rigged** in advance, paying a one-time installation cost.\n- On any day, you may **detonate** any subset of rigged bridges, paying a per-use cost for each detonation.\n- Destroyed bridges are repaired by the enemy overnight, so each day starts from the original graph again.\n- Each rigged bridge has a limited number of times it can be detonated during the whole campaign.\n- Your demolition teams also have a daily limit on how many bridges they can blow up on each day.\n\nYour task is to output **any feasible campaign plan**. The judge will compute its total cost, combining your demolition expenses and the total energy still harvested by the enemy. Lower is better.\n\nBecause the graph is general and decisions interact across many days, exact optimization is intended to be intractable; heuristic approaches are expected.\n\n## Input\n\nThe first line contains two integers:\n\n- `n` — number of islands\n- `e` — number of bridges\n\nIslands are numbered from `1` to `n`. \nBridges are numbered from `1` to `e` in input order.\n\nThe next `e` lines each contain five integers:\n\n- `u_j, v_j` — endpoints of bridge `j`\n- `a_j` — installation cost to rig bridge `j`\n- `b_j` — cost each time bridge `j` is detonated\n- `c_j` — maximum number of days bridge `j` may be detonated over the whole campaign\n\nThen follows one integer:\n\n- `m` — number of forecast days\n\nThe next `m` lines describe the days. \nLine `i` contains:\n\n- `r_i` — number of energy depots on day `i`\n- `L_i` — maximum number of bridges you may detonate on day `i`\n- then `2 * r_i` integers:\n - `h_1, v_1, h_2, v_2, ..., h_{r_i}, v_{r_i}`\n\nmeaning island `h_t` has a depot worth `v_t` energy on day `i`.\n\n### Guarantees\n\n- The bridge graph is connected.\n- `h_t != 1` for all depots.\n- Within one day, all depot islands are distinct.\n\n## Output\n\nYour output must describe one campaign plan.\n\n- First line: one integer `x` — number of rigged bridges.\n- Second line: `x` distinct integers — the IDs of the rigged bridges, in any order. \n If `x = 0`, this line should be empty.\n\nThen output `m` lines. \nOn day `i`, output:\n\n- `d_i` — number of bridges detonated on day `i`\n- followed by `d_i` distinct bridge IDs\n\n### Feasibility requirements\n\nYour output is **feasible** iff all of the following hold:\n\n1. Every listed bridge ID is between `1` and `e`.\n2. The rigged bridge list contains no duplicates.\n3. On each day, the detonated bridge list contains no duplicates.\n4. Every detonated bridge must be rigged.\n5. For each day `i`, `d_i <= L_i`.\n6. For each bridge `j`, it is detonated on at most `c_j` different days over the entire campaign.\n\nIf your output is infeasible, the score for that test is `0`.\n\n## Objective\n\nFor each day `i`:\n\n1. Start from the original graph.\n2. Remove all bridges detonated on day `i`.\n3. Any depot island still connected to island `1` contributes its value to the enemy's harvested energy that day.\n4. Any depot island disconnected from island `1` contributes `0`.\n\nLet:\n\n- `InstallCost = sum of a_j over all rigged bridges`\n- `BlastCost = sum of b_j over all detonations on all days`\n- `Harvested = sum of values of all depots that remain connected to island 1 on their respective days`\n\nYour objective value is\n\n`F = InstallCost + BlastCost + Harvested`\n\nYou must **minimize** `F`.\n\n## Scoring\n\nFor each test file, define the baseline solution as:\n\n- rig no bridges,\n- detonate no bridges on every day.\n\nIts objective value is\n\n`B = sum of all depot values on all days`.\n\nFor a feasible submission with objective value `F`, the test score is\n\n`Score_test = min(1000, 100 * B / max(1, F))`\n\nAn infeasible submission receives `Score_test = 0`.\n\nThe final score is the arithmetic mean of `Score_test` over all test files.\n\nNotes:\n\n- The baseline always scores exactly `100` on every test.\n- Better solutions score higher than `100`.\n- A solution at least `10` times better than the baseline is capped at `1000` on that test.\n\n## Constraints\n\n- `2 <= n <= 2 * 10^5`\n- `n - 1 <= e <= 3 * 10^5`\n- `1 <= m <= 2 * 10^5`\n- `1 <= u_j, v_j <= n`, `u_j != v_j`\n- `1 <= a_j, b_j <= 10^6`\n- `1 <= c_j <= 20`\n- `1 <= r_i < n`\n- `0 <= L_i <= 20`\n- `1 <= v_t <= 10^6`\n- `sum r_i <= 5 * 10^5`\n- `sum L_i <= 5 * 10^5`\n\n## Constraints\n- Time limit: 8 seconds\n- Memory limit: 512 MB\n\n## Example\n\n### Input\n```text\n5 4\n1 2 5 2 2\n2 3 2 1 1\n2 4 2 1 1\n1 5 4 2 1\n2\n2 1 3 10 4 8\n2 2 5 12 3 5\n```\n\n### Output\n```text\n2\n1 4\n1 1\n2 1 4\n```\n\n### Explanation\n\n- Rig bridges `1` and `4`.\n- Day 1: detonate bridge `1` (`1-2`), disconnecting islands `3` and `4`.\n- Day 2: detonate bridges `1` and `4`, disconnecting islands `3` and `5`.\n\nCosts:\n\n- Installation: `5 + 4 = 9`\n- Detonation: day 1 uses bridge `1` (`2`), day 2 uses bridges `1` and `4` (`2 + 2`), total `6`\n- Harvested energy: `0`\n\nSo `F = 9 + 6 + 0 = 15`.\n\nBaseline value:\n- Day 1: `10 + 8 = 18`\n- Day 2: `12 + 5 = 17`\n- `B = 35`\n\nTherefore this output gets\n\n`Score_test = 100 * 35 / 15 = 233.333...`\n```", "config": "checker: chk.cc\nmemory: 512m\nsubtasks:\n- n_cases: 10\n score: 100\ntime: 8s\ntype: default\n"}
133
+ {"problem_id": "307", "category": "algorithmic", "statement": "```markdown\n# Mobile Relay Layout\n\n## Problem\n\nA field-training area contains `N` fixed sensors. Sensor `j` is located at coordinates `(x_j, y_j)` and must upload `d_j` units of data to exactly one mobile relay hub.\n\nYou may deploy up to `K` relay hubs. Each hub can be placed at any real-valued coordinate.\n\nIf hub `i` is placed at `(X_i, Y_i)` and is assigned a non-empty set of sensors `S_i`, then:\n\n- its **squared service radius** is\n\n\\[\nR_i^2 = \\max_{j \\in S_i} \\left((X_i-x_j)^2 + (Y_i-y_j)^2\\right)\n\\]\n\n- its **load** is\n\n\\[\nL_i = \\sum_{j \\in S_i} d_j\n\\]\n\n- its **battery cost** is\n\n\\[\n\\text{cost}_i = P + A \\cdot R_i^2 + B \\cdot L_i^2\n\\]\n\nwhere `P`, `A`, and `B` are given constants.\n\nEmpty hubs are allowed in the output, but they contribute nothing and are ignored by the judge.\n\nYour task is to choose the number of hubs, their positions, and the assignment of every sensor so that the **total battery cost** is as small as possible.\n\nThis is an optimization problem: every feasible output receives a score based on how good its total cost is.\n\n---\n\n## Input\n\nThe input contains a single test case.\n\n- First line: two integers `N` and `K`\n- Second line: three real numbers `P`, `A`, and `B`\n- Next `N` lines: three real numbers `x_j`, `y_j`, and `d_j`\n\n### Meaning\n\n- `N`: number of sensors\n- `K`: maximum number of relay hubs you may deploy\n- `P`: fixed activation cost of each non-empty hub\n- `A`: coefficient for coverage radius cost\n- `B`: coefficient for load-balancing cost\n- `(x_j, y_j)`: position of sensor `j`\n- `d_j`: data amount of sensor `j`\n\nSensors are numbered from `1` to `N` in input order.\n\n---\n\n## Output\n\nYour output must describe one feasible relay layout.\n\n- First line: one integer `M` — the number of hubs you output (`1 <= M <= K`)\n- Next `M` lines: two real numbers `X_i` and `Y_i` — the coordinates of hub `i`\n- Then output `N` integers `a_1, a_2, ..., a_N` (separated by arbitrary whitespace), where `a_j` is the hub index assigned to sensor `j`\n\n### Feasibility requirements\n\nYour output is **feasible** if and only if all of the following hold:\n\n1. `1 <= M <= K`\n2. Every printed hub coordinate is finite and satisfies `|X_i|, |Y_i| <= 10^9`\n3. For every sensor `j`, the assignment `a_j` is an integer in `[1, M]`\n\nIf any requirement is violated, the submission is invalid and receives score `0` on that test.\n\n---\n\n## Objective\n\nFor each hub `i`, let\n\n\\[\nS_i = \\{j \\mid a_j = i\\}\n\\]\n\nIf `S_i` is empty, hub `i` contributes `0`.\n\nOtherwise:\n\n\\[\nR_i^2 = \\max_{j \\in S_i} \\left((X_i-x_j)^2 + (Y_i-y_j)^2\\right)\n\\]\n\n\\[\nL_i = \\sum_{j \\in S_i} d_j\n\\]\n\n\\[\n\\text{cost}_i = P + A \\cdot R_i^2 + B \\cdot L_i^2\n\\]\n\nThe total objective value is\n\n\\[\nC = \\sum_{i=1}^{M} \\text{cost}_i\n\\]\n\nYour goal is to **minimize `C`**.\n\nThe judge computes all values using `long double`.\n\n---\n\n## Scoring\n\nFor each test, the judge also computes a deterministic **baseline** solution:\n\n1. Sort sensors by `(x_j, y_j, j)`.\n2. Split the sorted list into `K` consecutive blocks:\n - block `t` contains indices from \n \\[\n \\left\\lfloor \\frac{(t-1)N}{K} \\right\\rfloor + 1\n \\quad \\text{to} \\quad\n \\left\\lfloor \\frac{tN}{K} \\right\\rfloor\n \\]\n in the sorted order, for `t = 1..K`\n3. Ignore empty blocks.\n4. For each non-empty block:\n - create one hub at the arithmetic mean of the block's sensor coordinates\n - assign every sensor in that block to that hub\n5. Let the baseline total cost be `C_base`\n\nIf your solution has total cost `C`, then your per-test score is\n\n\\[\n\\text{score} = 10^6 \\cdot \\frac{C_{base}}{C_{base} + C}\n\\]\n\nProperties:\n\n- If your solution matches the baseline exactly, you get `500000`\n- Better-than-baseline solutions get more than `500000`\n- Worse-than-baseline solutions get less than `500000`\n- Invalid outputs get `0`\n\nThe final score is the arithmetic mean of per-test scores over all official tests.\n\n---\n\n## Constraints\n\n- `1 <= N <= 200000`\n- `1 <= K <= 100`\n- `0 < P, A, B <= 10^6`\n- `|x_j|, |y_j| <= 10^6`\n- `0 < d_j <= 10^6`\n\n## Constraints\n- Time limit: 4 seconds\n- Memory limit: 512 MB\n\n---\n\n## Example\n\n### Input\n```text\n6 2\n10 1 0.5\n0 0 2\n1 0 1\n0 1 1\n10 0 2\n10 1 1\n11 0 1\n```\n\n### Output\n```text\n2\n0.3333333333 0.3333333333\n10.3333333333 0.3333333333\n1 1 1 2 2 2\n```\n\n### Explanation\n\nThe first hub serves sensors `1,2,3`, and the second serves `4,5,6`.\n\nFor each hub:\n\n- load `L = 2+1+1 = 4`\n- squared radius \n \\[\n R^2 = \\max\\left(\\frac{2}{9}, \\frac{5}{9}, \\frac{5}{9}\\right) = \\frac{5}{9}\n \\]\n- cost \n \\[\n 10 + 1 \\cdot \\frac{5}{9} + 0.5 \\cdot 4^2 = 18.555\\ldots\n \\]\n\nSo the total cost is approximately:\n\n\\[\nC = 37.111\\ldots\n\\]\n\nFor this instance, the deterministic baseline produces the same partition, so `C = C_base`, and the score is exactly:\n\n\\[\n10^6 \\cdot \\frac{C_base}{C_base + C} = 500000\n\\]\n```", "config": "checker: chk.cc\nmemory: 512m\nsubtasks:\n- n_cases: 10\n score: 100\ntime: 4s\ntype: default\n"}
134
+ {"problem_id": "308", "category": "algorithmic", "statement": "```markdown\n# Farmwide Teleport Pad Deployment\n\n## Problem\n\nFarmer John is upgrading his manure logistics again.\n\nThis time, instead of building a single teleporter, he may install a **network of teleport pads** at selected road intersections across the farm. The farm road system is modeled as a connected, undirected, weighted graph.\n\nThere are `N` manure shipments. Shipment `i` must be moved from intersection `s_i` to intersection `t_i`. Each shipment is transported independently.\n\nIf Farmer John installs a set of teleport pads, then for any shipment he may choose either:\n\n1. **Drive directly** from `s_i` to `t_i`, or\n2. **Use the teleport network once**:\n - drive from `s_i` to any installed pad,\n - teleport instantly and for free to any other installed pad,\n - drive from that pad to `t_i`.\n\nTeleportation between installed pads has zero cost and unlimited capacity.\n\nHowever, each candidate pad location has a construction cost, and the total construction cost must not exceed the budget.\n\nYour task is to choose which candidate pad locations to build in order to minimize the total driving distance over all shipments.\n\nThis is an **optimization challenge**: better solutions receive higher scores.\n\n---\n\n## Input\n\nThe input describes one test file.\n\n- The first line contains five integers \n `V E M N C`\n - `V`: number of intersections (`1..V`)\n - `E`: number of roads\n - `M`: number of candidate teleport-pad sites\n - `N`: number of shipments\n - `C`: total construction budget\n\n- The next `E` lines each contain three integers \n `u v w` \n meaning there is an undirected road between intersections `u` and `v` with length `w`.\n\n- The next `M` lines each contain two integers \n `p_j cost_j` \n meaning candidate site `j` is located at intersection `p_j` and costs `cost_j` to build.\n\n- The next `N` lines each contain two integers \n `s_i t_i` \n describing a shipment from `s_i` to `t_i`.\n\nAll road lengths and construction costs are positive integers.\n\nThe graph is connected.\n\n---\n\n## Output\n\nOutput a feasible set of candidate sites to build.\n\n- The first line must contain a single integer `K` — the number of chosen sites.\n- The next `K` lines must each contain one integer: the index of a chosen candidate site (an integer from `1` to `M`).\n\n### Feasibility requirements\n\nYour output is **feasible** iff all of the following hold:\n\n- `0 <= K <= M`\n- all chosen indices are distinct\n- each chosen index is between `1` and `M`\n- the sum of construction costs of the chosen sites is at most `C`\n\nIf your output is infeasible, your score for that test file is `0`.\n\n---\n\n## Objective\n\nLet `dist(a,b)` be the shortest-path distance between intersections `a` and `b` in the road graph.\n\nLet `S` be the set of chosen candidate sites, and let `P(S)` be their intersections.\n\nFor shipment `i`, define:\n\n- Direct cost:\n `direct_i = dist(s_i, t_i)`\n\n- Teleport-assisted cost:\n - if `S` is empty, this cost is treated as `+infinity`\n - otherwise \n `tele_i = min_{x in P(S)} dist(s_i, x) + min_{y in P(S)} dist(t_i, y)`\n\nThe shipment cost is\n\n`d_i = min(direct_i, tele_i)`\n\nThe objective value of your output is\n\n`O = sum_{i=1..N} d_i`\n\nYour goal is to **minimize** `O`.\n\n---\n\n## Scoring\n\nFor each test file, define the **baseline** solution as building no pads at all.\n\nIts objective value is therefore\n\n`B = sum_{i=1..N} dist(s_i, t_i)`\n\nFor a feasible submission with objective value `O`, the score for that test file is\n\n`score = round(1,000,000 * max(0, min(1, (B - O) / B )))`\n\nSince direct transport is always allowed, any feasible solution satisfies `O <= B`, so this is simply the relative improvement over the baseline, scaled to `1,000,000`.\n\n- Baseline solution: score `0`\n- Better solutions: higher scores\n- Perfectly eliminating all driving distance: score `1,000,000`\n\nIf your output is infeasible, the score is `0`.\n\nThe total score of a submission is the sum of its scores over all test files.\n\n---\n\n## Constraints\n\n- `2 <= V <= 8000`\n- `V-1 <= E <= 40000`\n- `1 <= M <= 3000`\n- `1 <= N <= 100000`\n- `1 <= C <= 10^12`\n- `1 <= w <= 10^9`\n- `1 <= cost_j <= 10^9`\n- `1 <= u, v, p_j, s_i, t_i <= V`\n- `s_i != t_i`\n- candidate site intersections `p_j` are distinct\n\nThe exact optimum is intended to be computationally difficult in general; heuristic and approximation methods are expected.\n\n- Time limit: 4 seconds\n- Memory limit: 1024 MB\n\n---\n\n## Example\n\n### Sample input\n```text\n5 6 3 3 7\n1 2 4\n2 3 4\n3 4 4\n4 5 4\n1 5 20\n2 5 7\n2 3\n4 4\n5 5\n1 4\n1 5\n3 5\n```\n\n### Sample output\n```text\n2\n1\n2\n```\n\n### Explanation\n\nThere are 3 candidate pad sites:\n\n- site 1 at intersection 2, cost 3\n- site 2 at intersection 4, cost 4\n- site 3 at intersection 5, cost 5\n\nThe sample output builds sites 1 and 2, with total cost `3 + 4 = 7`, which fits the budget.\n\nShortest direct shipment costs are:\n\n- `1 -> 4`: `12`\n- `1 -> 5`: `11`\n- `3 -> 5`: `8`\n\nSo the baseline is `B = 31`.\n\nWith pads at intersections 2 and 4:\n\n- `1 -> 4`: drive `1 -> 2` (4), teleport `2 -> 4` (0), drive `4 -> 4` (0), total `4`\n- `1 -> 5`: drive `1 -> 2` (4), teleport `2 -> 4` (0), drive `4 -> 5` (4), total `8`\n- `3 -> 5`: best remains `8`\n\nThus `O = 4 + 8 + 8 = 20`.\n\nRelative improvement is `(31 - 20) / 31 = 11/31`, so the score for this file is approximately `354,839`.\n```", "config": "checker: chk.cc\nmemory: 1024m\nsubtasks:\n- n_cases: 10\n score: 100\ntime: 4s\ntype: default\n"}
135
+ {"problem_id": "309", "category": "algorithmic", "statement": "```markdown\n# Archipelago Relay Network Design\n\n## Problem\nThe Republic of AtCoder consists of `L+1` islands aligned west-to-east, numbered `0` to `L`.\n\nFor each `1 <= k <= L`, there is a bidirectional air route between islands `k-1` and `k`.\nRoute `k` is operated by company `S_k`, which is either `A` or `J`.\n\nThe government now wants to establish a **permanent cargo relay network** for daily shipments.\n\nThere are `N` residents who may be hired as shuttle operators.\n\n- Resident `i` lives on island `X_i`.\n- They own a company coupon `C_i` (`A` or `J`).\n- Hiring them costs a fixed management fee `H_i`.\n- If hired, they can operate **one** bidirectional shuttle service between two islands `l_i < r_i` such that `r_i - l_i <= D_i`.\n\nA hired resident creates a direct bidirectional shuttle edge between `l_i` and `r_i`.\n\n### Coupon rule\nWhen a resident travels along a route owned by their coupon company, that route is free for them.\nOtherwise, it costs `1`.\n\nTherefore:\n\n- The **operating cost per unit cargo** of resident `i`'s shuttle `(l_i, r_i)` is the number of routes on the path from `l_i` to `r_i` whose owner is **not** `C_i`.\n- The **setup cost** of hiring resident `i` for shuttle `(l_i, r_i)` is\n\n`H_i + min(cost_i(X_i, l_i), cost_i(X_i, r_i))`\n\nwhere `cost_i(u, v)` is the number of routes on the path between islands `u` and `v` whose owner is **not** `C_i`.\n\nIn addition to hired shuttles, the government may always use the original adjacent-island routes directly for cargo transport at cost `1` per unit cargo per route.\n\n---\n\nThere are `M` daily cargo demands.\n\nDemand `j` requires shipping `W_j` units of cargo from island `A_j` to island `B_j` every day.\n\nFor a fixed set of hired shuttles, each demand is transported independently along a **minimum-cost path** in the resulting graph:\n\n- vertices: islands `0..L`\n- always-available edges: `(k-1, k)` with cost `1`\n- hired shuttle edges: `(l_i, r_i)` with cost equal to that resident's operating cost\n\nThe total daily cost is:\n\n- sum of setup costs of all hired residents\n- plus, for each demand, `W_j × (shortest path cost between A_j and B_j)`\n\nYour task is to output **any feasible relay design**. Better designs get better scores.\n\n## Input\nThe input is given in the following format:\n\n```text\nL N M\nS\nX_1 C_1 H_1 D_1\nX_2 C_2 H_2 D_2\n...\nX_N C_N H_N D_N\nA_1 B_1 W_1\nA_2 B_2 W_2\n...\nA_M B_M W_M\n```\n\n- `S` is a string of length `L`\n- `S_k` is `A` or `J`, representing the owner of the route between islands `k-1` and `k`\n\n## Output\nOutput exactly `N` lines.\n\nFor each resident `i`, output one of the following:\n\n- `-1` \n meaning resident `i` is not hired\n\n- `l_i r_i` \n meaning resident `i` is hired to operate a shuttle between islands `l_i` and `r_i`\n\n### Feasibility requirements\nIf resident `i` is hired, the following must hold:\n\n- `0 <= l_i < r_i <= L`\n- `r_i - l_i <= D_i`\n\nIf any line is malformed or any hired resident violates these conditions, the output is infeasible.\n\n## Objective\nMinimize the total daily cost:\n\n```text\nTotalCost =\n(sum of setup costs of hired residents)\n+ (sum over demands of W_j × shortest_path_cost(A_j, B_j))\n```\n\n### Definitions\nFor resident `i`, let:\n\n- `bad_i(u, v)` = number of route indices `k` on the path between islands `u` and `v` such that `S_k != C_i`\n\nThen for a hired shuttle `(l_i, r_i)`:\n\n- setup cost = `H_i + min(bad_i(X_i, l_i), bad_i(X_i, r_i))`\n- shuttle edge cost = `bad_i(l_i, r_i)`\n\nThe shortest path for each demand is computed in the graph consisting of:\n\n- adjacent-island edges `(k-1, k)` of cost `1`\n- all hired shuttle edges, bidirectional, with their shuttle edge costs\n\n## Scoring\nThis is an optimization problem. Lower `TotalCost` is better.\n\nFor each test file:\n\n- Let `B` be the baseline cost obtained by hiring nobody. \n Then all shipments use only adjacent-island routes, so\n\n```text\nB = sum over demands of W_j × |A_j - B_j|\n```\n\n- Let `U` be your output's `TotalCost`.\n\nIf your output is infeasible, the score for that test file is `0`.\n\nOtherwise, the score is:\n\n```text\nScore = floor(10^9 × min(5, B / U))\n```\n\n- The baseline solution always scores exactly `10^9`.\n- Better-than-baseline solutions score more than `10^9`.\n- Scores are capped at `5 × 10^9` per test file.\n\nThe final score is the sum of scores over all test files.\n\n## Constraints\n- `1 <= L <= 5000`\n- `1 <= N <= 5000`\n- `1 <= M <= 20000`\n- `S_k` is `A` or `J`\n- `0 <= X_i <= L`\n- `C_i` is `A` or `J`\n- `0 <= H_i <= 10^9`\n- `1 <= D_i <= L`\n- `0 <= A_j, B_j <= L`\n- `A_j != B_j`\n- `1 <= W_j <= 10^6`\n\n## Constraints\n- Time limit: 5 seconds\n- Memory limit: 1024 MB\n\n## Example\n### Sample Input\n```text\n6 3 3\nAAJJAJ\n0 A 1 3\n6 J 1 3\n3 A 4 6\n0 6 10\n1 5 4\n2 4 5\n```\n\n### Sample Output\n```text\n0 3\n3 6\n-1\n```\n\n### Explanation\n- Resident 1 operates shuttle `(0, 3)`.\n - Path owner string: `AAJ`\n - With coupon `A`, the shuttle edge cost is `1`\n - Setup cost is `1 + min(0, 1) = 1`\n\n- Resident 2 operates shuttle `(3, 6)`.\n - Path owner string: `JAJ`\n - With coupon `J`, the shuttle edge cost is `1`\n - Setup cost is `1 + min(1, 0) = 1`\n\n- Resident 3 is not hired.\n\nSo the fixed setup cost is `2`.\n\nThe resulting graph has:\n- normal edges of cost `1` between consecutive islands\n- shuttle edges `(0,3)` and `(3,6)`, each of cost `1`\n\nDemand costs:\n- `0 -> 6`, volume `10`: shortest path cost `2`, contributes `20`\n- `1 -> 5`, volume `4`: shortest path cost `4`, contributes `16`\n- `2 -> 4`, volume `5`: shortest path cost `2`, contributes `10`\n\nTotal cost:\n```text\n2 + 20 + 16 + 10 = 48\n```\n\nBaseline cost:\n```text\n10×6 + 4×4 + 5×2 = 86\n```\n\nScore for this test file:\n```text\nfloor(10^9 × 86 / 48) = 1791666666\n```\n```", "config": "checker: chk.cc\nmemory: 1024m\nsubtasks:\n- n_cases: 10\n score: 100\ntime: 5s\ntype: default\n"}
136
+ {"problem_id": "310", "category": "algorithmic", "statement": "```markdown\n# Metallic Pink Resonator Layout\n\n## Problem\nThe Martians have built a circular relay with ports labeled `0,1,…,M-1`. \nSome ports will be equipped with **pink emitters**; the rest remain **plain reflectors**.\n\nIf port `a` is an emitter and port `b` is a reflector, then together they can generate the frequency\n\n\\[\n(a+b)\\bmod M.\n\\]\n\nFor each frequency `r`, the Martians know:\n\n- a **value** `w_r` gained for each successful generating pair producing `r`,\n- a **saturation limit** `d_r`: once `d_r` pairs producing `r` exist, extra pairs for `r` give no additional benefit.\n\nYou must choose which ports become emitters, subject to a budget.\n\nLet `A` be the set of chosen emitters, and `B = {0,1,…,M-1} \\ A` be the reflectors. \nFor each residue `r`, define\n\n\\[\nc_r = |\\{(a,b)\\in A\\times B : (a+b)\\bmod M = r\\}|,\n\\]\n\nwhere pairs are **ordered**: choosing emitter `a` and reflector `b` is one pair.\n\nThe contribution of residue `r` is\n\n\\[\nw_r \\cdot \\min(c_r, d_r).\n\\]\n\nYour task is to output any feasible emitter set maximizing the total contribution.\n\n---\n\n## Input\nA single test file contains one instance.\n\n- The first line contains two integers `M` and `B` — the number of ports and the total budget.\n- The second line contains `M` integers `cost_0, cost_1, …, cost_{M-1}` — the cost of installing an emitter at each port.\n- The third line contains `M` integers `w_0, w_1, …, w_{M-1}` — the value of each residue.\n- The fourth line contains `M` integers `d_0, d_1, …, d_{M-1}` — the saturation limit of each residue.\n\nAll residue arithmetic is modulo `M`.\n\n---\n\n## Output\nOutput any feasible solution.\n\n- The first line must contain one integer `K` — the number of chosen emitter ports.\n- The second line must contain `K` distinct integers `p_1, p_2, …, p_K` in increasing order, each between `0` and `M-1`, denoting the emitter ports.\n\nA solution is **feasible** if:\n\n1. all listed ports are distinct,\n2. all listed ports are valid indices in `[0, M-1]`,\n3. \\(\\sum_{i=1}^{K} cost_{p_i} \\le B\\).\n\nIf your output is infeasible or malformed, your objective value is `0`.\n\nIf `K = 0`, you may omit the second line.\n\n---\n\n## Objective\nFor your chosen emitter set `A` and reflector set `B = [0, M-1] \\ A`, compute for each residue `r`:\n\n\\[\nc_r = |\\{(a,b)\\in A\\times B : (a+b)\\bmod M = r\\}|.\n\\]\n\nYour objective value is\n\n\\[\nU = \\sum_{r=0}^{M-1} w_r \\cdot \\min(c_r, d_r).\n\\]\n\nHigher is better.\n\n---\n\n## Scoring\nFor each official test instance, the judge also computes a deterministic **baseline** solution:\n\n1. Sort all ports by `(cost_i, i)` ascending.\n2. Traverse this order once.\n3. Add port `i` to the emitter set iff doing so keeps the total cost at most `B`.\n\nLet the baseline objective value be `U_base`, and your objective value be `U`.\n\nThe score for that test is:\n\n- `0`, if `U = 0` and `U_base = 0`;\n- otherwise\n\n\\[\n100 \\cdot \\frac{U}{U + U_{base}}.\n\\]\n\nSo:\n- matching the baseline gives `50`,\n- worse than the baseline gives less than `50`,\n- better than the baseline gives more than `50`,\n- the score approaches `100` as `U` becomes much larger than `U_base`.\n\nYour final score is the arithmetic mean of your per-test scores over all official test instances.\n\n---\n\n## Constraints\n- `2 ≤ M ≤ 200000`\n- `1 ≤ cost_i ≤ 10^9`\n- `1 ≤ w_i ≤ 10^6`\n- `1 ≤ d_i ≤ M`\n- `1 ≤ B ≤ 10^18`\n- At least one port satisfies `cost_i ≤ B`\n\nThe search space is exponential in `M`; exact optimization is not expected.\n\n- Time limit: 8 seconds\n- Memory limit: 1024 MB\n\n---\n\n## Example\nInput\n```text\n6 5\n3 2 2 4 1 3\n5 1 4 2 3 6\n1 2 1 1 2 1\n```\n\nOutput\n```text\n3\n1 2 4\n```\n\nBrief explanation:\n\n- Chosen emitters: `{1,2,4}`\n- Total cost: `2 + 2 + 1 = 5`, so the solution is feasible.\n- Reflectors: `{0,3,5}`\n\nOrdered emitter-reflector pairs generate residues with counts:\n\n- residue `0`: 1 pair\n- residue `1`: 3 pairs\n- residue `2`: 1 pair\n- residue `3`: 1 pair\n- residue `4`: 2 pairs\n- residue `5`: 1 pair\n\nAfter applying saturation limits `d = [1,2,1,1,2,1]`, the objective is:\n\n\\[\n5\\cdot1 + 1\\cdot2 + 4\\cdot1 + 2\\cdot1 + 3\\cdot2 + 6\\cdot1 = 25.\n\\]\n\nFor this instance, the baseline picks the same set, so `U = U_base = 25`, and the test score is\n\n\\[\n100 \\cdot \\frac{25}{25+25} = 50.\n\\]\n```", "config": "checker: chk.cc\nmemory: 1024m\nsubtasks:\n- n_cases: 10\n score: 100\ntime: 8s\ntype: default\n"}
137
+ {"problem_id": "311", "category": "algorithmic", "statement": "```markdown\n# Resonant Bay Layout\n\n## Problem\n\nA research lab wants to place `n` oscillators on a long straight rail with numbered bays `0, 1, ..., m-1`.\n\nOscillator `i` has an intrinsic phase ratio `p_i / q_i`. Some pairs of oscillators are connected by coupling channels. If oscillators `u` and `v` are placed `d = |x_u - x_v|` bays apart, then channel `(u, v)` produces energy\n\n\\[\nE_{u,v}(d)\n=\nw_{u,v}\n\\cdot\n\\left|\\sin\\left(\\pi \\frac{p_u}{q_u} d\\right)\\right|\n\\cdot\n\\left|\\sin\\left(\\pi \\frac{p_v}{q_v} d\\right)\\right|.\n\\]\n\nYou must assign every oscillator to a **distinct integer bay**. Your goal is to maximize the total produced energy over all channels.\n\nThis is an **optimization challenge**: any feasible output is accepted, and better layouts receive better scores.\n\n## Input\n\nThe first line contains an integer `t` — the number of test cases.\n\nFor each test case:\n\n- The first line contains three integers `n`, `m`, and `r`:\n - `n` — number of oscillators\n - `m` — number of bays\n - `r` — number of coupling channels\n- The next `n` lines each contain two integers `p_i` and `q_i`.\n- The next `r` lines each contain three integers `u`, `v`, and `w` describing a channel between oscillators `u` and `v` with weight `w`.\n\nOscillators are numbered from `1` to `n`.\n\nThere are no self-loops and no repeated channels.\n\n## Output\n\nFor each test case, output one line containing `n` integers:\n\n\\[\nx_1, x_2, \\dots, x_n\n\\]\n\nwhere `x_i` is the bay chosen for oscillator `i`.\n\nA solution is **feasible** for a test case if and only if:\n\n- `0 <= x_i < m` for all `i`\n- all `x_i` are pairwise distinct\n\nIf a test case output is infeasible, its objective value is defined as `0`.\n\n## Objective\n\nFor a feasible layout, let\n\n\\[\nd_{u,v} = |x_u - x_v|.\n\\]\n\nThe total energy is\n\n\\[\nF\n=\n\\sum_{(u,v)\\in \\text{channels}}\nw_{u,v}\n\\cdot\n\\left|\\sin\\left(\\pi \\frac{p_u}{q_u} d_{u,v}\\right)\\right|\n\\cdot\n\\left|\\sin\\left(\\pi \\frac{p_v}{q_v} d_{u,v}\\right)\\right|.\n\\]\n\nYou must **maximize** `F`.\n\n### Judge computation details\n\nFor each factor, the judge may reduce the angle using periodicity before evaluating sine:\n\n\\[\n\\sin\\left(\\pi \\frac{p_i}{q_i} d\\right)\n=\n\\sin\\left(\\pi \\frac{(p_i d \\bmod 2q_i)}{q_i}\\right).\n\\]\n\nThis is mathematically equivalent and avoids large angles.\n\n## Scoring\n\nFor each test case, a deterministic **baseline layout** is defined as follows:\n\n1. Compute the weighted degree of each oscillator:\n \\[\n \\deg(i) = \\sum_{(i,j)\\in \\text{channels}} w_{i,j}.\n \\]\n2. Sort oscillators by decreasing `deg(i)`, breaking ties by smaller index.\n3. Define baseline bays:\n - if `n = 1`, the only bay is `0`\n - otherwise, for `k = 0, 1, ..., n-1`:\n \\[\n b_k = \\left\\lfloor \\frac{k(m-1)}{n-1} \\right\\rfloor\n \\]\n4. Assign the `k`-th oscillator in the sorted order to bay `b_k`.\n\nLet `B` be the objective value of this baseline layout, and let `F` be the objective value of your output.\n\nThe score for that test case is\n\n\\[\nS\n=\n10^6\n\\cdot\n\\operatorname{clamp}\\left(\n\\frac{F+1}{B+1},\n0,\n2\n\\right),\n\\]\n\nwhere\n\n\\[\n\\operatorname{clamp}(x,0,2)=\n\\begin{cases}\n0 & x<0\\\\\nx & 0\\le x\\le 2\\\\\n2 & x>2\n\\end{cases}\n\\]\n\nThe score of an input file is the arithmetic mean of its test case scores.\n\nHigher is better.\n\n## Constraints\n\n- `1 <= t <= 20`\n- `2 <= n <= 400`\n- `n <= m <= 10^9`\n- `1 <= r <= min(30000, n(n-1)/2)`\n- `1 <= p_i, q_i <= 10^9`\n- `1 <= w <= 10^6`\n\nAcross one input file:\n\n- `sum(n) <= 4000`\n- `sum(r) <= 120000`\n\n- Time limit: 8 seconds\n- Memory limit: 512 MB\n\n## Example\n\n### Input\n```text\n1\n4 7 4\n1 2\n1 3\n2 5\n1 4\n1 2 10\n1 3 7\n2 4 8\n3 4 6\n```\n\n### Output\n```text\n0 3 5 1\n```\n\n### Explanation\nThis places the 4 oscillators in distinct bays:\n\n- oscillator 1 at bay 0\n- oscillator 2 at bay 3\n- oscillator 3 at bay 5\n- oscillator 4 at bay 1\n\nFor each channel, the judge computes the bay distance, evaluates the two sine factors, multiplies by the channel weight, and sums the results.\n\nThe baseline layout is built from weighted-degree order and evenly spaced bays. Your score depends continuously on how your total energy compares to that baseline.\n```", "config": "checker: chk.cc\nmemory: 512m\nsubtasks:\n- n_cases: 10\n score: 100\ntime: 8s\ntype: default\n"}
138
+ {"problem_id": "312", "category": "algorithmic", "statement": "```markdown\n# Park Ranger Shift Balancing\n\n## Problem\nThe city wants to inspect every trail in a large park during one night.\n\nThe park has `n` glades, numbered `1` to `n`, and `m` undirected trails, numbered `1` to `m`. \nTrail `i` connects glades `x_i` and `y_i` and has length `c_i`.\n\n- A trail may be a self-loop (`x_i = y_i`).\n- Several different trails may connect the same pair of glades.\n\nThere are `k` ranger teams. Every team starts at glade `1`, walks along trails, and must return to glade `1` by the end of its shift.\n\nA team may traverse any trail any number of times. However, **every original trail must be traversed at least once by some team** so that it gets inspected.\n\nYour task is to output one closed walk for each team so that all trails are inspected, while balancing the teams as well as possible.\n\n## Input\nThe first line contains three integers:\n\n`n m k`\n\n- `1 ≤ n ≤ 2 · 10^5`\n- `1 ≤ m ≤ 2 · 10^5`\n- `1 ≤ k ≤ 40`\n\nThe next `m` lines describe the trails. \nLine `i + 1` contains three integers:\n\n`x_i y_i c_i`\n\n- `1 ≤ x_i, y_i ≤ n`\n- `1 ≤ c_i ≤ 10^9`\n\nIt is guaranteed that every glade incident to at least one trail is reachable from glade `1`.\n\n## Output\nOutput exactly `k` route descriptions, one for each ranger team.\n\nFor team `j`, output:\n\n`t_j a_{j,1} a_{j,2} ... a_{j,t_j}`\n\nwhere:\n\n- `t_j ≥ 0` is the number of trail traversals in team `j`'s walk,\n- each `a_{j,p}` is a nonzero signed integer with `|a_{j,p}|` between `1` and `m`.\n\nInterpretation of a signed trail id:\n\n- if `a = +i`, the team traverses trail `i` from `x_i` to `y_i`,\n- if `a = -i`, the team traverses trail `i` from `y_i` to `x_i`.\n\nA solution is **feasible** iff all of the following hold:\n\n1. Team `j` starts at glade `1`.\n2. For every consecutive traversal in team `j`'s list, the departure glade of the next signed trail equals the current glade.\n3. After its last traversal, team `j` is back at glade `1`.\n4. Every trail id `1..m` appears at least once in at least one team's list.\n\nEmpty walks are allowed: `t_j = 0`.\n\nThe judge treats all whitespace equally, so route descriptions may span multiple lines if desired.\n\n## Objective\nFor each team `j`, let `L_j` be the total length of all traversals in its walk, counting repeated traversals each time.\n\nYour objective value is\n\n`A = max(L_1, L_2, ..., L_k)`\n\nwhich must be **minimized**.\n\n## Scoring\nFor each test case, the judge first computes a deterministic baseline value `B`:\n\n1. Compute shortest-path distances `dist(v)` from glade `1` to every glade.\n2. For each trail `i = (x_i, y_i, c_i)`, define its standalone round-trip cost\n `τ_i = dist(x_i) + c_i + dist(y_i)`.\n3. Sort all trails by decreasing `τ_i` \n (break ties by smaller trail id).\n4. Process trails in that order and assign each trail to the currently least-loaded team \n (break ties by smaller team index).\n5. Let `B` be the maximum load of any team after all assignments.\n\nThis baseline corresponds to inspecting each trail separately by going from glade `1` to one endpoint, traversing the trail once, and returning from the other endpoint to glade `1`, with greedy load balancing.\n\nFor a feasible submission with objective value `A`, the test score is\n\n`score = 100000 · min(2, B / A)`\n\nFor an infeasible submission, the test score is `0`.\n\nThe final score is the arithmetic mean of test scores over all test cases.\n\nNotes:\n\n- The baseline always scores `100000` on every test.\n- A solution twice as good as the baseline, or better, gets the capped score `200000` on that test.\n\n## Constraints\n- Time limit: 5 seconds\n- Memory limit: 512 MB\n\n## Example\n### Sample input\n```text\n4 4 2\n1 2 3\n2 3 2\n3 1 4\n1 4 5\n```\n\n### Sample output\n```text\n3 1 2 3\n2 4 -4\n```\n\n### Explanation\n- Team 1 walks along trails `1, 2, 3`, i.e. `1 -> 2 -> 3 -> 1`, for total length `3 + 2 + 4 = 9`.\n- Team 2 walks `1 -> 4 -> 1` using trail `4` twice, for total length `5 + 5 = 10`.\n\nAll four trails are inspected at least once, and both teams return to glade `1`, so the solution is feasible.\n\nThe objective value is `A = max(9, 10) = 10`.\n\nFor the baseline:\n- `dist(1)=0`, `dist(2)=3`, `dist(3)=4`, `dist(4)=5`\n- standalone costs are `6, 9, 8, 10`\n- greedy balancing yields loads `16` and `17`, so `B = 17`\n\nThus the sample score on this test would be\n\n`100000 · (17 / 10) = 170000`.\n```", "config": "checker: chk.cc\nmemory: 512m\nsubtasks:\n- n_cases: 10\n score: 100\ntime: 5s\ntype: default\n"}
139
+ {"problem_id": "313", "category": "algorithmic", "statement": "```markdown\n# Duff's Defensive Lineup\n\n## Problem\n\nDuff has `n` friends. The `i`-th friend has name `s_i` (names are not necessarily unique).\n\nBefore asking Malek to collect candies, Duff may reorder her friends into a single queue. Let the final order be a permutation `p` of `1..n`, where friend `p_1` stands first, friend `p_2` stands second, and so on.\n\nDuff then issues `q` complaints. Each complaint is described by three integers `l`, `r`, and `k`.\n\nFor one complaint `(l, r, k)`:\n\n- Duff looks at every **adjacent pair of seats** `(i, i+1)` such that `l <= i < r`.\n- For each such pair, she forms the merged badge string \n `s_{p_i} + s_{p_{i+1}}` \n (plain concatenation, with **no separator**).\n- Malek must pay \n `occur(s_k, s_{p_i} + s_{p_{i+1}})` \n candies for that pair, where `occur(t, x)` is the number of occurrences of string `t` as a contiguous substring of `x`. Overlapping occurrences count.\n\nYour task is to output **any permutation** of the friends. Better permutations lead to fewer total candies.\n\nThis is an optimization problem: the judge will compute the total candies for your permutation.\n\n---\n\n## Input\n\nThe input contains a single test case.\n\n- The first line contains two integers `n` and `q`.\n- The next `n` lines contain the names `s_1, s_2, ..., s_n`.\n- The next `q` lines each contain three integers `l`, `r`, and `k`, describing one complaint.\n\n---\n\n## Output\n\nPrint one line containing a permutation of `1..n`:\n\n`p_1 p_2 ... p_n`\n\n### Feasibility requirements\n\nYour output is **feasible** if and only if:\n\n- it contains exactly `n` integers,\n- each integer is between `1` and `n`,\n- every value from `1` to `n` appears exactly once.\n\nIf the output is infeasible, the score for that test file is `0`.\n\n---\n\n## Objective\n\nFor a feasible permutation `p`, define its total candy cost as\n\n\\[\nC(p)=\\sum_{j=1}^{q}\\ \\sum_{i=l_j}^{r_j-1} occur\\big(s_{k_j},\\ s_{p_i}s_{p_{i+1}}\\big),\n\\]\n\nwhere `(l_j, r_j, k_j)` is the `j`-th complaint.\n\nYour goal is to **minimize** `C(p)`.\n\n---\n\n## Scoring\n\nLet:\n\n- `Y` = your total candy cost,\n- `B` = the total candy cost of the **baseline permutation** \n `p = [1, 2, ..., n]`.\n\nFor each test file, your score is\n\n\\[\n\\text{score} = 1000 \\times \\min\\left(2,\\ \\frac{B+1}{Y+1}\\right).\n\\]\n\n### Notes\n\n- The `+1` avoids division-by-zero corner cases.\n- The baseline permutation always scores exactly `1000`.\n- Better-than-baseline solutions score more than `1000`, up to a maximum of `2000`.\n- Worse solutions score less than `1000`.\n- The final contest score is the arithmetic mean of the scores over all test files.\n\n---\n\n## Constraints\n\n- `1 <= n <= 2000`\n- `1 <= q <= 200000`\n- `1 <= |s_i| <= 40`\n- All names consist only of lowercase English letters.\n- `1 <= l < r <= n`\n- `1 <= k <= n`\n- The sum of all `|s_i|` does not exceed `100000`.\n\n- Time limit: 5 seconds\n- Memory limit: 512 MB\n\n---\n\n## Example\n\n### Input\n```text\n4 3\na\nba\nab\nb\n1 4 1\n2 4 2\n1 3 3\n```\n\n### Output\n```text\n2 4 1 3\n```\n\n### Explanation\n\nThe output permutation is `[2, 4, 1, 3]`, so the adjacent merged strings are:\n\n- seats `(1,2)`: `s_2 + s_4 = \"ba\" + \"b\" = \"bab\"`\n- seats `(2,3)`: `s_4 + s_1 = \"b\" + \"a\" = \"ba\"`\n- seats `(3,4)`: `s_1 + s_3 = \"a\" + \"ab\" = \"aab\"`\n\nNow evaluate the complaints:\n\n1. `(1, 4, 1)` uses target `s_1 = \"a\"` on all three adjacent pairs \n `occur(\"a\",\"bab\") + occur(\"a\",\"ba\") + occur(\"a\",\"aab\") = 1 + 1 + 2 = 4`\n\n2. `(2, 4, 2)` uses target `s_2 = \"ba\"` on pairs `(2,3)` and `(3,4)` \n `occur(\"ba\",\"ba\") + occur(\"ba\",\"aab\") = 1 + 0 = 1`\n\n3. `(1, 3, 3)` uses target `s_3 = \"ab\"` on pairs `(1,2)` and `(2,3)` \n `occur(\"ab\",\"bab\") + occur(\"ab\",\"ba\") = 1 + 0 = 1`\n\nSo the submitted cost is `Y = 4 + 1 + 1 = 6`.\n\nFor the baseline permutation `[1,2,3,4]`, the cost is `B = 8`, so this submission would score\n\n\\[\n1000 \\times \\min\\left(2,\\frac{8+1}{6+1}\\right)\n= 1000 \\times \\frac{9}{7}\n\\approx 1285.714.\n\\]\n\nAny feasible permutation is accepted; lower total cost gives a better score.\n```", "config": "checker: chk.cc\nmemory: 512m\nsubtasks:\n- n_cases: 10\n score: 100\ntime: 5s\ntype: default\n"}
140
+ {"problem_id": "314", "category": "algorithmic", "statement": "```markdown\n# Prime Resonance Retuning\n\n## Problem\n\nYash has built a **prime resonance network** on a rooted tree.\n\nThe network has `n` nodes, rooted at node `1`. \nEach node `i` stores a non-negative integer `a_i`. A modulus `m` is also given.\n\nFor every node, only its value modulo `m` matters. Let\n\n- `P = { p | p is prime and 2 <= p < m }`\n\nbe the set of prime residues of interest.\n\nYou may install **retuners** on some nodes. \nA retuner placed on node `v` with shift `d` adds `d` (modulo `m`) to **every node in the subtree of `v`**.\n\nIf a node `u` has several retuners on its ancestors, their shifts add up modulo `m`.\n\nThere are `t` observatories. Observatory `j` watches the subtree of node `s_j` and has importance weight `w_j`.\n\nAfter all chosen retuners are applied, observatory `j` gains credit for every prime residue `p in P` that appears at least once among the final values of nodes in the subtree of `s_j`.\n\nYour task is to choose where to place retuners and what shifts to use.\n\n---\n\nMore formally:\n\n- Let `x_v` be the chosen shift at node `v`:\n - `x_v = 0` means no retuner is installed at `v`\n - `x_v in {1,2,...,m-1}` means a retuner with shift `x_v` is installed\n- At most `k` nodes may have `x_v != 0`\n- Final residue of node `u` is\n\n `r_u = (a_u + sum of x_v over all ancestors v of u, including u) mod m`\n\n- For observatory `j`, let\n\n `C_j = number of primes p in P such that there exists a node u in subtree(s_j) with r_u = p`\n\n- Its penalty is\n\n `penalty_j = w_j * (|P| - C_j)`\n\n- Installing a retuner at node `v` costs `c_v`\n\nYour goal is to **minimize total penalty + total retuner cost**.\n\n## Input\n\nThe input contains one test instance.\n\n- First line: four integers `n`, `m`, `t`, `k`\n - `n` = number of nodes\n - `m` = modulus\n - `t` = number of observatories\n - `k` = maximum number of retuners you may install\n- Second line: `n` integers `a_1, a_2, ..., a_n`\n- Third line: `n` integers `c_1, c_2, ..., c_n`\n- Next `n-1` lines: edges of the tree, each containing two integers `u`, `v`\n- Next `t` lines: observatories, each containing two integers `s_j`, `w_j`\n\nThe tree is rooted at node `1`.\n\n## Output\n\nOutput a feasible retuner placement.\n\n- First line: integer `q` — the number of installed retuners\n- Next `q` lines: two integers `v` and `d`\n - `v` = node index\n - `d` = shift, with `1 <= d < m`\n\n### Feasibility requirements\n\nYour output is feasible iff all of the following hold:\n\n- `0 <= q <= k`\n- all chosen nodes `v` are distinct\n- each shift satisfies `1 <= d < m`\n\nIf the output is infeasible, the score for the test is `0`.\n\n## Objective\n\nLet `S` be the set of chosen retuners.\n\nThe objective value is\n\n`F = sum over observatories j of [ w_j * (|P| - C_j) ] + sum over (v,d) in S of c_v`\n\nwhere `C_j` is the number of distinct prime residues from `P` appearing in the final residues of the subtree of `s_j`.\n\nYou must **minimize `F`**.\n\n## Scoring\n\nFor each test case, define the **baseline solution** as:\n\n- install no retuners\n\nLet its objective value be `F_base`.\n\nYour score for the test is:\n\n- if `F_base = 0`:\n - score = `1,000,000` if `F = 0`\n - score = `0` otherwise\n- else:\n\n `score = floor(1,000,000 * max(0, (F_base - F) / F_base))`\n\nSo:\n\n- matching the baseline gets score `0`\n- improving on the baseline gives a positive score\n- reaching objective `0` gets score `1,000,000`\n\nThe final score is the average of test-case scores, rounded down to the nearest integer.\n\n## Constraints\n\n- `1 <= n <= 100000`\n- `3 <= m <= 1000`\n- `1 <= t <= 100000`\n- `0 <= a_i <= 10^9`\n- `1 <= c_i <= 10^9`\n- `1 <= w_j <= 10^9`\n- `1 <= k <= n`\n\n## Constraints\n- Time limit: 5 seconds\n- Memory limit: 512 MB\n\n## Example\n\n### Input\n```text\n5 10 3 3\n0 1 4 6 9\n5 2 2 1 1\n1 2\n1 3\n3 4\n3 5\n1 4\n3 3\n4 2\n```\n\n### Output\n```text\n1\n3 3\n```\n\n### Explanation\n\nHere `m = 10`, so the prime residues are `{2, 3, 5, 7}`.\n\nThe single retuner `(3, 3)` adds `3` modulo `10` to nodes `3, 4, 5`.\n\nFinal residues become:\n\n- node 1: `0`\n- node 2: `1`\n- node 3: `7`\n- node 4: `9`\n- node 5: `2`\n\nObservatory penalties:\n\n- subtree `1` contains prime residues `{2, 7}` → misses 2 primes → penalty `4 * 2 = 8`\n- subtree `3` contains prime residues `{2, 7}` → misses 2 primes → penalty `3 * 2 = 6`\n- subtree `4` contains no prime residue → misses 4 primes → penalty `2 * 4 = 8`\n\nRetuner cost: `c_3 = 2`\n\nSo the objective is `F = 8 + 6 + 8 + 2 = 24`.\n\nWith no retuners, the objective is `F_base = 36`, so this output improves over baseline.\n```", "config": "checker: chk.cc\nmemory: 512m\nsubtasks:\n- n_cases: 10\n score: 100\ntime: 5s\ntype: default\n"}
141
+ {"problem_id": "315", "category": "algorithmic", "statement": "```markdown\n# Quadratic Witness Packing\n\n## Problem\nYou are building a small library of reusable **quadratic witnesses**.\n\nA witness is a pair of integers \\((A,B)\\). \nFor a query \\((p,x)\\), the witness **matches** the query if\n\n\\[\nA^2 + B^2 \\equiv x \\pmod p.\n\\]\n\nYou are given many weighted queries. Your task is to output at most \\(K\\) witnesses so that the total weight of matched queries is as large as possible.\n\nA single witness may match many queries, and a query is counted at most once even if several witnesses match it.\n\nThe moduli are guaranteed to be odd and square-free, i.e. for every odd prime \\(q\\mid p\\), we have \\(q^2 \\nmid p\\).\n\nThis is an optimization problem: any feasible solution is accepted and scored by how much total weight it covers.\n\n## Input\nThe input contains one test instance.\n\n- The first line contains three integers:\n \\[\n n\\ \\ K\\ \\ B\n \\]\n where:\n - \\(n\\) is the number of queries,\n - \\(K\\) is the maximum number of witnesses you may output,\n - \\(B\\) is the coordinate bound for every witness.\n\n- The next \\(n\\) lines each contain three integers:\n \\[\n p_i\\ \\ x_i\\ \\ w_i\n \\]\n meaning:\n - \\(p_i\\) is the modulus,\n - \\(x_i\\) is the target residue,\n - \\(w_i\\) is the weight of the query.\n\nA query \\(i\\) is covered if there exists at least one output witness \\((A,B)\\) such that\n\\[\nA^2 + B^2 \\equiv x_i \\pmod{p_i}.\n\\]\n\n## Output\nOutput a feasible witness set:\n\n- The first line contains one integer \\(m\\) \\((0 \\le m \\le K)\\), the number of witnesses you output.\n- The next \\(m\\) lines each contain two integers:\n \\[\n A_j\\ \\ B_j\n \\]\n satisfying\n \\[\n 0 \\le A_j \\le B,\\qquad 0 \\le B_j \\le B.\n \\]\n\n### Feasibility rules\n- \\(m\\) must satisfy \\(0 \\le m \\le K\\).\n- Every printed coordinate must be an integer in \\([0,B]\\).\n- Duplicate witnesses are allowed, but usually useless.\n- If the output is invalid, the submission receives score \\(0\\) for that test file.\n\n## Objective\nLet \\(C\\) be the set of queries covered by at least one of your witnesses.\n\nYour objective value is\n\n\\[\nV = \\sum_{i \\in C} w_i.\n\\]\n\nYou must **maximize** \\(V\\).\n\n## Scoring\nFor each test file, the judge also computes a fixed **baseline solution**:\n\n- it outputs exactly \\(K\\) witnesses\n \\[\n (0,0), (1,0), (2,0), \\dots, (K-1,0),\n \\]\n- this is always feasible because \\(B \\ge K-1\\).\n\nLet:\n\n- \\(W = \\sum_{i=1}^n w_i\\) be the total weight,\n- \\(V_{\\text{base}}\\) be the baseline objective value,\n- \\(U = W - V\\) be your uncovered weight,\n- \\(U_{\\text{base}} = W - V_{\\text{base}}\\) be the baseline uncovered weight.\n\nThe per-file score is:\n\n- if \\(U_{\\text{base}} = 0\\), then every feasible submission gets **1,000,000** points;\n- otherwise,\n \\[\n \\text{score} =\n \\left\\lfloor\n 10^6 \\cdot\n \\max\\left(0,\\ \\min\\left(1,\\ \\frac{U_{\\text{base}} - U}{U_{\\text{base}}}\\right)\\right)\n \\right\\rfloor.\n \\]\n\nEquivalently,\n\n\\[\n\\text{score} =\n\\left\\lfloor\n10^6 \\cdot\n\\max\\left(0,\\ \\min\\left(1,\\ \\frac{V - V_{\\text{base}}}{W - V_{\\text{base}}}\\right)\\right)\n\\right\\rfloor\n\\quad\\text{when } V_{\\text{base}} < W.\n\\]\n\nSo:\n- matching the baseline gives score \\(0\\),\n- covering all queries gives score \\(1{,}000{,}000\\),\n- intermediate improvements give proportionally higher scores.\n\nThe final contest score is the sum of per-file scores over all test files.\n\n## Constraints\n- \\(1 \\le n \\le 2 \\times 10^5\\)\n- \\(1 \\le K \\le 60\\)\n- \\(K-1 \\le B \\le 10^9\\)\n- \\(1 \\le p_i \\le 10^7\\)\n- \\(p_i\\) is odd\n- \\(0 \\le x_i < p_i\\)\n- \\(1 \\le w_i \\le 10^6\\)\n- For every odd prime \\(q\\mid p_i\\), \\(q^2 \\nmid p_i\\)\n\n## Constraints\n- Time limit: 4 seconds\n- Memory limit: 512 MB\n\n## Example\n### Sample input\n```text\n6 2 100\n5 0 10\n5 1 8\n13 5 7\n13 8 6\n15 5 9\n15 8 4\n```\n\n### Sample output\n```text\n2\n1 2\n2 2\n```\n\n### Explanation\nThe two witnesses are:\n- \\((1,2)\\), with \\(1^2+2^2=5\\),\n- \\((2,2)\\), with \\(2^2+2^2=8\\).\n\nThus they cover:\n- residue \\(0 \\bmod 5\\) via \\(5\\),\n- residue \\(5 \\bmod 13\\) via \\(5\\),\n- residue \\(8 \\bmod 13\\) via \\(8\\),\n- residue \\(5 \\bmod 15\\) via \\(5\\),\n- residue \\(8 \\bmod 15\\) via \\(8\\).\n\nSo the covered total weight is\n\\[\n10 + 7 + 6 + 9 + 4 = 36.\n\\]\n\nThe only uncovered query is \\((5,1)\\) with weight \\(8\\), so \\(W=44\\) and \\(U=8\\).\n\nThe baseline witnesses are \\((0,0)\\) and \\((1,0)\\), whose sums are \\(0\\) and \\(1\\). \nThey cover only the first two queries, so \\(V_{\\text{base}}=18\\), hence \\(U_{\\text{base}}=26\\).\n\nTherefore the score for this file is\n\\[\n\\left\\lfloor 10^6 \\cdot \\frac{26-8}{26} \\right\\rfloor\n=\n692307.\n\\]\n```", "config": "checker: chk.cc\nmemory: 512m\nsubtasks:\n- n_cases: 10\n score: 100\ntime: 4s\ntype: default\n"}
142
  {"problem_id": "33", "category": "algorithmic", "statement": "Permutation (Modified Version)\n\nTime Limit: 5 s\nMemory Limit: 1024 MB\n\nThe Pharaohs use the relative movement and gravity of planets to accelerate their spaceships. Suppose a spaceship will pass by some planets with orbital speeds in order. For each planet, the Pharaohs' scientists can choose whether to accelerate the spaceship using this planet or not. To save energy, after accelerating by a planet with orbital speed p[i], the spaceship cannot be accelerated using any planet with orbital speed p[j] < p[i]. In other words, the chosen planets form an increasing subsequence of p.\n\nThe scientists have identified that there are exactly k different ways a set of planets can be chosen to accelerate the spaceship. They have lost their record of all the orbital speeds (even the value of n). However, they remember that p is a permutation of {0, 1, …, n−1}. Your task is to find one possible permutation of sufficiently small length.\n\nInput\nThe first line contains an integer q (1 ≤ q ≤ 100), the number of spaceships.\nThe second line contains q integers k1, k2, …, kq (2 ≤ ki ≤ 10^18).\n\nOutput\nFor each ki, output two lines:\n- The first line contains an integer n (the length of the permutation).\n- The second line contains n integers: a valid permutation of {0, 1, …, n−1} having exactly ki increasing subsequences.\n\nScoring\nLet m be the maximum permutation length you used across all queries.\nYour score for the test file will be determined as follows:\n\nm ≤ 90 → 100 points\n\n90 < m < 2000 -> linear function\n\nm >= 2000 -> 0\n\nExample\nInput\n2\n3 8\n\nOutput\n2\n1 0\n3\n0 1 2\n\nExplanation\nFor k = 3, one valid permutation is [1, 0], which has exactly 3 increasing subsequences: [], [0], [1].\nFor k = 8, one valid permutation is [0, 1, 2], which has exactly 8 increasing subsequences: [], [0], [1], [2], [0, 1], [0, 2], [1, 2], [0, 1, 2].\n", "config": "type: default\ntime: 5s\nmemory: 1024m\nsubtasks:\n - score: 100\n n_cases: 3\nchecker: checker.cpp\nchecker_type: testlib"}
143
  {"problem_id": "35", "category": "algorithmic", "statement": "Language: C++ only\n\nTime limit per test: 5 seconds\nMemory limit per test: 1024 megabytes\n\nThis is an interactive problem.\n\nThere is a hidden array a containing all the numbers from 1 to n, and all of them appear twice except one (which only appears once).\n\nYou can ask queries in the following format, where S is a subset of {1,2,…,2n−1} and x is an integer in [1,n]:\n\n? x |S| S1 S2 ... S|S|\n\nThe answer to this query is: does there exist i ∈ S such that a_i = x ?\n\nYour task is to find the number appearing exactly once, using at most 5000 queries. You don’t need to find its position.\n\nNote that the interactor is not adaptive, which means that the hidden array does not depend on the queries you make.\n\nInput\nEach test contains multiple test cases.\nThe first line contains the number of test cases t (1 ≤ t ≤ 20).\n\nThe description of the test cases follows.\n\nThe first line of each test case contains a single integer n (n = 300) — the maximum value in the hidden array.\n\nInteraction\nFor each test case, first read a single integer. If the integer you read is -1, it means that the answer to the previous test case was wrong, and you should exit immediately.\n\nYou may ask up to 5000 queries in each test case.\n\nTo ask a query, print a line in the format described above.\nAs a response to the query, you will get:\n\n1 if the answer is yes,\n\n0 if the answer is no,\n\n-1 if you made an invalid query. In this case you should exit immediately.\n\nTo output an answer, print:\n! y\nwhere y is the number that appears exactly once.\nPrinting the answer doesn’t count as a query.\n\nIf you ask too many queries, you ask a malformed query, or your answer is wrong, you will get -1.\n\nAfter printing a query, do not forget to output the end of line and flush the output. Otherwise, you will get Idleness limit exceeded.\nIn C++, you can use:\nfflush(stdout);\ncout.flush();\n\nScoring\n\nIf you solve the problem with at most 500 queries, you get 100 points.\n\nIf you solve it with 5000 queries, you get 0 points.\n\nFor values in between, the score decreases linearly.\n\nExample\nInput\n1\n300\n0\n\nExplanation\nIn the first test case, n = 300, so the hidden array has length 2n − 1 = 599.\n\nContestant prints / Interactor replies\n? 187 1 1\n0\n! 187\n\nQuery: does a1 = 187? → No.\nWe then output ! 187.\nFortunately, the answer is correct.\n\nWe have asked 1 query (printing the answer does not count as a query), which is less than the maximum allowed number of queries (5000).", "config": "# Set the problem type to interactive\ntype: interactive\n\n# Specify the interactor source file\ninteractor: interactor.cpp\n\n# Time and memory limits still apply to the contestant's solution\ntime: 5s\nmemory: 1024m\n\n# The subtasks section works the same way\nsubtasks:\n - score: 100\n n_cases: 3 # Looks for 1.in, 2.in, ... 5.in"}
144
  {"problem_id": "36", "category": "algorithmic", "statement": "Hack!\n\nThis is an I/O interactive problem. I/O interaction refers to interactive problems, where the program communicates with a special judge during execution instead of producing all output at once. In these problems, the program sends queries (output) to the judge and must immediately read responses (input) before continuing. The solution must strictly follow the input-output protocol defined in the problem statement, because any extra output, missing flush, or incorrect format can cause a wrong answer. Unlike standard problems, interactive problems require careful handling of I/O, synchronization, and flushing to ensure smooth communication between the contestant’s code and the judge.\n\nYou know that unordered_set uses a hash table with n buckets, which are numbered from 0 to\nn − 1. Unfortunately, you do not know the value of n and wish to recover it.\nWhen you insert an integer x into the hash table, it is inserted to the (x mod n) -th bucket. If\nthere are b elements in this bucket prior to the insertion, this will cause b hash collisions to occur.\n\nBy giving k distinct integers x[0],x[1],…,x[k − 1] to the interactor, you can find out the total\nnumber of hash collisions that had occurred while creating an unordered_set containing the\nnumbers. However, feeding this interactor k integers in one query will incur a cost of k.\nFor example, if n = 5, feeding the interactor with x = [2, 15, 7, 27, 8, 30] would cause 4 collisions in\ntotal:\n\nOperation New collisions Buckets\ninitially − [],[],[],[],[]\ninsert x[0] = 2 0 [],[],[2],[],[]\ninsert x[1] = 15 0 [15],[],[2],[],[]\ninsert x[2] = 7 1 [15],[],[2, 7],[],[]\ninsert x[3] = 27 2 [15],[],[2, 7, 27],[],[]\ninsert x[4] = 8 0 [15],[],[2, 7, 27],[8],[]\ninsert x[5] = 30 1 [15, 30],[],[2, 7, 27],[8],[]\n\nNote that the interactor creates the hash table by inserting the elements in order into an initially empty unordered_set, and a new empty unordered_set will be created for each query. In other words, all queries are independent.\n\nYour task is to find the number of buckets n (2<=n<=10^9) using total cost of at most 1 000 000. Total cost is the total length of your queries. You have to minimize total cost as much as possible. Your final score will be calculated as the average of 100 * clamp(log_50(10^6 / (your_total_cost - 9 * 10^4)), 0, 1) across all cases.\n\nInput\n\nThere is no input in this problem.\n\nInteraction\n\nTo ask a query, output one line. First output 0 followed by a space, then output an positive integer m, the number of elements in this query, then print a sequence of m integers ranging from 1 to 10^18 separated by a space. After flushing your output, your program should read a single integer x indicating the number of collisions created by inserting the elements in order to an unordered_set.\n\nIf you want to guess n, output one line. First output 1 followed by a space, then print the n you guess. After flushing your output, your program should exit immediately.\n\nNote that the answer for each test case is pre-determined. That is, the interactor is not adaptive. Also note that your guess does not count as a query.\n\nTo flush your output, you can use:\n\n fflush(stdout) (if you use printf) or cout.flush() (if you use cout) in C and C++.\n\n System.out.flush() in Java.\n\n stdout.flush() in Python.\n\nNote\n\nPlease note that if you receive a Time Limit Exceeded verdict, it is possible that your query is invalid or the number of queries exceeds the limit.\n\nConstraints \n- Time limit: 3 seconds\n- Memory Limit: 1024 MB\n- Let Q be the query cost you make.\n - If your program exceeds time limit, memory limit, or returns incorrect answer → score=0.\n - Otherwise, your score depends on Q:\n - score(Q) = 1000001 / (Q + 1)\n - In other words, a solution with Q <= 1000000 is awarded the full score.\n\nExample input (you to interactor):\n0 6 2 15 7 27 8 30\n\n0 3 1 2 3\n\n0 5 10 20 30 40 50\n\n1 5\n\nExample output (interactor to you):\n\n4\n\n0\n\n10", "config": "# Set the problem type to interactive\ntype: interactive\n\n# Specify the interactor source file\ninteractor: interactor.cpp\n\n# Time and memory limits still apply to the contestant's solution\ntime: 3s\nmemory: 1024m\n\n# The subtasks section works the same way\nsubtasks:\n - score: 100\n n_cases: 3 # Looks for 1.in, 2.in, ... 5.in"}