diff --git a/ace/ace.py b/ace/ace.py index 2d662adc..f713f889 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 ) @@ -672,6 +680,17 @@ def _offline_train( error_logs = [] best_accuracy = 0.0 self.best_playbook = self.playbook + metrics_eval_path = os.path.join(save_path, "metrics_eval.jsonl") + checkpoints_index_path = os.path.join(save_path, "checkpoints_index.jsonl") + + # Start each offline run with fresh metric/checkpoint index logs. + for p in (metrics_eval_path, checkpoints_index_path): + with open(p, "w", encoding="utf-8") as _f: + _f.write("") + + def append_jsonl(path: str, payload: Dict[str, Any]) -> None: + with open(path, "a", encoding="utf-8") as f: + f.write(json.dumps(payload, ensure_ascii=False) + "\n") print(f"Total epochs: {num_epochs}") print(f"Train samples per epoch: {len(train_samples)}") @@ -731,6 +750,16 @@ def _offline_train( ) with open(intermediate_path, "w") as f: f.write(self.playbook) + append_jsonl(checkpoints_index_path, { + "timestamp": datetime.now().isoformat(), + "checkpoint_type": "intermediate", + "epoch": epoch, + "step": step, + "global_step": (epoch - 1) * len(train_samples) + step, + "path": intermediate_path, + "playbook_num_tokens": count_tokens(self.playbook), + "playbook_length": len(self.playbook), + }) # Periodic evaluation if step % eval_steps == 0: @@ -748,6 +777,7 @@ def _offline_train( # Validation evaluation val_results = {} + val_error_log = {} if val_samples: val_results, val_error_log = evaluate_test_set( data_processor, self.generator, self.playbook, @@ -774,6 +804,21 @@ def _offline_train( "val_results": val_results, "error_log": val_error_log }) + append_jsonl(metrics_eval_path, { + "timestamp": datetime.now().isoformat(), + "epoch": epoch, + "step": step, + "global_step": (epoch - 1) * len(train_samples) + step, + "train_pre_accuracy": pre_train_accuracy, + "train_post_accuracy": post_train_accuracy, + "val_mean_score": val_results.get("mean_score"), + "val_accuracy": val_results.get("accuracy"), + "val_format_valid_count": val_results.get("format_valid_count"), + "val_evaluated_count": val_results.get("evaluated_count"), + "val_failed_count": val_error_log.get("failed_count", 0), + "playbook_num_tokens": count_tokens(self.playbook), + "playbook_length": len(self.playbook), + }) # Track best playbook if val_results: @@ -801,6 +846,16 @@ def _offline_train( ) with open(epoch_playbook_path, "w") as f: f.write(self.playbook) + append_jsonl(checkpoints_index_path, { + "timestamp": datetime.now().isoformat(), + "checkpoint_type": "epoch_final", + "epoch": epoch, + "step": len(train_samples), + "global_step": epoch * len(train_samples), + "path": epoch_playbook_path, + "playbook_num_tokens": count_tokens(self.playbook), + "playbook_length": len(self.playbook), + }) # Save training results results_path = os.path.join(save_path, "train_results.json") @@ -818,11 +873,32 @@ def _offline_train( final_playbook_path = os.path.join(save_path, f"final_playbook.txt") with open(final_playbook_path, "w") as f: f.write(self.playbook) + append_jsonl(checkpoints_index_path, { + "timestamp": datetime.now().isoformat(), + "checkpoint_type": "final_playbook", + "epoch": num_epochs, + "step": len(train_samples), + "global_step": num_epochs * len(train_samples), + "path": final_playbook_path, + "playbook_num_tokens": count_tokens(self.playbook), + "playbook_length": len(self.playbook), + }) # Save best playbook best_playbook_path = os.path.join(save_path, f"best_playbook.txt") with open(best_playbook_path, "w") as f: f.write(self.best_playbook) + append_jsonl(checkpoints_index_path, { + "timestamp": datetime.now().isoformat(), + "checkpoint_type": "best_playbook", + "epoch": num_epochs, + "step": len(train_samples), + "global_step": num_epochs * len(train_samples), + "path": best_playbook_path, + "best_validation_accuracy": best_accuracy, + "playbook_num_tokens": count_tokens(self.best_playbook), + "playbook_length": len(self.best_playbook), + }) print(f"\n{'='*60}") print(f"OFFLINE TRAINING COMPLETE") diff --git a/ace/core/generator.py b/ace/core/generator.py index 3ceebecc..0fd4bb07 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 3304ca76..d01041b6 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_all.jsonl b/eval/frontier-cs/data/algorithmic_all.jsonl new file mode 100644 index 00000000..b2539a39 --- /dev/null +++ b/eval/frontier-cs/data/algorithmic_all.jsonl @@ -0,0 +1,172 @@ +{"context": "# Pack the Polyominoes (Reflections Allowed)\n\n## Problem\nYou are given a set of n polyominoes placed on a unit square grid. Each polyomino consists of between 1 and 10 unit cells, connected edge-to-edge (4-connectivity). Your task is to place all polyominoes—allowing **rotations, reflections, and translations**—into an axis-aligned rectangle of the grid with no overlaps and no cells outside the rectangle, minimizing the rectangle’s area.\n\nA placement specifies, for every polyomino, an integer translation, an optional reflection, and a rotation by a multiple of 90°, such that:\n\n- every cell lands on integer grid coordinates,\n- no two placed cells overlap,\n- all placed cells lie within a single axis-aligned rectangle of width W and height H.\n\nThe objective is to minimize A = W × H. In case of ties on area, prefer smaller H, then smaller W.\n\n---\n\n## Input Format\n- Line 1: integer n (100 <= n <= 10^4) — number of polyominoes. \n- For each polyomino i = 1 … n:\n - One line: integer kᵢ (1 ≤ kᵢ ≤ 10) — number of cells.\n - Next kᵢ lines: two integers xᵢⱼ, yᵢⱼ — cell coordinates in the polyomino’s local frame. \n These coordinates define a 4-connected polyomino.\n\nNotes:\n- Coordinates may be negative.\n- Shapes may have internal holes.\n- Shapes are defined by structure; initial placement does not matter.\n\n---\n\n## Output Format\n- Line 1: two integers W and H — width and height of the chosen rectangle.\n- Then n lines — one per polyomino i, each containing:\n$$X_i\\ Y_i\\ R_i\\ F_i$$\n\nWhere:\n- (Xᵢ, Yᵢ): integer translation \n- Rᵢ ∈ {0,1,2,3}: number of 90° clockwise rotations \n- Fᵢ ∈ {0,1}: reflection flag (**1 = reflect across the y-axis before rotation**, 0 = no reflection)\n\nAll transformed cells must satisfy:\n0 ≤ xᵢⱼ′ < W, 0 ≤ yᵢⱼ′ < H, W=H\n\n---\n\n## Rules\n1. All cells occupy unit squares with integer coordinates. \n2. **Allowed transforms: reflection (optional) → rotation (0°, 90°, 180°, 270°) → translation (in that order).** \n3. Distinct polyomino cells must not overlap. \n4. Every cell must lie inside [0, W) × [0, H). \n5. Scoring: Minimize A = W × H.\n\n---\n\n## Constraints\n- 100 ≤ n ≤ 10000\n- 1 ≤ kᵢ ≤ 10 \n\n---\n\n## Validation\nA solution is valid if:\n- All rules are satisfied. \n- The judge verifies non-overlap and bounding-box compliance.\n\n---\n\n## Scoring (for heuristic / leaderboard contests)\n- Per test case: score = 1e5*Σkᵢ/A\n- Any invalid test case → entire submission rejected\n\n---\n\n## Example\n\nInput\n```\n3\n1\n0 0\n3\n0 0\n1 0\n0 1\n4\n0 0\n1 0\n0 1\n1 1\n```\n\nOutput\n```\n3 3\n0 0 0 0\n2 0 1 0\n1 1 0 0\n```\n\nThis places the monomino at (0,0), rotates the triomino by 90° (R=1), and fits all shapes into a 3×3 rectangle. (Reflections are allowed, but not used in this example: F=0.)\n\n---\n\n## Generation\n\nLet $S$ be the set of all pieces from size 1-10. Each piece is chosen uniformly at random with replacement from $S$. \n\n$n$ is chosen as $10^p$, where $p \\sim U(2, 4)$.", "target": "", "metadata": {"track": "algorithmic", "problem_id": 0, "statement_path": "/Users/jingzhuohu/repos/Frontier-CS/algorithmic/problems/0/statement.txt", "config_path": "/Users/jingzhuohu/repos/Frontier-CS/algorithmic/problems/0/config.yaml", "interactive": false}} +{"context": "Problem F: Treasure Packing\n\nA dragon has terrorized the region for decades, breathing fire and stealing treasures. A hero has decided to steal back the treasures and return them to the community. However, they drastically underestimated the size of the dragon's hoard, bringing only a single 25 liter bag, only strong enough to hold 20 kg, to carry out the treasures. The hero has decided to try to return as much value as possible. The dragon has 12 different types of items of different values, masses, and volumes: crowns, figurines, jeweled goblets, gold helms, etc., where each item of the same type has the same mass and volume. For example, all goblets have the same mass and volume. Write a program helping the hero determine what items they should put in the bag so as to maximize value accounting for the constraints on the bag.\n\nInput\nThe input is JSON keyed by treasure category name, such as \"goblet\". Every category has a unique name composed of at most 100 lowercase ASCII characters. There are exactly twelve treasure categories. Each corresponding value is a list with one integer q (1 <= q <= 10000) and three integers v (0 < v <= 10^9), m (0 < m <= 20 * 10^6), and l (0 < l <= 25 * 10^6), where q is the maximum number of treasures of this category that can be looted, v is the value of one item, m is the mass (in mg) of one item, and l the volume (in µliters) of one item. (There are one million mg per kg and µliters per liter.)\n\nPlease see the sample input for an example of how the JSON is formatted.\n\nOutput\nPrint a JSON with the same keys as the input, but with single a nonnegative integer values giving the numbers of items of that category added to the bag in your solution.\n\nScoring\nProducing an algorithm that always generates optimal solutions is very difficult, so your solution only needs to be \"good enough\". We will compare your output to a baseline heuristic provided by the NSA, and to a best effort to compute the true optimum. You must beat the NSA heuristic to receive points; after that, the better your solution, the higher your score. Specifically, your score on this problem is your average of the per-test-case score.\n\n100 * clamp((your value - baseline value) / (best value - baseline value), 0, 1).\n\nTime limit: \n1 second\n\nMemoriy limit:\n1024 MB\n\nSample input:\n{\n \"circlet\": [\n 19,\n 113005,\n 146800,\n 514247\n ],\n \"coppercoin\": [\n 887,\n 6171,\n 12593,\n 18081\n ],\n \"crown\": [\n 13,\n 726439,\n 1079353,\n 1212213\n ],\n \"dagger\": [\n 21,\n 279513,\n 558367,\n 522344\n ],\n \"figurine\": [\n 18,\n 26272,\n 1488281,\n 2295986\n ],\n \"goblet\": [\n 22,\n 300053,\n 698590,\n 986387\n ],\n \"goldcoin\": [\n 129,\n 14426,\n 82176,\n 27597\n ],\n \"helm\": [\n 3,\n 974983,\n 2470209,\n 882803\n ],\n \"jewelry\": [\n 23,\n 272450,\n 171396,\n 262226\n ],\n \"plate\": [\n 22,\n 98881,\n 246257,\n 363420\n ],\n \"silvercoin\": [\n 288,\n 12587,\n 53480,\n 28654\n ],\n \"torc\": [\n 17,\n 244957,\n 388222,\n 500000\n ]\n}\n\nSample Output:\n{\n \"circlet\": 2,\n \"coppercoin\": 8,\n \"crown\": 13,\n \"dagger\": 0,\n \"figurine\": 0,\n \"goblet\": 0,\n \"goldcoin\": 0,\n \"helm\": 0,\n \"jewelry\": 23,\n \"plate\": 0,\n \"silvercoin\": 1,\n \"torc\": 4\n}", "target": "", "metadata": {"track": "algorithmic", "problem_id": 1, "statement_path": "/Users/jingzhuohu/repos/Frontier-CS/algorithmic/problems/1/statement.txt", "config_path": "/Users/jingzhuohu/repos/Frontier-CS/algorithmic/problems/1/config.yaml", "interactive": false}} +{"context": "Permutation\n\nThis is an interactive problem.\n\nThere is a hidden permutation of n. Recall that a permutation of n is a sequence where each integer from 1 to n (both inclusive) appears exactly once. Piggy wants to unravel the permutation with some queries.\n\nEach query must consist of a sequence (not necessarily a permutation) with n integers ranging from 1 to n (both inclusive). Each query is answered with an integer x, indicating the number of the positions where the corresponding element in Piggy's query sequence matches that of the hidden permutation. For example, if the hidden permutation is {1, 3, 4, 2, 5} and the sequence Piggy asks is {2, 3, 5, 2, 5}, he'll receive 3 as the answer.\n\nAs Piggy is busy recently, he gives this problem to you. This problem is graded based on the number of queries you recieve. In order to receive any points, you must get better than a baseline of 10000 queries. After that, your answer will be compared to a solution best_queries.\nYour final score will be calculated as the average of 100 * clamp((10000 - your_queries)/(10000 - best_queries), 0, 1) across all 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^3) indicating the length of the hidden permutation.\n\nInteraction\n\nTo ask a query, output one line. First output 0 followed by a space, then print a sequence of n integers ranging from 1 to n separated by a space. After flushing your output, your program should read a single integer x indicating the answer to your query.\n\nIf you want to guess the permutation, output one line. First output 1 followed by a space, then print a permutation of n separated by a space. 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\nExample\n\n(The example content is missing from the provided text).\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\nTime limit: 4 seconds\n\nMemory Limit: 1024 MB\n\nExample input:\n\n0 3 1 3 2 2\n\n0 3 1 5 2 2\n\n0 3 5 4 4 4\n\n1 3 1 5 2 4\n\nExample output:\n5\n\n3\n\n4\n\n2", "target": "", "metadata": {"track": "algorithmic", "problem_id": 2, "statement_path": "/Users/jingzhuohu/repos/Frontier-CS/algorithmic/problems/2/statement.txt", "config_path": "/Users/jingzhuohu/repos/Frontier-CS/algorithmic/problems/2/config.yaml", "interactive": true}} +{"context": "This is an interactive question.\n\ntime limit: 10 seconds (up to 5 seconds for interactive library)\nSpace limitations: 1GB (up to 64MB for interactive library)\n\nDescription\nHope City is a city built on a floating island. At the edge of the floating island, there are n lamp sockets evenly distributed, forming a ring shape. Each lamp holder is labeled with a number between 1 and n, and forms an arrangement of length n in a clockwise direction p1, p2,..., pn. You don't know this arrangement and hope to restore it through interaction with the system.\n\nYou can ask the system to switch the state of a set of lamp holders at a time (if it was not originally lit, it will be lit; if it was originally lit, it will be extinguished).\n\nThe system will maintain a set of currently lit lamp holders S (initially empty) internally. You cannot directly see the contents of the set, but you can obtain the following information through interaction:\n\nYou can submit a set of operations at once (i.e. a series of target IDs for wick input), and the system will process each of these operations one by one:\n\n- If a lamp holder is not in S, it will be lit up after inserting the wick (add into S);\n- If a lamp holder is already in S, it will be extinguished up after inserting the wick (remove it from S);\n- After each operation, the system will record whether there is a pair of adjacent lamp holders on the ring in the current set S, and return the records of all operations together.\nAfter you submit a set of operations at once and receive the returned records, S will not be cleared, but will continue to serve as the initial set for the next set of operations.\n\nInput\nOne line, contains two integers, subtask, n, representing the subtask ID and the length of the loop;\n\nImplementation Details\nTo ask a query, output one line. First output a number L followed by a space, then print a sequence of L integers ranging from 1 to n separated by a space. \nAfter flushing your output, your program should read a sequence of L integers, indicating whether there are adjacent pairs in S after each operation.\nSpecifically, The system will maintain a set S, which is initially the result of the previous query (i.e. not reset), and sequentially scans each element u in this query:\nIf u is not in S when scanned, perform an operation to light up u so that u is in S; if u is in S when scanned, perform an operation to extinguish u so that u is not in S. Then report an integer indicating whether there are adjacent pairs in S after this operation(0: does not exist; 1: exist).\n\nIf you want to guess the permutation, output one line. First output -1 followed by a space, then print a permutation of n separated by a space, representing the arrangement of lamp holder numbers p1~pn. Since the ring has no starting point or direction, any cyclic shift of p1~pn or p1~pn is considered correct. 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:\nfflush(stdout) (if you use printf) or cout.flush() (if you use cout) in C and C++.\n\nSubtask\nSubtask 1 (10 points): Ensure n=1000.\nSubtask 2 (90 points): Ensure n=10 ^ 5.\n\nFor a testcase, if your interaction process is illegal or the returned answer is incorrect, you will directly receive 0 points.\n\nOtherwise, record the total number of times you call query as t, and record the sum of the number of operations you perform each time when calling query as Q.\n\nYour score ratio lambda will be calculated according to the following formula:\nlambda=max (0, 1-0.1 (f (t/18)+f (Q/ (1.5 * 10^7)))\nWhere f (x)=min (max (log_2 (x), 0), 8)\nThen, if the subtask where this testcase is located has a maximum score of S, then you will get lambda * S.\n\nThe total number of times you call query cannot exceed 10 ^ 7, and the sum of the number of operations you perform each time when calling 'query' cannot exceed 3 * 10 ^ 8.\nTo prevent unexpected behavior caused by a large vector, you also need to ensure that the number of operations in a single query call always does not exceed 10 ^ 7.\n\nInteractive Example\nAssuming n=4 and the arrangement of lamp holder is [2,4,1,3], the following is a valid interaction process:\n\nPlayer Program | Interaction Library | Description\n- | Call solve (4, 0) | Start the interaction process\nCall query ([1, 2]) | Return [0, 0] | Found that the two lamp holders with numbers 1 and 2 are not adjacent on the ring\nCall query ([1, 2]) | Return [0, 0] | extinguish 1,2\nCall query ([1, 3]) | Return [0, 1] | Found that two lamp holders with numbers 1 and 3 are adjacent on the ring\nCall query ([1, 3]) | Return [0, 0] | extinguish 1,3\nCall query ([1, 4]) | Return [0, 1] | Found that two lamp holders with numbers 1,4 are adjacent on the ring\nCall query ([1, 4]) | Return [0, 0] | extinguish 1,4\nCall query ([2, 3]) | Return [0, 1] | Found that two lamp holders with numbers 2 and 3 are adjacent on the ring\nCall query ([2, 3]) | Return [0, 0] | extinguish 2,3\nCall query ([2, 4]) | Return [0, 1] | Found that two lamp holders with numbers 2 and 4 are adjacent on the ring\nCall query ([2, 4]) | Return [0, 0] | extinguish 2,4\nCall query ([3, 4]) | Return [0, 0] | Found that the two lamp holders with numbers 3 and 4 are not adjacent on the ring\nCall query ([3, 4]) | Return [0, 0] | extinguish 3,4\nRun ends and returns [1, 4, 2, 3] | Print interaction result to screen | Interaction ends, result is correct", "target": "", "metadata": {"track": "algorithmic", "problem_id": 3, "statement_path": "/Users/jingzhuohu/repos/Frontier-CS/algorithmic/problems/3/statement.txt", "config_path": "/Users/jingzhuohu/repos/Frontier-CS/algorithmic/problems/3/config.yaml", "interactive": true}} +{"context": "Problem: Matrix k-th Smallest (Interactive)\n\nYou are given an unknown n×n matrix a. You must find the k-th smallest value among all a[i][j].\nYou cannot read the matrix directly. Instead, you must interact with the judge using the protocol below.\nThe matrix satisfies:\nfor all i<=n and j> create_map(int N, int M,\n std::vector A, std::vector B) \nN: the number of countries.\nM: the number of pairs of adjacent countries.\nA and B: arrays of length M describing adjacent countries.\nThe procedure should return an array C that represents the map. Let K be the length of C.\nEach element of C must be an array of length K, containing integers between 1 and N\ninclusive.\nC[i][j] is the color of the cell at row i and column j (for each i and j such that 0≤i,j=1), indicating the number of test cases. For each test case:\n- The first line contains a single integer n (10=0) meaning the number of operations you used.\nThen m lines follow, where each line starts with an integer 0<=ki