TAROT: Test-driven and Capability-adaptive Curriculum Reinforcement Fine-tuning for Code Generation with Large Language Models
Organizations: Electronics and Telecommunications Research Institute · The Hong Kong University of Science and Technology (Guangzhou) · The Hong Kong University of Science and Technology · Hugging Face ·
Abstract
Large Language Models (LLMs) are changing the coding paradigm, known as vibe coding, yet synthesizing algorithmically sophisticated and robust code still remains a critical challenge. Incentivizing the deep reasoning capabilities of LLMs is essential to overcoming this hurdle. Reinforcement Fine-Tuning (RFT) has emerged as a promising strategy to address this need. However, most existing approaches overlook the heterogeneous difficulty and granularity inherent in test cases, leading to an imbalanced distribution of reward signals and consequently biased gradient updates during training. To address this, we propose Test-driven and cApability-adaptive cuRriculum reinfOrcement fine-Tuning (TAROT). TAROT systematically constructs, for each problem, a four-tier test suite (basic, intermediate, complex, edge), providing a controlled difficulty landscape for curriculum design and evaluation. Crucially, TAROT decouples curriculum progression from raw reward scores, enabling capability-conditioned evaluation and principled selection from a portfolio of curriculum policies rather than incidental test-case difficulty composition. This design fosters stable optimization and more efficient competency acquisition. Extensive experimental results reveal that the optimal curriculum for RFT in code generation is closely tied to a model's inherent capability, with less capable models achieving greater gains with an easy-to-hard progression, whereas more competent models excel under a hard-first curriculum. TAROT provides a reproducible method that adaptively tailors curriculum design to a model's capability, thereby consistently improving the functional correctness and robustness of the generated code. All code and data are released to foster reproducibility and advance community research at https://github.com/deep-diver/TAROT.
Figures & tables
| Strategy | Reward Weights (B, I, C, E) | Curriculum Schedule Progression |
| Forward (Uniform) | (0.25, 0.25, 0.25, 0.25) | B (B,I) (B,I,C) All |
| Forward (B & I Weighted) | (0.35, 0.35, 0.15, 0.15) | B (B,I) (B,I,C) All |
| Forward (C & E Weighted) | (0.15, 0.15, 0.35, 0.35) | B (B,I) (B,I,C) All |
| Reversed (C & E Weighted) | (0.15, 0.15, 0.35, 0.35) | C (C,E) (C,E,I) All |
| Basic Only | (1.0, 0.0, 0.0, 0.0) | Static |
| Complex Only | (0.0, 0.0, 1.0, 0.0) | Static |
| Strategy | HumanEval | HumanEval+ | MBPP | MBPP+ |
| Base | 89.02% | 78.66% | 52.60% | 56.61% |
| C/E Weighted | 91.46% (+2.44pp) | 82.92% (+4.26pp) | 55.20% (+2.60pp) | 58.73% (+2.12pp) |
| Model | Strategy | HumanEval | HumanEval+ | MBPP | MBPP+ | CodeForces | LCBv5 | CruxEval |
| Qwen2.5-1.5B-Instruct | Avg-reward | 59.15% | 54.27% | 49.20% | 57.93% | 2.72% | 3.70% | 38.75/32.87% |
| Pass@All | 60.98% | 56.10% | 44.60% | 53.43% | 2.72% | 3.94% | 34.62/31.75% | |
| TAROT (Best) | 60.98% | 55.49% | 51.80% | 58.20% | 4.49% | 5.26% | 40.20/33.75% | |
| Qwen2.5-7B-Instruct | Avg-reward | 83.75% | 76.22% | 66.00% | 69.84% | 11.41% | 11.95% | 56.37/58.50% |
| Pass@All | 81.10% | 73.78% | 63.00% | 68.52% | 9.49% | 14.81% | 55.62/56.63% | |
| TAROT (Best) | 84.15% | 77.44% | 69.00% | 70.63% | 12.95% | 19.12% | 57.88/59.38% |
| Strategy | HumanEval | HumanEval+ | MBPP | MBPP+ | CodeForces | LCBv5 | CruxEval |
| Base | 60.37% | 54.88% | 59.60% | 65.08% | 8.61% | 11.83% | 45.63/47.63% |
| Uniform | 65.85 % | 57.93% | 59.20% | 64.55% | 10.82% | 13.62% | 51.63 /47.13% |
| Basic Only | 63.41% | 56.10% | 60.40 % | 65.08% | 9.49% | 14.70 % | 51.00/48.00% |
| Complex Only | 65.85 % | 60.37 % | 58.60% | 64.55% | 9.93% | 12.54% | 48.25/48.00% |
Appendix figures & tables18 assets
Supplementary material from the paper’s appendix.
Appendix
| You are an expert software engineer with extensive experience in designing comprehensive unit tests. Your task is to generate four distinct unit tests for a given code implementation based solely on the provided problem statement. Treat this as a black-box testing exercise—focus exclusively on the inputs and expected outputs without assuming any details about the internal implementation. Important: A baseline test case will be provided separately. Each test case you generate must be more challenging than the baseline test case. Please generate four unit tests with the following guidelines: 1. Basic Complexity Test (label as "basic"): • Use simple, straightforward inputs. • Validate the core behavior under normal conditions. • Focus on the happy path scenario. • This should be the least challenging test case relative to the others. 2. Medium Complexity Test (label as "intermediate"): • Include moderately complex inputs with some edge conditions. • Test with mixed data types or larger inputs. • Incorporate common edge cases and boundary values. • Ensure this test is more challenging than the basic test. 3. High Complexity Test (label as "complex"): • Use complex, nested, or structured inputs. • Validate advanced functionality and complex logic paths. • Stress test the implementation with challenging scenarios. • This test should be more intricate than both the basic and intermediate tests. 4. Edge Case Test (label as "edge"): • Use extreme boundary conditions and special cases. • Validate behavior with empty, null, or invalid inputs. • Focus on error handling and exception scenarios. • This should be the most challenging test case among the four. For each test case, follow the JSON format provided in the example below (include only the input and expected output): ⬇ { " language ": " python ", " test_cases ": [ { " input ": "4\ n4 \ n0001 \ n1000 \ n0011 \ n0111 \ n3 \ n010 \ n101 \ n0 \ n2 \ n00000 \ n00001 \ n4 \ n01 \ n001 \ n0001 \ n00001 \ n ", " output ": "1\ n3 \ n -1\ n0 \ n \ n2 \ n1 2 \ n ", " type ": " stdin_stdout ", " label ": " basic ", " reason ": " This test represents simple , straightforward input conditions ." } ] } Remember: • Do not assume any knowledge about the internal code; base your tests purely on the input-output behavior described in the problem statement. • Ensure that each of your test cases is incrementally more challenging than the baseline test case provided. |
| Problem Statement: {problem_statement} Baseline Test Case: {baseline_test_case} |
| Strategy | HumanEval | HumanEval+ | MBPP | MBPP+ | CodeForces | LCBv5 | CruxEval |
| Base | 42.07% | 34.76% | 41.20% | 47.09% | 2.21% | 4.30% | 37.50/26.88% |
| Uniform | 39.02 % | 31.09 % | 33.80 % | 39.95 % | 0.22 % | 3.58 % | 33.00 / 26.63 % |
| B/I Weighted | 35.98 % | 32.32 % | 35.60 % | 42.06 % | 0.22 % | 4.30% | 38.63 / 27.25 % |
| C/E Weighted | 41.46 % | 34.15 % | 39.20 % | 48.41 % | 0.22 % | 3.94 % | 36.63 / 26.75 % |
| C/E Weighted (Rev) | 40.86 % | 35.37 % | 40.20 % | 44.44 % | 0.44 % | 3.94 % | 35.63 / 26.75 % |
| Basic Only | 44.51 % | 37.20 % | 38.60 % | 46.83 % | 1.77 % | 3.94 % | 39.88 / 27.88 % |
| Model | Strategy | HumanEval | HumanEval+ | MBPP | MBPP+ | CodeForces | LCBv5 | CruxEval |
| Qwen3-Coder-30B-A3B-Instruct | ||||||||
| Base | 94.51% | 86.59% | 73.80% | 75.13% | 29.65% | 37.63% | 81.75/79.25% | |
| Qwen3-4B-Instruct-2507 | ||||||||
| Base | 89.02% | 78.66% | 52.60% | 56.61% | 33.63% | 32.02% | 78.25/ 77.75% | |
| Uniform | 88.41% | 80.09% | 35.30% | 53.70% | 31.86% | 31.96% | 79.37/75.75% | |
| B/I Weighted | 89.63% | 81.09% | 28.00% | 52.38% | 33.04% | 33.81% | 79.50/75.38% | |
| Model | Strategy | HumanEval | HumanEval+ | MBPP | MBPP+ | CodeForces | LCBv5 | CruxEval |
| Qwen2.5-7B-Instruct | ||||||||
| Base | 82.93% | 75.61% | 63.20% | 67.46% | 8.54% | 14.10% | 57.75/58.00% | |
| Uniform | 82.93% | 73.78% | 67.40% | 67.46% | 12.36% | 14.93% | 57.88 / 59.38% | |
| B/I Weighted | 78.05% | 76.83% | 67.60% | 69.58% | 11.56% | 15.89% | 57.25/59.25% | |
| C/E Weighted | 79.27% | 73.78% | 66.20% | 70.37% | 10.89% | 15.77% | 57.13/55.50% | |
| C/E Weighted (Rev) | 84.15% | 77.44% | 69.00% | 70.11% | 8.24% | 15.41% | 57.88 /56.38% | |
| Solve the following coding problem using the programming language python: You are given two positive integer numbers a and b. Permute (change order) of the digits of a to construct maximal number not exceeding b. No number in input and/or output can start with the digit 0. It is allowed to leave a as it is. Input The first line contains integer a ( ). The second line contains integer b ( ). Numbers don’t have leading zeroes. It is guaranteed that answer exists. Output Print the maximum possible number that is a permutation of digits of a and is not greater than b. The answer can’t have any leading zeroes. It is guaranteed that the answer exists. The number in the output should have exactly the same length as number a. It should be a permutation of digits of a. Examples Input 123 222 Output 213 Input 3921 10000 Output 9321 Input 4940 5000 Output 4940 The input will be given via stdin and the output should be printed to stdout by your code. Now solve the problem by providing the code. | ||||
| Test cases | Basic | Intermediate | Complex | Edge |
| Input | 21 12 | 3051 5310 | 98761230 98765000 | 111222333444555666 1000000000000000000 |
| Output | 12 | 5310 | 98763210 | 666555444333222111 |
| Reason | A simple 2-digit case where swapping the digits yields the only valid permutation bound, illustrating the happy path. | A 4-digit case including zero, requiring the algorithm to match the upper bound exactly with a permutation of the digits. | An 8-digit case where matching the bound fails at a later position, forcing backtracking and a maximal tail fill. | An extreme boundary case with an 18 - digit input and a longer 19 - digit bound, where any valid permutation fits, so the result is the digits sorted in descending order. |
| Solve the following coding problem using the programming language python: Winter is here at the North and the White Walkers are close. John Snow has an army consisting of n soldiers. While the rest of the world is fighting for the Iron Throne, he is going to get ready for the attack of the White Walkers. He has created a method to know how strong his army is. Let the -th soldier’s strength be . For some , we call the indices a clan if and . The strength of that clan is defined as . The strength of the army is defined by the sum of the strengths of all possible clans. Your task is to find the strength of his army. As the number may be very large, you have to print it modulo 1000000007 ( ). Greatest common divisor ( ) of a sequence of integers is the maximum possible integer so that each element of the sequence is divisible by it. -----Input----- The first line contains integer n the size of the army. The second line contains n integers denoting the strengths of his soldiers. -----Output----- Print one integer the strength of John Snow’s army modulo 1000000007 ( ). -----Examples----- Input 3 3 3 1 Output 12 Input 4 2 3 4 6 Output 39 -----Note----- In the first sample the clans are so the answer will be The input will be stdin and you should print your solution to stdout Now solve the problem and return the code. | ||||
| Test cases | Basic | Intermediate | Complex | Edge |
| Input | 4 2 3 5 7 | 6 2 4 8 3 9 6 | 7 2 2 2 2 2 2 2 | 5 1 1 1 1 1 |
| Output | 17 | 119 | 896 | 0 |
| Reason | All strengths are prime, so only single-soldier clans contribute. | Mix of primes and composites yields clans of various sizes and gcds. | Uniform strengths where every nonempty subset is a valid clan (gcd=2). | All strengths are 1, so no clan has gcd>1; result is zero. |
| Solve the following coding problem using the programming language python: A permutation is a sequence of length n integers from 1 to n, in which all the numbers occur exactly once. For example, [1], [3, 5, 2, 1, 4], [1, 3, 2] permutations, and [2, 3, 2], [4, 3, 1], [0] no. Polycarp was recently gifted a permutation a[1 …n] of length n. Polycarp likes trees more than permutations, so he wants to transform permutation a into a rooted binary tree. He transforms an array of different integers into a tree as follows: • The maximum element of the array becomes the root of the tree; • All elements to the left of the maximum form a left subtree (which is built according to the same rules but applied to the left part of the array), but if there are no elements to the left of the maximum, then the root has no left child; • All elements to the right of the maximum form a right subtree (which is built according to the same rules but applied to the right side of the array), but if there are no elements to the right of the maximum, then the root has no right child. For example, if he builds a tree by permutation a = [3, 5, 2, 1, 4], then the root will be the element = 5, and the left subtree will be the tree that will be built for the subarray a[1 …1] [3], and the right one for the subarray a[3 …5] [2, 1, 4]. As a result, the following tree will be built: <image> The tree corresponding to the permutation a=[3, 5, 2, 1, 4]. Another example: let the permutation be a=[1, 3, 2, 7, 5, 6, 4]. In this case, the tree looks like this: <image> The tree corresponding to the permutation a=[1, 3, 2, 7, 5, 6, 4]. Let us denote by the depth of the vertex , that is, the number of edges on the path from the root to the vertex numbered . Note that the root depth is zero. Given the permutation a, for each vertex, find the value of . Input The first line contains one integer t the number of test cases. Then t test cases follow. The first line of each test case contains an integer n the length of the permutation. This is followed by n numbers permutation a. Output For each test case, output n values . Example Input 3 5 3 5 2 1 4 1 1 4 4 3 1 2 Output 1 0 2 3 1 0 0 1 3 2 The input will be stdin and you should print your solution to stdout Now solve the problem and return the code. | ||||
| Test cases | Basic | Intermediate | Complex | Edge |
| Input | 1 3 1 2 3 | 2 4 2 1 4 3 5 5 4 3 2 1 | 1 10 3 8 2 5 10 9 1 7 4 6 | 1 15 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
| Output | 2 1 0 | 1 2 0 1 0 1 2 3 4 | 2 1 3 2 0 1 3 2 4 3 | 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 |
| Reason | Simple ascending permutation forming a left - skewed tree under normal conditions. | Includes a mixed permutation and a strictly decreasing permutation to test right - skewed tree and boundary values. | Complex permutation of length 10 to test multiple recursion levels and both left and right subtrees. | Maximum ascending chain of length 15 to test deep recursion and large boundary condition. |
| Solve the following coding problem using the programming language python: Princess’Marriage Marriage of a princess English text is not available in this practice contest. A brave princess in a poor country, knowing that gambling payouts are determined by the parimutuel method, felt more familiar with gambling and was convinced of her victory in gambling. As a result, he spent more money than ever before and lost enough to lose all the taxes paid by the people. The King, who took this situation seriously, decided to marry the princess to the neighboring country. By doing this, I thought that I would like the princess to reflect on her daily activities and at the same time deepen her friendship with neighboring countries and receive financial assistance. The princess and the prince of the neighboring country liked each other, and the kings of both countries agreed on a political marriage. The princess triumphantly went to the neighboring country with a little money in her hand. On the other hand, the motive for the princess to marry is to pursue the unilateral interests of the king, and the aide of the prince of the neighboring country who thinks that it is not pleasant shoots countless thugs along the way to make the princess dead. It was. The path the princess will take has already been decided. There are a total of L post stations on the path of the princess. For convenience, the departure and arrival points are also set as post stations, and each post station is called S1, S2, …SL. The princess shall be in S1 first, visit the post station in ascending order (S2, S3 …in that order), and finally go to SL. At the post station, you can pay money to hire an escort, and as long as you have the money, you can contract for as long as you like to protect the princess. The cost of hiring an escort is 1 gold per distance. Note that the princess can also partially protect the section through which she passes. The distance between Si and Si + 1 is given by Di, and the expected value of the number of times a thug is attacked per distance between Si and Si + 1 is given by Pi. Find the expected number of thugs to reach your destination when the princess has a budget of M and hires an escort to minimize the expected number of thugs. Input The input consists of multiple datasets. Each dataset has the following format. > N M > D1 P1 > D2 P2 > ... > DN PN Two integers are given in the first row of each dataset, representing the number of intervals N and the budget M of the princess difference, respectively. The next N lines show information about the path the princess takes. Each line contains two integers, and the i-th line is the expected value of the interval Di and the number of attacks when moving one unit distance between them Pi ). The end of the input is represented by a data set with N = 0 and M = 0. Do not output the calculation result for this data set. Output For each dataset, output the expected number of times the princess will be attacked by thugs to your destination. Sample Input 2 8 5 6 4 5 3 1 5 10 5 10 5 10 0 0 Output for the Sample Input Five 140 The input will be given via stdin and the output should be printed to stdout by your code. | ||||
| Test cases | Basic | Intermediate | Complex | Edge |
| Input | 4 7 3 2 4 1 1 5 2 2 0 0 | 6 12 5 3 2 0 7 2 3 3 4 1 6 2 0 0 | 10 30 10 1 5 5 8 5 6 3 12 2 4 5 7 3 9 4 3 0 11 2 0 0 | 3 0 5 2 10 4 7 3 4 100 5 2 10 4 7 3 8 0 2 1000 100 0 200 0 0 0 |
| Output | 3 | 22 | 83 | 71 0 0 |
| Reason | Simple scenario with multiple segments and straightforward positive Pi values; tests basic greedy coverage under a limited budget. | Moderate number of segments including Pi=0, ensuring segments with no attacks are ignored and budget partially covers higher-Pi segments. | Larger set of segments with ties in Pi values and varied distances, requiring correct sorting and partial coverage among equal-Pi segments. | Edge conditions including zero budget, budget exceeding total distance, and segments with Pi=0 to verify no-protection and full-protection behaviors. |
| Solve the following coding problem using the programming language python: Valera loves his garden, where n fruit trees grow. This year he will enjoy a great harvest! On the i-th tree fruit grow, they will ripen on a day number . Unfortunately, the fruit on the tree get withered, so they can only be collected on day and day (all fruits that are not collected in these two days, become unfit to eat). Valera is not very fast, but there are some positive points. Valera is ready to work every day. In one day, Valera can collect no more than v fruits. The fruits may be either from the same tree, or from different ones. What is the maximum amount of fruit Valera can collect for all time, if he operates optimally well? -----Input----- The first line contains two space-separated integers n and v the number of fruit trees in the garden and the number of fruits that Valera can collect in a day. Next n lines contain the description of trees in the garden. The i-th line contains two space-separated integers and the day the fruits ripen on the i-th tree and the number of fruits on the i-th tree. -----Output----- Print a single integer the maximum number of fruit that Valera can collect. -----Examples----- Input 2 3 1 5 2 3 Output 8 Input 5 10 3 20 2 20 1 20 4 20 5 20 Output 60 -----Note----- In the first sample, in order to obtain the optimal answer, you should act as follows. On the first day collect 3 fruits from the 1-st tree. On the second day collect 1 fruit from the 2-nd tree and 2 fruits from the 1-st tree. On the third day collect the remaining fruits from the 2-nd tree. In the second sample, you can only collect 60 fruits, the remaining fruit will simply wither. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code. | ||||
| Test cases | Basic | Intermediate | Complex | Edge |
| Input | 2 5 1 3 3 4 | 3 1 1 2 2 2 3 2 | 5 5 1 4 2 6 2 3 5 10 6 2 | 2 1000 2999 1500 3000 2500 |
| Output | 7 | 4 | 25 | 3000 |
| Reason | No overlapping ripening days and capacity exceeds daily fruits; collect all fruits on their ripening days. | Capacity is only 1 per day with overlapping two-day windows; requires optimal scheduling across consecutive days. | Multiple trees ripen on the same days, gaps between ripening days, and moderate capacity to stress multi-day planning. | Ripening on the maximum allowed days (2999 and 3000) tests boundary handling and two-day collection windows at the end of the range. |
| Solve the following coding problem using the programming language python: Bessie the cow has just intercepted a text that Farmer John sent to Burger Queen! However, Bessie is sure that there is a secret message hidden inside. The text is a string of lowercase Latin letters. She considers a string as hidden in string if exists as a subsequence of whose indices form an arithmetic progression. For example, the string aab is hidden in string aaabb because it occurs at indices , , and , which form an arithmetic progression with a common difference of . Bessie thinks that any hidden string that occurs the most times is the secret message. Two occurrences of a subsequence of are distinct if the sets of indices are different. Help her find the number of occurrences of the secret message! For example, in the string aaabb, a is hidden times, b is hidden times, ab is hidden times, aa is hidden times, bb is hidden time, aab is hidden times, aaa is hidden time, abb is hidden time, aaab is hidden time, aabb is hidden time, and aaabb is hidden time. The number of occurrences of the secret message is . -----Input----- The first line contains a string of lowercase Latin letters ( ) — the text that Bessie intercepted. -----Output----- Output a single integer the number of occurrences of the secret message. -----Examples----- Input aaabb Output 6 Input usaco Output 1 Input lol Output 2 -----Note----- In the first example, these are all the hidden strings and their indice sets: a occurs at , , b occurs at , ab occurs at , , , , , aa occurs at , , bb occurs at aab occurs at , aaa occurs at abb occurs at aaab occurs at aabb occurs at aaabb occurs at Note that all the sets of indices are arithmetic progressions. In the second example, no hidden string occurs more than once. In the third example, the hidden string is the letter l. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code. | ||||
| Test cases | Basic | Intermediate | Complex | Edge |
| Input | abab | abacaba | abababab | z |
| Output | 3 | 6 | 10 | 1 |
| Reason | A simple alternating pattern to validate basic subsequence counting. | Mixed letters and repeating patterns to test moderately complex subsequences. | Longer alternating pattern to stress test counting of many arithmetic-progression subsequences. | Minimal input length boundary case. |
| Solve the following coding problem using the programming language python: The ZCO scholarship contest offers scholarships to first time ZCO participants. You are participating in it for the first time. So you want to know the number of participants who’ll get the scholarship. You know that the maximum number of scholarships offered is and there are a total of participants numbered from to . Out of these, you know the set of people (denoted by ) who you know, had participated in previous year ZCOs and hence, they shall not get the scholarship. Further, as the world isn’t free from plagiarism, so is the case with the scholarship contest. And from your secret sources, you also know the set of people (denoted by set ) who were involved in plagiarism and therefore aren’t eligible for scholarship either. Find out the number of participants who shall get the scholarship. PS: Don’t ask how so many scholarships are being offered when you see the constraints on . You never questioned it when in mathematics classes, some person bought watermelons twice just to compare them and save 1. -----Input:----- - The first line will contain a single integer, , the number of testcases. Then the testcases follow. - The first line of each test case contains four integers; , , and denoting the number of participants, maximum number of scholarships offered, number of old participants, and the number of participants involved in plagiarism, respectively. - The second line of each test case contains space separated integers denoting the indices of people who participated in previous years. If is empty, this line is skipped and no empty line is in the input. - The third line of each test case contains space separated integers denoting the indices of people who are involved in plagiarism. If is empty, this line is skipped and no empty line is in input. -----Output:----- For each testcase, print a single integer in a new line, denoting the number of participants who shall get the scholarship. -----Constraints----- - - - - - - All are distinct - All are distinct - Sum of over all test cases does not exceed - Sum of over all test cases does not exceed -----Subtasks----- - 20 points : , and the sum of over all test cases does not exceed - 30 points : , and the sum of over all test cases does not exceed - 50 points: Original constraints -----Sample Input:----- 3 5 3 0 1 4 10 2 4 6 3 1 7 6 4 3 1 5 9 7 10 4 4 6 3 1 7 6 4 3 1 5 9 7 -----Sample Output:----- 3 2 3 -----EXPLANATION:----- - In the first testcase, only participant is involved in plagiarism, and thus not eligible for the scholarship. No user has participated in previous years, and so no empty line is there in the sample. All participants except participant are eligible for the scholarship, but only three of them get it because . - Both second and third testcases are the same, except for . In both samples, only participants , and are eligible for scholarships. - In the second testcase, since the maximum number of scholarships is , only participants get scholarships. - In the third testcase, all three eligible participants get scholarships. The input will be stdin and you should print your solution to stdout | ||||
| Test cases | Basic | Intermediate | Complex | Edge |
| Input | 1 4 2 1 1 1 4 | 2 7 4 3 2 2 4 5 4 6 5 1 0 2 3 5 | 3 1000000000000 1000000000000 2 3 1 1000000000000 500000000000 1 999999999999 20 15 5 5 1 2 3 4 5 4 5 6 7 8 50 100 3 2 10 20 30 30 40 | 2 1000000000000000 0 0 0 5 10 3 3 1 2 3 3 4 5 |
| Output | 2 | 3 1 | 999999999996 12 46 | 0 0 |
| Reason | Basic test with a single test case, non-empty X and Y sets without overlap, validating core functionality. | Medium complexity with multiple test cases, overlapping X and Y in the first, and an empty X set in the second. | High complexity with very large N and R values, moderate X and Y sizes, and multiple test cases to stress-test the implementation. | Edge case with maximum boundary values and zero scholarships in the first, and X and Y covering all participants in the second, testing empty sets and full exclusion. |
| Solve the following coding problem using the programming language python: Polycarp has recently got himself a new job. He now earns so much that his old wallet can’t even store all the money he has. Berland bills somehow come in lots of different sizes. However, all of them are shaped as rectangles (possibly squares). All wallets are also produced in form of rectangles (possibly squares). A bill fits into some wallet if either and or and . Bills can overlap with each other in a wallet and an infinite amount of bills can fit into a wallet. That implies that all the bills Polycarp currently have fit into a wallet if every single one of them fits into it independently of the others. Now you are asked to perform the queries of two types: — Polycarp earns a bill of size ; — Polycarp wants to check if all the bills he has earned to this moment fit into a wallet of size . It is guaranteed that there is at least one query of type before the first query of type and that there is at least one query of type in the input data. For each query of type print "YES" if all the bills he has earned to this moment fit into a wallet of given size. Print "NO" otherwise. -----Input----- The first line contains a single integer ( ) — the number of queries. Each of the next lines contains a query of one of these two types: ( ) — Polycarp earns a bill of size ; ( ) — Polycarp wants to check if all the bills he has earned to this moment fit into a wallet of size . It is guaranteed that there is at least one query of type before the first query of type and that there is at least one query of type in the input data. -----Output----- For each query of type print "YES" if all the bills he has earned to this moment fit into a wallet of given size. Print "NO" otherwise. -----Example----- Input 9 + 3 2 + 2 3 ? 1 20 ? 3 3 ? 2 3 + 1 5 ? 10 10 ? 1 5 + 1 1 Output NO YES YES YES NO -----Note----- The queries of type of the example: Neither bill fits; Both bills fit (just checking that you got that bills can overlap); Both bills fit (both bills are actually the same); All bills fit (too much of free space in a wallet is not a problem); Only bill fit (all the others don’t, thus it’s "NO"). The input will be stdin and you should print your solution to stdout | ||||
| Test cases | Basic | Intermediate | Complex | Edge |
| Input | 4 + 4 5 ? 5 4 ? 4 4 ? 6 4 | 7 + 2 7 + 3 3 + 7 2 ? 3 7 ? 4 6 + 10 1 ? 10 5 | 13 + 5 5 + 6 4 + 9 1 ? 5 5 ? 9 1 ? 4 9 + 2 8 ? 8 9 + 7 7 ? 7 7 ? 8 7 ? 10 8 ? 6 6 | 8 + 1000000000 1 + 1 1000000000 + 500000000 500000000 ? 1000000000 1000000000 ? 999999999 1000000000 ? 1000000000 499999999 + 1000000000 1000000000 ? 1000000000 1000000000 |
| Output | YES NO YES | YES NO YES | NO NO NO YES NO NO YES NO | YES YES NO YES |
| Reason | Single bill with queries testing orientation and size validation under straightforward conditions. | Multiple bills including duplicates and interleaved adds and queries testing correct global dimension tracking. | Complex interleaving of many adds and queries with varying dimensions to stress test global maximum computations. | Extreme boundary values testing maximum limits and strict comparison edge where one dimension is just below requirement. |
| Solve the following coding problem using the programming language python: Valera had an undirected connected graph without self-loops and multiple edges consisting of n vertices. The graph had an interesting property: there were at most k edges adjacent to each of its vertices. For convenience, we will assume that the graph vertices were indexed by integers from 1 to n. One day Valera counted the shortest distances from one of the graph vertices to all other ones and wrote them out in array d. Thus, element d[i] of the array shows the shortest distance from the vertex Valera chose to vertex number i. Then something irreparable terrible happened. Valera lost the initial graph. However, he still has the array d. Help him restore the lost graph. Input The first line contains two space-separated integers n and k . Number n shows the number of vertices in the original graph. Number k shows that at most k edges were adjacent to each vertex in the original graph. The second line contains space-separated integers d[1], d[2], ..., d[n] . Number d[i] shows the shortest distance from the vertex Valera chose to the vertex number i. Output If Valera made a mistake in his notes and the required graph doesn’t exist, print in the first line number -1. Otherwise, in the first line print integer m the number of edges in the found graph. In each of the next m lines print two space-separated integers ai and bi , denoting the edge that connects vertices with numbers ai and bi. The graph shouldn’t contain self-loops and multiple edges. If there are multiple possible answers, print any of them. Examples Input 3 2 0 1 1 Output 3 1 2 1 3 3 2 Input 4 2 2 0 1 3 Output 3 1 3 1 4 2 3 Input 3 1 0 0 0 Output -1 The input will be given via stdin and the output should be printed to stdout by your code. | ||||
| Test cases | Basic | Intermediate | Complex | Edge |
| Input | 4 2 0 1 1 2 | 7 3 0 1 2 2 1 2 3 | 10 3 0 1 1 1 2 2 2 2 2 3 | 5 3 0 2 2 3 3 |
| Output | 3 1 2 1 3 2 4 | 6 1 2 1 5 2 3 2 4 5 6 3 7 | 9 1 2 1 3 1 4 2 5 2 6 3 7 3 8 4 9 5 10 | -1 |
| Reason | Simple BFS tree with one level-2 vertex. | Moderately sized tree with branching and various depths. | Larger tree with multiple branches and depth-3 leaf. | No vertices at distance 1, invalid distance sequence |
| Solve the following coding problem using the programming language python: The game of Berland poker is played with a deck of cards, of which are jokers. players play this game ( is divisible by ). At the beginning of the game, each player takes cards from the deck (so each card is taken by exactly one player). The player who has the maximum number of jokers is the winner, and he gets the number of points equal to , where is the number of jokers in the winner’s hand, and is the maximum number of jokers among all other players. If there are two or more players with maximum number of jokers, all of them are winners and they get points. Here are some examples: , , . If one player gets jokers and plain card, and another player gets jokers and plain cards, then the first player is the winner and gets points; , , . Two players get plain cards, and the other two players get jokers, so both of them are winners and get points; , , . If the first player gets jokers, the second player gets joker and plain cards, and the third player gets jokers and plain card, then the first player is the winner, and he gets point; , , . Since there are no jokers, everyone gets jokers, everyone is a winner, and everyone gets points. Given , and , calculate the maximum number of points a player can get for winning the game. -----Input----- The first line of the input contains one integer ( ) — the number of test cases. Then the test cases follow. Each test case contains three integers , and ( , , , is a divisors of ). -----Output----- For each test case, print one integer — the maximum number of points a player can get for winning the game. -----Example----- Input 4 8 3 2 4 2 4 9 6 3 42 0 7 Output 3 0 1 0 -----Note----- Test cases of the example are described in the statement. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code. | ||||
| Test cases | Basic | Intermediate | Complex | Edge |
| Input | 3 9 2 3 12 5 4 6 5 3 | 5 20 10 5 15 3 5 10 10 2 14 7 7 18 17 3 | 7 50 25 25 49 49 7 48 20 6 30 0 5 32 16 4 45 23 9 28 14 7 | 6 2 0 2 2 2 2 50 0 25 50 50 50 50 25 5 50 1 2 |
| Output | 2 2 0 | 2 3 0 1 0 | 1 0 5 0 5 2 2 | 0 0 0 0 6 1 |
| Reason | Simple small cases covering scenarios where jokers are fewer than, equal to, or exceed the per-player limit. | Moderate-sized inputs, testing exact division of jokers, no jokers, and tied maximum distributions. | Varied larger values including big decks, testing heavy distributions and zero-joker scenarios. | Extreme boundary conditions with minimal and maximal n, k, and m values to test edge handling. |
LLM Code Generation
Large language model code generation studies how models translate instructions and context into executable programs and how to make them reliable.
See all 309 papers