diff --git a/ace/ace.py b/ace/ace.py index 2d662ad..1e6b43b 100644 --- a/ace/ace.py +++ b/ace/ace.py @@ -454,6 +454,11 @@ def _train_single_sample( token_budget = config_params['token_budget'] use_json_mode = config_params['use_json_mode'] no_ground_truth = config_params['no_ground_truth'] + # if algorithmic task, use code prompt style + if hasattr(data_processor, "get_generator_prompt_style"): + prompt_style = data_processor.get_generator_prompt_style() + else: + prompt_style = "json" # Extract sample data question = task_dict.get("question", "") @@ -468,6 +473,7 @@ def _train_single_sample( context=context, reflection="(empty)", use_json_mode=use_json_mode, + prompt_style=prompt_style, call_id=f"{step_id}_gen_initial", log_dir=log_dir ) @@ -533,6 +539,7 @@ def _train_single_sample( context=context, reflection=reflection_content, use_json_mode=use_json_mode, + prompt_style=prompt_style, call_id=f"{step_id}_post_reflect_round_{round_num}", log_dir=log_dir ) @@ -612,6 +619,7 @@ def _train_single_sample( context=context, reflection="(empty)", use_json_mode=use_json_mode, + prompt_style=prompt_style, call_id=f"{step_id}_post_curate", log_dir=log_dir ) diff --git a/ace/core/generator.py b/ace/core/generator.py index 3ceebec..0fd4bb0 100644 --- a/ace/core/generator.py +++ b/ace/core/generator.py @@ -6,7 +6,7 @@ import json import re from typing import Dict, List, Tuple, Optional, Any -from ..prompts.generator import GENERATOR_PROMPT +from ..prompts.generator import GENERATOR_PROMPT_JSON, GENERATOR_PROMPT_CODE from llm import timed_llm_call class Generator: @@ -37,6 +37,7 @@ def generate( context: str = "", reflection: str = "(empty)", use_json_mode: bool = False, + prompt_style: str = "json", call_id: str = "gen", log_dir: Optional[str] = None ) -> Tuple[str, List[str], Dict[str, Any]]: @@ -56,8 +57,13 @@ def generate( Tuple of (full_response, bullet_ids_used, call_info) """ # Format the prompt - prompt = GENERATOR_PROMPT.format(playbook, reflection, question, context) + if prompt_style == "code": + prompt = GENERATOR_PROMPT_CODE.format(playbook, reflection, question, context) + else: + prompt = GENERATOR_PROMPT_JSON.format(playbook, reflection, question, context) + use_json_mode_call = use_json_mode and prompt_style != "code" + response, call_info = timed_llm_call( self.api_client, self.api_provider, @@ -67,7 +73,7 @@ def generate( call_id=call_id, max_tokens=self.max_tokens, log_dir=log_dir, - use_json_mode=use_json_mode + use_json_mode=use_json_mode_call ) # Extract bullet IDs if using retrieval and reason mode diff --git a/ace/prompts/generator.py b/ace/prompts/generator.py index 3304ca7..d01041b 100644 --- a/ace/prompts/generator.py +++ b/ace/prompts/generator.py @@ -3,7 +3,7 @@ """ # Retrieval and Reason Generator prompt that outputs bullet IDs -GENERATOR_PROMPT = """You are an analysis expert tasked with answering questions using your knowledge, a curated playbook of strategies and insights and a reflection that goes over the diagnosis of all previous mistakes made while answering the question. +GENERATOR_PROMPT_JSON = """You are an analysis expert tasked with answering questions using your knowledge, a curated playbook of strategies and insights and a reflection that goes over the diagnosis of all previous mistakes made while answering the question. **Instructions:** - Read the playbook carefully and apply relevant strategies, formulas, and insights @@ -39,4 +39,34 @@ }} --- -""" \ No newline at end of file +""" + +# Code-only generator prompt for programming tasks +GENERATOR_PROMPT_CODE = """You are a coding expert tasked with solving programming problems using your knowledge, a curated playbook of strategies and insights, and a reflection that summarizes previous mistakes. + +**Instructions:** +- Use the playbook and reflection when helpful +- Write a complete, runnable solution that follows the problem's input/output format +- Return only the final code (no explanations, no markdown, no JSON) +- Prefer C++17 when the question asks for it + +**Playbook:** +{} + +**Reflection:** +{} + +**Question:** +{} + +**Context:** +{} + +**Output:** +Return only the code. + +--- +""" + +# Backward-compatible alias +GENERATOR_PROMPT = GENERATOR_PROMPT_JSON \ No newline at end of file diff --git a/eval/frontier-cs/data/algorithmic_test.jsonl b/eval/frontier-cs/data/algorithmic_test.jsonl new file mode 100644 index 0000000..08dff97 --- /dev/null +++ b/eval/frontier-cs/data/algorithmic_test.jsonl @@ -0,0 +1,18 @@ +{"context": "Interactive RBS\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\nThere is a hidden bracket sequence s of length n, where s only contains '(' and ')'. It is guaranteed that s contains at least one '(' and one ')'.\n\nTo find this bracket sequence, you can ask queries. Each query has the following form: you pick an integer k and arbitrary indices i_1,i_2,...,i_k (1<=k<=1000, 1<=i_1,i_2,...,i_k<=n). Note that the indices can be equal. Next, you receive an integer f(s_{i_1}s_{i_2}...s_{i_k}) calculated by the jury.\n\nFor a bracket sequence t, f(t) is the number of non-empty regular bracket substrings in t (the substrings must be contiguous). For example, f(\"()())\")=3.\n\nA bracket sequence is called regular if it can be constructed in the following way.\n\n1. The empty sequence ∅ is regular.\n2. If the bracket sequence A is regular, then (A) is also regular.\n3. If the bracket sequences A and B are regular, then the concatenated sequence AB is also regular.\n\nFor example, the sequences \"(())()\", \"()\" are regular, while \"(()\" and \"())(\" are not.\n\nFind the sequence s using no more than 200 queries. Specifically, your score will be (200 - q) / 200, where q is the number of queries.\n\nThe first line of each test case contains one integer n (2<=n<=1000). At this moment, the bracket sequence s is chosen. The interactor in this task is not adaptive. In other words, the bracket sequence s is fixed in every test case and does not change during the interaction.\n\nTo ask a query, you need to pick an integer k and arbitrary indices i_1,i_2,...,i_k (1<=k<=1000), 1<=i_1,i_2,...,i_k<=n) and print the line of the following form (without quotes):\n\n\"0 k i_1 i_2 ... i_k\"\n\nAfter that, you receive an integer f(s_{i_1}s_{i_2}...s_{i_k}).\n\nYou can ask at most 200 queries of this form.\n\nNext, if your program has found the bracket sequence s, print a line with the following format (without quotes):\n\n\"1 s_1s_2...s_n\"\n\nNote that this line is not considered a query and is not taken into account when counting the number of queries asked.\n\nIf you ask more than 200 queries during an interaction, your program must terminate immediately, and you will receive the Wrong Answer verdict. Otherwise, you can get an arbitrary verdict because your solution will continue to read from a closed stream.\n\nAfter printing a query or the answer for a test case, do not forget to output the end of the line and flush the output. Otherwise, you will get the verdict Idleness Limit Exceeded. To do this, use:\n\nfflush(stdout) or cout.flush() in C++;\nSystem.out.flush() in Java;\nflush(output) in Pascal;\nstdout.flush() in Python;\nsee the documentation for other languages.\n\nExample Input 1 (interactor to you):\n\n3\n\n0\n\n1\n\n1\n\nExample Output 1 (you to interactor):\n\n\n0 4 1 2 3 3\n\n0 2 2 1\n\n0 2 3 1\n\n1 )((\n\nExample Input 2 (interactor to you):\n\n2\n\n3\n\nExample Output 2 (you to interactor):\n\n\n0 4 1 2 1 2\n\n1 ()", "target": "", "metadata": {"track": "algorithmic", "problem_id": 40, "statement_path": "/Users/jingzhuohu/repos/Frontier-CS/algorithmic/problems/40/statement.txt", "config_path": "/Users/jingzhuohu/repos/Frontier-CS/algorithmic/problems/40/config.yaml"}} +{"context": "Story\n--------\nTakahashi is a skilled purse seine fisher.\nHis fishing boat is equipped with state-of-the-art sonar, allowing him to accurately determine the positions of fish within the fishing area.\nAdditionally, the boat is capable of high-speed movement, enabling him to assume that fish remain stationary while he sets up the fishing net.\n\nThe fishing method involves using the boat to deploy nets and form a closed polygon, capturing the fish within the enclosed area.\nTo optimize efficiency, each edge of the polygon formed by the nets must be aligned either parallel to the east-west or north-south direction.\nFurthermore, due to the limited length of the nets equipped on the boat, the polygon must be constructed within these constraints.\n\nThe fishing area contains two types of fish: mackerels and sardines.\nFor resource conservation reasons, sardines are currently prohibited from being caught in this fishing area.\nAny sardines caught in the net must be released back into the sea.\nBecause this process is labor-intensive, Takahashi should focus on maximizing the catch of mackerel while avoiding sardines as much as possible.\n\n\nProblem Statement\n--------\nThere are $N$ mackerels and $N$ sardines on a two-dimensional plane.\nConstruct a polygon that satisfies the following conditions and maximize the value obtained by subtracting the total number of sardines inside the polygon from the total number of mackerels inside it.\nNote that any points lying on the edges of the polygon are considered to be inside the polygon.\n\n### Conditions\n1. The number of vertices in the polygon must not exceed $1000$, and the total length of its edges must not exceed $4 \\times 10^5$.\n2. The coordinates of each vertex $(x, y)$ must be integers satisfying $0 \\leq x, y \\leq 10^5$.\n3. Each edge of the polygon must be parallel to either the $x$-axis or the $y$-axis.\n4. The polygon must not self-intersect: non-adjacent edges must not share any points, and adjacent edges must only meet at their endpoints.\n\n\n\nScoring\n--------\nLet $a$ be the total number of mackerels inside the polygon and $b$ be the total number of sardines inside the polygon.\nThen, you will obtain the score of $\\max(0, a - b + 1)$.\n\nThere are $150$ test cases, and the score of a submission is the total score for each test case.\nIf your submission produces an illegal output or exceeds the time limit for some test cases, the submission itself will be judged as WA or TLE , and the score of the submission will be zero.\nThe highest score obtained during the contest will determine the final ranking, and there will be no system test after the contest.\nIf more than one participant gets the same score, they will be ranked in the same place regardless of the submission time.\n\n\n\nInput\n--------\nInput is given from Standard Input in the following format:\n~~~\n$N$\n$x_0$ $y_0$\n$\\vdots$\n$x_{2N-1}$ $y_{2N-1}$\n~~~\n\n- In all test cases, the number of mackerels and sardines, $N$, is fixed at $5000$.\n- For each $i = 0, 1, \\dots, N-1$, $(x_i, y_i)$ represents the coordinates of the $i$-th mackerel.\n- For each $i = 0, 1, \\dots, N-1$, $(x_{N+i}, y_{N+i})$ represents the coordinates of the $i$-th sardine.\n- Each coordinate $(x_i, y_i)$ satisfies $0 \\leq x_i, y_i \\leq 10^5$, and all coordinates are distinct.\n\n\nOutput\n--------\nLet the number of vertices in the polygon be $m$ ($4 \\leq m \\leq 1000$), and let $(a_i, b_i)$ denote the coordinates of the $i$-th vertex.\nThen, output to Standard Output in the following format:\n~~~\n$m$\n$a_0$ $b_0$\n$\\vdots$\n$a_{m-1}$ $b_{m-1}$\n~~~\n\nThe output vertices do not necessarily need to form the actual corners of the polygon.\nIn other words, three consecutive vertices $(a_i, b_i), (a_{i+1}, b_{i+1}), (a_{i+2}, b_{i+2})$ may lie on a straight line.\nHowever, all vertices must have distinct coordinates.\n\nThe vertices can be output in either clockwise or counterclockwise order.\n\nShow example\n\n\nYour program may output multiple solutions.\nIf multiple solutions are output, only the last one is used for scoring.\nYou can compare multiple solutions using the web version of the visualizer.\n\n\n\n\n\nInput Generation\n--------\n- $\\mathrm{rand}(L, U)$: Generates a random integer uniformly distributed between $L$ and $U$ (inclusive).\n- $\\mathrm{rand\\\\_double}(L, U)$: Generates a random real number uniformly distributed between $L$ and $U$.\n- $\\mathrm{normal}(\\mu, \\sigma)$: Generates a random real number from a normal distribution with mean $\\mu$ and standard deviation $\\sigma$.\n\nFirst, generate the coordinates of mackerels.\nThe number of clusters $n$ is determined by generating $n = \\mathrm{rand}(10, 25)$.\nFor each cluster $i$, generate the following parameters:\n\n- Weight $w_i = \\mathrm{rand\\\\_double}(0, 1)$\n- Center $(cx_i, cy_i) = (\\mathrm{rand}(20000, 80000), \\mathrm{rand}(20000, 80000))$\n- Standard deviation $\\sigma_i = \\mathrm{rand}(1000, 5000)$\n\nRepeat the following process $N$ times to generate the coordinates of $N$ mackerels:\n\n- Randomly select a cluster $i$ with probability proportional to its weight $w_i$.\n- Generate $x = \\mathrm{round}(\\mathrm{normal}(cx_i, \\sigma_i))$ and $y = \\mathrm{round}(\\mathrm{normal}(cy_i, \\sigma_i))$.\n- If the generated coordinates $(x, y)$ satisfy $0 \\leq x, y \\leq 10^5$ and are distinct from all previously generated coordinates, they are accepted as the coordinates of a mackerel. Otherwise, regenerate $(x, y)$.\n\nAfter generating the coordinates of mackerels, generate the coordinates of sardines in the same way.\n\n\n\nTools (Input generator and visualizer)\n--------\n- Web version: This is more powerful than the local version providing animations.\n- Local version: You need a compilation environment of Rust language.\n\t- Pre-compiled binary for Windows: If you are not familiar with the Rust language environment, please use this instead.\n\nPlease be aware that sharing visualization results or discussing solutions/ideas during the contest is prohibited.", "target": "", "metadata": {"track": "algorithmic", "problem_id": 167, "statement_path": "/Users/jingzhuohu/repos/Frontier-CS/algorithmic/problems/167/statement.txt", "config_path": "/Users/jingzhuohu/repos/Frontier-CS/algorithmic/problems/167/config.yaml"}} +{"context": "Story\n--------\nMr. Takahashi, the mayor of Takahashi City, decided to draw a map of Takahashi City on the floor of the city hall lobby using colored square tiles.\nTakahashi City is divided into several wards, and in this map, each ward should be represented as a set of connected tiles of the same color.\nHe commissioned a contractor to create a draft of an accurate map, but the number of tiles to be used was too large, and the budget was exceeded.\nMayor Takahashi, who loves graphs, is only interested in the adjacencies between the wards and thinks that the map could be drawn with fewer tiles if information other than adjacencies, such as the shape and size of each ward, is ignored.\nPlease create a map using as few tiles as possible.\n\n
\n
\n \n\t

Accurate map

\n
\n
\n \n\t

Small map correctly representing adjacencies

\n
\n
\n\nProblem Statement\n--------\nGiven a map of Takahashi City represented on a grid of $n\\times n$ squares.\nLet $(0,0)$ be the coordinates of the top-left square, and $(i,j)$ be the coordinates of the square located $i$ squares down and $j$ squares to the right from there.\nThe city consists of $m$ wards, and the square of color $c$ ($1\\leq c\\leq m$) corresponds to the $c$-th ward.\nThe outside of the $n\\times n$ squares correspond to the outside of the city and is colored $0$.\n\nTwo squares are defined as \"adjacent\" if they share an edge, and a set of squares is defined as \"connected\" if any two squares can reach each other via adjacent squares.\nIn the given map, for each color c, the set of squares of color c is guaranteed to be connected.\n\nYour task is to create a map represented on a grid of $n\\times n$ squares that satisfies all of the following conditions.\n\n- For every color $c$ ($0\\leq c\\leq m$), squares of color $c$ must be connected. Note that since the outside of the $n\\times n$ squares is colored $0$, squares of color $0$ can be connected through the outside squares.\n- For every pair of colors $c$ and $d$ ($0\\leq cWA or TLE , and the score of the submission will be zero.\nThe highest score obtained during the contest will determine the final ranking, and there will be no system test after the contest.\nIf more than one participant gets the same score, they will be ranked in the same place regardless of the submission time.\n\n\n\nInput\n--------\nInput is given from Standard Input in the following format.\n\n~~~\n$n$ $m$\n$c_{0,0}$ $c_{0,1}$ $\\cdots$ $c_{0,n-1}$\n$\\vdots$\n$c_{n-1,0}$ $c_{n-1,1}$ $\\cdots$ $c_{n-1,n-1}$\n~~~\n\nFor all test cases, we fix $n = 50$ and $m = 100$.\n$c_{i,j}$ is an integer value representing the color of the square at coordinates $(i,j)$ and satisfies $1\\leq c_{i,j}\\leq m$.\nFor every $k=1,2,\\cdots,m$, there exists at least one $(i,j)$ with $c_{i,j}=k$.\n\n\nOutput\n--------\nLet $d_{i,j}$ ($0\\leq d_{i,j}\\leq m$) be the color of the square at coordinates $(i,j)$ in the created map.\nThen, output to Standard Output in the following format.\n\n~~~\n$d_{0,0}$ $d_{0,1}$ $\\cdots$ $d_{0,n-1}$\n$\\vdots$\n$d_{n-1,0}$ $d_{n-1,1}$ $\\cdots$ $d_{n-1,n-1}$\n~~~\n\nIf the output map does not satisfy the conditions specified in the problem statement, the submission will be judged as WA.\n\nYour program may output multiple solutions.\nIf multiple solutions are output, only the last one is used for scoring.\nYou can compare multiple solutions using the web version of the visualizer.\n\nShow example\n\n\nInput Generation\n--------\n
\nFirst, we initialize with $c_{i,j}=0$ for all $(i,j)$.\nNext, for each $k=1,2,\\cdots,m$, we randomly select a square with $c_{i,j}=0$ and set $c_{i,j}=k$.\nFinally, we repeat the following process while squares with $c_{i,j}=0$ remain.\n\nRandomly select a square with $c_{i,j}=0$ and randomly select its adjacent square $(i',j')$.\nWe set $c_{i,j}=c_{i',j'}$.\n
\n\nTools (Input generator and visualizer)\n--------\n- Web version: This is more powerful than the local version providing animations and manual play.\n- Local version: You need a compilation environment of Rust language.\n\t- Pre-compiled binary for Windows: If you are not familiar with the Rust language environment, please use this instead.\n\nPlease be aware that sharing visualization results or discussing solutions/ideas during the contest is prohibited.", "target": "", "metadata": {"track": "algorithmic", "problem_id": 163, "statement_path": "/Users/jingzhuohu/repos/Frontier-CS/algorithmic/problems/163/statement.txt", "config_path": "/Users/jingzhuohu/repos/Frontier-CS/algorithmic/problems/163/config.yaml"}} +{"context": "Time limit: 2 seconds\nMemory limit: 1024 megabytes\nThis is an interactive problem.\nA mischievous robot is navigating an infinitely large 2D grid. However, its movement is confined to the first quadrant, meaning its coordinates (x, y) must always satisfy x > 0 and y > 0. Initially, the robot is located at grid coordinates (s_x, s_y). All grid cells are initially white.\nSet T = 3000. The game proceeds in discrete time steps. In each time step, the following sequence occurs:\n1. Your Move: You choose integer coordinates (x_m, y_m) such that 1 <= x_m <= T and 1 <= y_m <= T. You then mark this cell black. A cell, once marked black, remains black for the rest of the game. You can mark any cell within the range, including the cell where the robot is currently located.\n2. Robot’s Move: The robot, currently at position (r_x, r_y), observes the grid (including the cell you just marked black). It knows the locations of all currently black cells. It then moves to a new position (n_x, n_y). The new position (n_x, n_y) must be one of the 8 cells immediately adjacent (horizontally, vertically, or diagonally) to (r_x, r_y). That is, |n_x - r_x| <= 1 and |n_y - r_y| <= 1, and (n_x, n_y) ̸= (r_x, r_y). Additionally, the robot must stay within the first quadrant, so n_x > 0 and n_y > 0. The interactor (controlling the robot) will choose one valid move for the robot. The robot’s strategy is unknown to you.\n3. Outcome Check: After the robot moves to (n_x, n_y), the system checks if the cell (n_x, n_y) is black.\n • If (n_x, n_y) is black, the robot explodes.\n • If (n_x, n_y) is white, the game continues to the next time step, with the robot now at (n_x, n_y).\nYour goal is to make the robot explode within as less steps as possiable. Answers exceeding 3000 steps are considered as incorrect answers.\n\nInput\nThe first line of input contains two integers sx and sy (1 <= s_x, s_y <= 20), the initial coordinates of the robot.\n\nInteraction Protocol\nThe interaction proceeds in turns for at most T turns. In each turn t (from t = 1 to T):\n1. Your program must print one line containing two space-separated integers x_m and y_m, representing the coordinates of the cell you choose to mark black in this turn. Remember to flush the output stream.\n2. The interactor reads your chosen coordinates (x_m, y_m).\n3. The interactor determines the robot’s next move to (n_x, n_y) based on its current position and the set of all black cells (including the one just marked at (x_m, y_m) ).\n4. The interactor checks if the cell (n_x, n_y) is black.\n • If it is black (robot explodes), the interactor will print a single line containing '0 0' and terminate. Your program should then read these values and terminate successfully.\n • If it is white, the interactor will print a single line containing two space-separated integers n_x and n_y, the new coordinates of the robot. Your program should read these coordinates to know the robot’s current position for the next turn.\nIf the robot has not exploded after you have made T moves, your program should terminate. Your solution will be judged as incorrect in this case (or if you exceed the turn limit or make an invalid move). To flush your output, you can use fflush(stdout) (if you use printf) or cout.flush() (if you use cout).\n\nExample\nstandard input\n5 5\n5 4\n5 3\n5 2\n5 1\n0 0\nstandard output\n6 1\n4 1\n6 2\n4 2\n5 2", "target": "", "metadata": {"track": "algorithmic", "problem_id": 13, "statement_path": "/Users/jingzhuohu/repos/Frontier-CS/algorithmic/problems/13/statement.txt", "config_path": "/Users/jingzhuohu/repos/Frontier-CS/algorithmic/problems/13/config.yaml"}} +{"context": "time limit per test: 1 second\nmemory limit per test: 256 megabytes\nThis is an interactive problem.\nZookeeper has set up a special lock for the rabbit enclosure.\nThe lock consists of n concentric rings numbered from 0 to n−1. The innermost ring is ring 0 and the outermost ring is ring n−1. All rings are split equally into n*m sections each. Each of those rings contains a single metal arc that covers exactly m contiguous sections. At the center of the ring is a core and surrounding the entire lock are n*m receivers aligned to the n*m sections.\nThe core has n*m lasers that shine outward from the center, one for each section. The lasers can be blocked by any of the arcs. A display on the outside of the lock shows how many lasers hit the outer receivers.\nFor example, there are n=3 rings, each covering m=4 sections. There are n*m=12 sections. The ring 0 covers sections 0, 1, 2, 3, the ring 1 covers sections 1, 2, 3, 4, and ring 2 covers sections 7, 8, 9, 10. Three of the lasers (sections 5, 6, 11) are not blocked by any arc, thus the display will show 3 in this case.\nWabbit cannot see where any of the arcs are. Given the relative positions of the arcs, Wabbit can open the lock on his own.\nTo be precise, Wabbit needs n−1 integers p_1,p_2,…,p_{n−1} satisfying 0≤p_i 30%).\n- When you output your final answer \"! x\", if there exists ANY valid role assignment where x is NOT the Impostor, your answer is considered wrong.\n- To be correct, your queries must uniquely determine who the Impostor is.\n\n--------------------------------------------------\nInput\n--------------------------------------------------\n\nThe first line contains an integer t (1 ≤ t ≤ 1000) — the number of test cases.\n\nFor each test case, you are given a single integer n (3 ≤ n ≤ 1e5).\nIt is guaranteed that the sum of n over all test cases does not exceed 1e5.\n\n--------------------------------------------------\nInteraction Protocol\n--------------------------------------------------\n\nFor each test case:\n\n1) You may ask queries of the form:\n ? i j\n (1 ≤ i, j ≤ n, i ≠ j)\n\n The interactor replies with:\n 1 if player i answers \"Yes\" (thinks j is a Knight),\n 0 otherwise.\n\n2) When you decide to answer, output:\n ! x\n (1 ≤ x ≤ n)\n\n After you output your answer, the interaction continues with the next test case (if any).\n The interactor does not send a reply to your answer (but internally tracks correctness for scoring).\n\nInvalid output (wrong format, out-of-range indices, i = j in a query) will cause the interactor to print -1.\nIf you receive -1, terminate immediately.\n\nAfter printing any query or answer, print a newline and flush.\n\n--------------------------------------------------\nScoring (modified version)\n--------------------------------------------------\n\nYour submission is evaluated over the whole input consisting of t test cases.\n\nLet:\n- Q = total number of queries (\"? i j\") you asked across all test cases.\n- c = number of test cases for which your final answer \"! x\" was wrong.\n\nYour total cost (to be minimized) is:\n cost = Q + (4^c - 1)\n\nScoring:\n- If cost ≤ 15000: full score (100 points)\n- If cost ≥ 100000: zero score (0 points)\n- Otherwise: linearly interpolated between 0 and 100 points\n\nNotes:\n- You are allowed to be wrong on some test cases; this increases c and thus adds a penalty (4^c - 1).\n- The final \"! x\" outputs do NOT count as queries (only lines starting with \"?\" count toward Q).\n- Since the grader is adaptive, you must ask enough questions to uniquely determine the Impostor.\n\n--------------------------------------------------\nExample (format demonstration)\n--------------------------------------------------\n\nThis example shows one possible interaction transcript (it is not optimal).\n\nInput (from interactor)\n2\n7\n1\n0\n0\n1\n1\n0\n0\n4\n0\n1\n1\n1\n\nOutput (to interactor)\n? 1 3\n? 7 6\n? 2 5\n? 6 2\n? 4 5\n? 4 6\n? 1 4\n! 4\n? 1 2\n? 2 3\n? 3 4\n? 4 1\n! 3\n\n(Explanation: After the first line \"2\" (number of test cases), each test case begins with n.\nThe numbers in \"Input\" after each n are the interactor's replies to the queries (lines starting with \"?\").\nNote that there is no reply from the interactor after answer lines (starting with \"!\").\nSince the grader is adaptive, the shown answers may differ from what you receive.)", "target": "", "metadata": {"track": "algorithmic", "problem_id": 245, "statement_path": "/Users/jingzhuohu/repos/Frontier-CS/algorithmic/problems/245/statement.txt", "config_path": "/Users/jingzhuohu/repos/Frontier-CS/algorithmic/problems/245/config.yaml"}} +{"context": "Given (1 <= n <= 1e2) and (B = 1e15), n integers a_1 … a_n (0 <= a_i <= B) drawn from either (normal, uniform, pareto, exponential) distributions, find a subset of a_1..a_n that sums as close as possible to T=x_i*a_i, x_i drawn from Bernoulli (1/2).\n\nScore = 100 * (15 - log(error + 1)) / 15\n\n25% of the test cases will be from U(0, B)\n25% of the test cases will be from N(B/2, B/6)\n25% of the test cases will be from Exp(B/2)\n25% of the test cases will be from TruncatedPareto(m=B/3, alpha=2, max=B)\n\nInput: \nn T\nA_1 a_2 a_3 a_4 .. a_n\n\n\n\nOutput: \nPrint a binary string of length n, denoting the subset selection.\n\nSample input: \n3 4\n1 2 3\n\nSample output:\n101", "target": "", "metadata": {"track": "algorithmic", "problem_id": 64, "statement_path": "/Users/jingzhuohu/repos/Frontier-CS/algorithmic/problems/64/statement.txt", "config_path": "/Users/jingzhuohu/repos/Frontier-CS/algorithmic/problems/64/config.yaml"}} +{"context": "Time Limit: 1 second\nMemory Limit: 256 mb\n\nInteractive Problem\n\nYOU MUST USE INTERACTIVE FORMAT FOR THIS PROBLEM.\n\nYou are standing in front of a row of n boxes, labeled 0 through n−1 from left to right.\nEach box contains a prize that cannot be seen until the box is opened. There are v ≥ 2\ndifferent prize types, numbered from 1 to v in decreasing order of value:\ntype 1 is the most expensive (the diamond), and type v is the cheapest (a lollipop).\nThere is exactly one diamond in the boxes.\n\nThe number of cheaper prizes is much larger than the number of more expensive ones.\nMore precisely, for all 2 ≤ t ≤ v: if there are k prizes of type t−1, then there are\nstrictly more than k^2 prizes of type t.\n\nYour task is to find the index i of the box containing the diamond using as few\nqueries as possible.\n\n-------------------------------------------------------------------------------\nInput\n-------------------------------------------------------------------------------\nStandard input (stdin) initially contains a single integer:\n n — the number of boxes.\n\nBox indices are 0-based: 0, 1, …, n−1.\n\n-------------------------------------------------------------------------------\nInteraction protocol (stdin/stdout)\n-------------------------------------------------------------------------------\nYour program communicates using standard input and standard output only.\nThere is no provided procedure to call; write a normal main program.\n\nTo ask about a box i (0 ≤ i < n):\n • Print a line: ? i\n • Flush the output stream immediately.\n\nThen read from stdin two integers a0 and a1 (on the same line):\n • a0 — among the boxes strictly to the left of i, the number of boxes that\n contain a more expensive prize than the one in box i.\n • a1 — among the boxes strictly to the right of i, the number of boxes that\n contain a more expensive prize than the one in box i.\n\nWhen you have determined the index i of the diamond (type 1), finish by:\n • Printing a line: ! i\n • Flushing the output, then terminating the program.\n\nNotes:\n • You may output extra whitespace on lines you print, but each command must be\n on its own line.\n • After each query line you print (\"? i\"), you must read exactly two integers.\n • In some test cases, the judge may be adaptive: its answers may depend on the\n questions you ask, but it will always remain consistent with the constraints.\n\n-------------------------------------------------------------------------------\nConstraints\n-------------------------------------------------------------------------------\n3 ≤ n ≤ 200000.\nEach prize type is an integer between 1 and v, inclusive.\nThere is exactly one prize of type 1 (the diamond).\nFor all 2 ≤ t ≤ v, if there are k prizes of type t−1, then there are strictly\nmore than k^2 prizes of type t.\n\n-------------------------------------------------------------------------------\nSubtasks\n-------------------------------------------------------------------------------\nSingle subtask: n ≤ 200000. (All constraints above apply.)\n\n-------------------------------------------------------------------------------\nExample (verbal transcript; no image)\n-------------------------------------------------------------------------------\nSuppose n = 8 and the hidden prize types are:\n index: 0 1 2 3 4 5 6 7\n types: 3 2 3 1 3 3 2 3\nHere, index 3 holds the diamond (type 1).\n\nPossible interaction:\n (read) 8\n (you) ? 0 → (judge replies) 0 3\n Meaning: left of 0 there are 0 more-expensive prizes; right of 0 there\n are 3 more-expensive prizes than the prize at 0.\n\n (you) ? 2 → (judge replies) 1 2\n Meaning: among indices {0,1}, exactly one is more expensive than 2’s;\n among {3,4,5,6,7}, exactly two are more expensive than 2’s.\n\n (you) ? 3 → (judge replies) 0 0\n Meaning: no box on either side is more expensive than 3’s prize.\n\n (you) ! 3 (finish)\n\nThe exact sequence of queries you make can differ; this is only an illustrative\ntranscript of the format.\n\n-------------------------------------------------------------------------------\nScoring\n-------------------------------------------------------------------------------\nLet q be the number of queries you print (i.e., the number of lines of the form \"? i\").\nYour raw score for a test is:\n 5000 − q (clamped below at 0 if needed).\nYour overall score is your average raw score divided by the best score.\n\n-------------------------------------------------------------------------------\nOutput\n-------------------------------------------------------------------------------\nPrint exactly one final line of the form:\n ! i\nwhere i is the index (0 ≤ i < n) of the box containing the diamond.\n\nIMPORTANT NOTE: Make sure to print out answer at the end of your code. Even if you did not find the diamond, print any arbitrary index before exiting.", "target": "", "metadata": {"track": "algorithmic", "problem_id": 127, "statement_path": "/Users/jingzhuohu/repos/Frontier-CS/algorithmic/problems/127/statement.txt", "config_path": "/Users/jingzhuohu/repos/Frontier-CS/algorithmic/problems/127/config.yaml"}} +{"context": "Time Limit: 10s\nMemory Limit: 1024M\n\nFirstly, you are given two integers n (1 <= n <= 400) and m (1 <= m <= 4000), which means that you have n elements and m sets.\n\nAfter that, there are m integers, the i-th integer is the cost of choosing the i-th set.\n\nAfter that, for the i-th element, firstly input an integer k_i, which means the number of sets that contain the element. After that, there\n\nare k_i integers, the j-th integer a_j means that the set with id a_j contains the element i.\n\nFind some sets so that each element belongs to at least one of these sets. You need to minimize the total cost of these sets. This value will determine your final score.\n\nOutput: \n\nFirstly output an integer |S|, which means the number of sets you choose. After that, output |S| ids of the sets you choose in another line.", "target": "", "metadata": {"track": "algorithmic", "problem_id": 50, "statement_path": "/Users/jingzhuohu/repos/Frontier-CS/algorithmic/problems/50/statement.txt", "config_path": "/Users/jingzhuohu/repos/Frontier-CS/algorithmic/problems/50/config.yaml"}} +{"context": "Guess Number\n\nThis is an interactive problem.\n\nVasya has thought of two secret integers a and b, both in the range [1, n]. Your task is to determine these two numbers by asking queries.\n\nEach query consists of two integers x and y (both in the range [1, n]). The interactor will respond with one of the following:\n\n- 0: Both x = a and y = b. You have successfully found the answer!\n- 1: x is less than a (x < a)\n- 2: y is less than b (y < b) \n- 3: x is greater than a OR y is greater than b (x > a or y > b)\n\nImportant: If multiple responses are true for your query, the interactor may choose any of them.\n\nYour goal is to find both numbers a and b using as few queries as possible.\n\nThis problem is graded based on the number of queries you use. In order to receive any points, you must use no more than 10,000 queries. Your answer will be compared to a reference solution ref_queries. Your final score will be calculated as the average of 100 * min((ref_queries + 1) / (your_queries + 1), 1) across all test cases.\n\nInput\n\nThere is only one test case in each test file.\n\nThe first line of the input contains an integer n (1 ≤ n ≤ 10^18) indicating the range of possible values.\n\nInteraction\n\nTo ask a query, output one line containing two integers x and y (1 ≤ x, y ≤ n) separated by a space. After flushing your output, your program should read a single integer representing the interactor's response (0, 1, 2, or 3).\n\nWhen you receive response 0, your program should terminate immediately.\n\nTo flush your output, you can use:\n- fflush(stdout) (if you use printf) or cout.flush() (if you use cout) in C and C++.\n- System.out.flush() in Java.\n- stdout.flush() in Python.\n\nExample\n\nInput:\n5\n\n3\n\n3\n\n2\n\n1\n\n0\nOutput:\n\n4 3\n\n3 4\n\n3 3\n\n1 5\n\n2 4\n\nTime limit: 2 seconds\nMemory Limit: 512 MB", "target": "", "metadata": {"track": "algorithmic", "problem_id": 134, "statement_path": "/Users/jingzhuohu/repos/Frontier-CS/algorithmic/problems/134/statement.txt", "config_path": "/Users/jingzhuohu/repos/Frontier-CS/algorithmic/problems/134/config.yaml"}} +{"context": "Find Median\n\nThis is an interactive problem.\n\nThere is a hidden permutation p of length n, where n is even.\nYou are allowed to make queries by choosing a subsequence of indices with even length k (where 4 ≤ k ≤ n). For a chosen subsequence, the interactor will return the two median values.\nFor a subsequence of even length k, the two medians are defined as the k/2-th and (k/2+1)-th smallest values in that subsequence.\n\nYour goal is to find the index of the two medians in permutation p. This problem is graded based on the number of queries you use. In order to receive any points, you must use no more than 500 queries. After that, your answer will be compared to a solution ref_queries. Your final score will be calculated as the average of 100 * min(ref_queries / your_queries, 1) across all cases.\n\nInput\n\nThe first line contains a single integer n (6 ≤ n ≤ 100, n is even) — the length of the hidden permutation.\n\nInteraction\n\nTo make a query, output one line in the following format:\n0 k x1 x2 ... xk\n\nwhere:\n- k is the length of the subsequence (4 ≤ k ≤ n, k must be even)\n- x1, x2, ..., xk are distinct indices between 1 and n\n\nAfter each query, read a line containing two integers m1 and m2 (1 ≤ m1 < m2 ≤ n) — the two median values of the subsequence.\n\nWhen you have found the answer, output one line in the following format:\n1 i1 i2 - the index of the two medians.\n\nAfter printing the answer, your program should terminate immediately.\n\nNote: The interactor is non-adaptive. The permutation is fixed before you start querying.\n\nTo flush your output, use:\n- fflush(stdout) or cout.flush() in C++\n- System.out.flush() in Java\n- stdout.flush() in Python\n\nExample Interaction\n\nInput:\n6\n\n3 4\n\n3 4\n\n2 3\n\nOutput:\n\n0 6 1 2 3 4 5 6\n\n0 4 3 6 1 5\n\n0 4 3 6 2 5\n\n1 3 6\n\nTime limit: 4 seconds\nMemory limit: 512 MB", "target": "", "metadata": {"track": "algorithmic", "problem_id": 144, "statement_path": "/Users/jingzhuohu/repos/Frontier-CS/algorithmic/problems/144/statement.txt", "config_path": "/Users/jingzhuohu/repos/Frontier-CS/algorithmic/problems/144/config.yaml"}} +{"context": "Story\n--------\nIn Japan, a traditional calligraphy contest known as 'Kakizome Taikai' is held during the New Year.\nAtCoder's Kakizome Taikai is an event in which, instead of writing with a brush, each employee types on a keyboard with a special key layout and outputs his/her favorite string on a PC screen for presentation.\n\nAfter learning many lucky words for this year through fortune-telling, CEO Takahashi decided to output a string containing all the lucky words as a (contiguous) substring (called a **lucky string**).\nFor example, if the lucky words are `AC`, `WA`, and `CE`, then `WHITESPACE` is not a **lucky string** because it does not contain `WA` as a substring, but `FACEWASH` is a **lucky string** because it contains all lucky words as substrings.\n\nMoving and typing fingers on the keyboard takes time depending on the distance between keys.\nBecause Takahashi is first in the order of presentation, he wants to type a **lucky string** as quickly as possible.\nPlease help him by creating a program to determine how to move his fingers.\n\n\nProblem Statement\n--------\nYou are given a key layout represented on an $N \\times N$ grid.\nLet $(0, 0)$ be the coordinates of the top-left square, and $(i, j)$ be the coordinates of the square located $i$ squares down and $j$ squares to the right from there.\nEach square contains an uppercase English letter $A_{i,j}$, and initially, the finger is placed on the square $(s_i, s_j)$.\n\nYou are given $M$ strings $t_1,\\cdots,t_M$ consisting of uppercase English letters.\nA string that contains all $t_k$ as (contiguous) substrings is defined as a **lucky string**.\nStarting with an empty string $S$, the goal is to make $S$ a **lucky string** by performing the following operations no more than $5000$ times.\n\n* Specify square $(i, j)$, move the finger to this square, and then append $A_{i, j}$ to the end of $S$. If the coordinates of the square where the finger was placed before the operation are $(i', j')$, this operation incurs a cost of $|i-i'|+|j-j'|+1$. The squares $(i, j)$ and $(i', j')$ can be the same, in which case the incurred cost is $1$.\n\nFind a sequence of operations that makes $S$ a **lucky string** with as little cost as possible.\n\nScoring\n--------\nLet $K$ be the number of $t_k$ contained in $S$ as (contiguous) substrings, and $T$ be the total cost of the operations.\nThen you will obtain the following score.\n\n* If $K\\lt M$, $\\mathrm{round}(1000 \\times (K+1)/M)$.\n* If $K=M$, $\\mathrm{max}(10000-T, 1001)$.\n\nIf the number of operations exceeds $5000$, or if a square outside the $N\\times N$ grid is specified, it will be judged as WA.\n\nThere are 150 test cases, and the score of a submission is the total score for each test case.\nIf your submission produces an illegal output or exceeds the time limit for some test cases, the submission itself will be judged as WA or TLE , and the score of the submission will be zero.\nThe highest score obtained during the contest will determine the final ranking, and there will be no system test after the contest.\nIf more than one participant gets the same score, they will be ranked in the same place regardless of the submission time.\n\n\nInput\n--------\nInput is given from Standard Input in the following format:\n\n~~~\n$N$ $M$\n$s_i$ $s_j$\n$A_{0,0}$$A_{0,1}$$\\cdots$$A_{0,N-1}$\n$A_{1,0}$$A_{1,1}$$\\cdots$$A_{1,N-1}$\n$\\vdots$\n$A_{N-1,0}$$A_{N-1,1}$$\\cdots$$A_{N-1,N-1}$\n$t_1$\n$\\vdots$\n$t_M$\n~~~\n\n* $N=15$\n* $M=200$\n* $0\\le s_i,s_j\\le N-1$\n* $A_{i,0}A_{i,1}\\cdots A_{i,N-1}$ is a string of length $N$ consisting of uppercase English letters.\n* $t_k$ is a string of length $5$ consisting of uppercase English letters.\n* $t_k\\ne t_{k'}$ $(k\\ne k')$\n* For every uppercase $c$, it is guaranteed that there exists at least one coordinate $(i,j)$ such that $A_{i,j}=c$.\n\nOutput\n--------\nLet $L$ be the number of operations and $(i_l, j_l)$ $(0\\le i_l, j_l\\le N-1)$ be the square specified in the $l$-th operation.\nThen, output to Standard Output in the following format.\n\n~~~\n$i_1$ $j_1$\n$\\vdots$\n$i_L$ $j_L$\n~~~\n\nShow example\n\n\nInput Generation\n--------\n
\nLet $\\mathrm{rand}(L,U)$ be a function that generates a uniform random integer between $L$ and $U$, inclusive.\n\n#### Generation of $(s_i,s_j)$\nGenerate $s_i=\\mathrm{rand}(0, N-1)$ and $s_j=\\mathrm{rand}(0, N-1)$.\n\n#### Generation of $A_{i,j}$\nFor each $(i, j)$, generate $A_{i,j}$ uniformly at random from uppercase English letters.\nIf there exists an uppercase letter that is not included in any $A_{i,j}$, regenerate all $A_{i,j}$.\n\n#### Generation of $t_k$\nFor each $k$, generate a string $t_k$ of length $5$ by randomly generating uppercase English letters $5$ times.\nIf there is an already generated $t_{k'}$ with $t_k=t_{k'}$, regenerate $t_k$.\nFinally, sort $t_1, t_2, \\cdots, t_M$ in lexicographic order.\n\n
\n\nTools (Input generator and visualizer)\n--------\n\n- Web version: This is more powerful than the local version and can display animations.\n- Local version: You need a compilation environment of Rust language.\n\t- Pre-compiled binary for Windows: If you are not familiar with the Rust language environment, please use this instead.\n\nPlease be aware that sharing visualization results or discussing solutions/ideas during the contest is prohibited.\n\n{sample example}", "target": "", "metadata": {"track": "algorithmic", "problem_id": 165, "statement_path": "/Users/jingzhuohu/repos/Frontier-CS/algorithmic/problems/165/statement.txt", "config_path": "/Users/jingzhuohu/repos/Frontier-CS/algorithmic/problems/165/config.yaml"}} +{"context": "Permutation (Interactive Problem)\n\nTime limit: 10s\nMemory limit: 1024MB\n\nYou are given an unknown permutation of length n. Your task is to determine the position of number n\nin this permutation.\n\nInteraction Protocol\n--------------------\nTo help you find the position of n, you may ask queries of the following form:\n\n? l r (1 ≤ l < r ≤ n)\n\nIn response, the interactor will return the position of the second largest number in the interval [l, r].\n\nAfter you finish asking queries for one test case, you must output the answer in the following form:\n\n! x (x is the position of number n)\n\nConstraints\n-----------\n- 1 ≤ T ≤ 10000, where T is the number of test cases.\n- 2 ≤ n ≤ 100000.\n- The sum of n over all test cases does not exceed 100000.\n- The sum of (r − l + 1) over all queries in a test case must not exceed 30n.\n\nScoring\n-------\nLet x be the number of queries asked in one test case, and let log2n = log2(n).\n\n- If x = log2n, the score for this test case is 100.\n- If x = 15·log2n, the score for this test case is 0.\n- For values of x in between, the score is computed by linear interpolation:\n\n score(x, n) = 100 * (15·log2n − x) / (14·log2n)\n\n- If x < log2n, the score is clamped to 100.\n- If x > 15·log2n, the score is clamped to 0.\n\nThe final score of your submission is the minimum score among all test cases.\n\nNotes\n-----\n- After printing each query or answer, do not forget to flush the output.\n- The interactor is non-adaptive: the permutation is fixed at the beginning of each test case.\n- Each query \"? l r\" is answered in O(r − l) time by the interactor.\n- Solutions must be submitted in C++ only.", "target": "", "metadata": {"track": "algorithmic", "problem_id": 17, "statement_path": "/Users/jingzhuohu/repos/Frontier-CS/algorithmic/problems/17/statement.txt", "config_path": "/Users/jingzhuohu/repos/Frontier-CS/algorithmic/problems/17/config.yaml"}} +{"context": "# Subset Sum\n\n## Problem\n\nYou are given a multiset of non-negative integers.\nYour task is to choose a subset whose sum is as close as possible to a given target value W.\n\nThis is the classic Subset Sum problem, evaluated with a soft scoring rule.\n\n## Input Format\n\n- Line 1: two integers n and W\n (1 ≤ n ≤ 2100)\n- Line 2: n integers a₁, a₂, ..., aₙ\n - aᵢ ≥ 0\n - All numbers (including W and aᵢ) can be up to 10^1100.\n\n## Output Format\n\n- Output exactly one line:\n - n integers b₁, b₂, ..., bₙ\n - each bᵢ ∈ {0, 1}\n - bᵢ = 1 means aᵢ is selected into the subset\n - bᵢ = 0 means aᵢ is not selected\n\n## Scoring\n\nLet:\n\n- S = sum of all aᵢ where bᵢ = 1\n- M = max(aᵢ) over all i\n\nYour goal is to make S as close to W as possible.\n\nScore is defined as:\n\n score = max(0, 1 - |W - S| / (W + M))\n\nNotes:\n- The score is always in the range [0, 1]\n- Achieving S = W yields score = 1\n- Any valid output is accepted and scored\n\n## Hint\n\n- Large integer arithmetic may be required", "target": "", "metadata": {"track": "algorithmic", "problem_id": 179, "statement_path": "/Users/jingzhuohu/repos/Frontier-CS/algorithmic/problems/179/statement.txt", "config_path": "/Users/jingzhuohu/repos/Frontier-CS/algorithmic/problems/179/config.yaml"}} +{"context": "F. Guess Divisors Count\n\ntime limit per test: 2 seconds\nmemory limit per test: 256 megabytes\ninput: standard input\noutput: standard output\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\nWe have hidden an integer 1 ≤ X ≤ 10^9. You don't have to guess this number. You have to find the number of divisors of this number, and you don't even have to find the exact number: your answer will be considered correct if its absolute error is not greater than 7 or its relative error is not greater than 0.5.\nMore formally, let your answer be ans and the number of divisors of X be d, then your answer will be considered correct if at least one of the two following conditions is true:\n * | ans - d | ≤ 7;\n * 1/2 ≤ ans / d ≤ 2.\n\nYou can make at most 100 queries. One query consists of one integer 1 ≤ Q ≤ 10^18. In response, you will get gcd(X, Q) — the greatest common divisor of X and Q.\n\nThe number X is fixed before all queries. In other words, interactor is not adaptive.\nLet's call the process of guessing the number of divisors of number X a game. In one test you will have to play T independent games, that is, guess the number of divisors T times for T independent values of X. Let q be the maximum number of queries you asked among all games, your score will be (100 - q) / 100.\n\nInput\n\nThe first line of input contains one integer T (1 ≤ T ≤ 100) — the number of games.\n\nInteraction\n\nTo make a query print a line \"0 Q\" (1 ≤ Q ≤ 10^18). After that read one integer gcd(X, Q). You can make no more than 100 such queries during one game.\nIf you are confident that you have figured out the number of divisors of X with enough precision, you can print your answer in \"1 ans\" format. ans have to be an integer. If this was the last game, you have to terminate the program, otherwise you have to start the next game immediately. Note that the interactor doesn't print anything in response to you printing answer.\n\nAfter printing a query do not forget to output end of line and flush the output. To do this, use:\n * fflush(stdout) or cout.flush() in C++;\n * System.out.flush() in Java;\n * flush(output) in Pascal;\n * stdout.flush() in Python;\n * see documentation for other languages.\n\nExample\nInput (from interactor to you)\n\n 2\n\n 1\n\n 1\n\n 1\n\n 1024\n\n 1048576\n\n 4194304\n\nOutput (from you to interactor)\n\n 0 982306799268821872\n\n 0 230856864650023977\n\n 0 134690134760714371\n\n 1 5\n 0 1024\n\n 0 1048576\n\n 0 1073741824\n\n 1 42\n\nNote\n\nLet's look at the example.\nIn the first game X = 998244353 is hidden. Would be hard to guess this, right? This number is prime, so the number of its divisors is 2. The solution has made several random queries, and all the responses turned out to be 1 (strange things, not even one of three random numbers is divisible by 998244353). It's fare to assume that the hidden number doesn't have many divisors, so the solution has answered 5. Why not. This answer will be considered correct since | 5 - 2 | = 3 ≤ 7.\nIn the second game X = 4,194,304 = 2^22 is hidden, it has 23 divisors. The solution has made queries 1024 = 2^10, 1,048,576 =2^20, 1,073,741,824 = 2^30 and got responses 1024 = 2^10, 1,048,576 =2^20, 4,194,304 = 2^22, respectively. Then the solution got completely confused and answered the answer to The Ultimate Question of Life, the Universe, and Everything.\nThis answer will be considered correct since 1/2 ≤ 42 / 23 ≤ 2.", "target": "", "metadata": {"track": "algorithmic", "problem_id": 107, "statement_path": "/Users/jingzhuohu/repos/Frontier-CS/algorithmic/problems/107/statement.txt", "config_path": "/Users/jingzhuohu/repos/Frontier-CS/algorithmic/problems/107/config.yaml"}} +{"context": "Title: Kangaroos\n\nGoal\nYou must print a grid (“map”) on which a simple multi-agent movement game is played. The judge will run 500 random control sequences on your map. Your map is accepted if at least 125 of those sequences fail to gather all agents into a single cell.\n\nWorld\n- The world is an n-by-m grid (1 ≤ n, m ≤ 20).\n- Each cell is either empty (1) or a wall (0).\n- Initially, every empty cell contains exactly one kangaroo (agent).\n- A move command is one of: U (up), D (down), L (left), R (right).\n- On each command, all kangaroos move simultaneously:\n * If the adjacent cell in that direction exists and is empty, the kangaroo moves there.\n * Otherwise, it stays where it is.\n\nMap requirements\n- Grid size at most 20 × 20.\n- There must be at least two empty cells.\n- The subgraph of empty cells must be connected (you can go between any two empty cells by moving only through empty cells).\n- The subgraph of empty cells must be acyclic (no cycles). In other words, the empty cells form a tree.\n\nJudging\n- The judge generates 500 random control strings, each of length 50,000.\n- Each character in a control string is chosen independently and uniformly from {U, D, L, R}.\n- In 1 string, if after applying all 50,000 moves there are still at least two kangaroos in different cells (i.e., not all agents have gathered into one cell), then you earn 1 point for that testcase.\n- Your goal is to try and maximize your score over 500 random testcases.\n- If your map violates any of the legality rules above (size, connectedness, no cycles, etc.), it is rejected regardless of performance.\n\nInput\n- There is no input. You only print the map.\n\nOutput\n1) Print two integers: n m (1 ≤ n, m ≤ 20).\n2) Then print n lines, each a string of length m consisting only of characters ‘0’ and ‘1’.\n - ‘1’ means the cell is empty.\n - ‘0’ means the cell is a wall.\n\nExample (format only; not necessarily valid as a final map)\n3 4\n1111\n1010\n1100\n\nNotes\n- The judge’s random strings are produced by a standard uniform choice among U, D, L, R (e.g., typical rand()%4 mapping).\n- Make sure your map satisfies all “Map requirements”; otherwise it will be rejected even if it performs well on the random tests.\n- When printing out the grid, you should actually provide a c++ code which will print out the grid when run.", "target": "", "metadata": {"track": "algorithmic", "problem_id": 137, "statement_path": "/Users/jingzhuohu/repos/Frontier-CS/algorithmic/problems/137/statement.txt", "config_path": "/Users/jingzhuohu/repos/Frontier-CS/algorithmic/problems/137/config.yaml"}} +{"context": "Time Limit: 2 s\nMemory Limit: 1024 MB\nThis is an interactive problem.\nBitaro found out that a string S of length N was written on the stone slate. Each character of the string is either ‘0’ or ‘1’. However, he does not yet know each character of the string S.\nBibako found out how to use the machine. To use it, we put the stone slate on the machine, input an integer m and two sequences of integers a, b, and make a query. Here the integer m and the sequences of integers a, b should satisfy:\n- 1 <= m <= 1002\n- Both of the lengths of the sequences a, b are equal to m.\n- Every element of the sequences a, b is an integer between 0 and m - 1, inclusive.\nIf we put the stone slate on the machine, input an integer m and two sequences of integers a, b, and make a query, the machine will operate as follows and will show an integer.\n 1. The machine sets 0 in the memory area of the machine.\n 2. The machine performs the following N operations. The (i + 1)-th (0 <= i <= N - 1) operation proceeds as follows.\nLet x be the current integer set in the memory area of the machine. The machine reads the character S_i (0<=i