First AI to Beat Every Human in a Programming Competition - Agentic GRPO Explained

Reddit r/LocalLLaMA Papers

Summary

GrandCode is a multi-agent reinforcement learning system that achieves grandmaster level in competitive programming, consistently beating all human participants in live Codeforces contests using a novel Agentic GRPO method.

* Traditional RL for LLMs treats one answer as one trajectory: * prompt > reasoning > final answer > reward * Agentic systems are different: * they call tools * generate hypotheses * run tests * debug code * summarize context * revise plans * loop many times before success That creates a hard RL problem: * rewards arrive very late * trajectories are very long * the policy changes while rollouts are still running (“off-policy drift”) Agentic GRPO is meant to stabilize learning in this setting. # First: what is GRPO? GRPO stands for Group Relative Policy Optimization. It is an RL algorithm similar in spirit to PPO: * sample multiple outputs * compare them against each other * reward relatively better ones * update the model toward better trajectories Instead of requiring a perfect scalar reward calibration, it uses relative ranking/normalization inside a group of samples. The paper builds on GRPO and adapts it for “agentic” multi-stage workflows. # Core intuition of Agentic GRPO Imagine an AI coding agent solving a hard programming problem. The workflow might be: 1. propose hypothesis 2. generate algorithm 3. write code 4. generate tests 5. run tests 6. debug failures 7. retry 8. finally pass In standard RL: * the model might only get reward at the very end * all earlier actions must wait * training becomes slow and unstable Agentic GRPO changes this by introducing: 1. Immediate rewards 2. Delayed correction # The key innovation The paper describes it as: * update immediately when intermediate feedback appears * later apply a correction once the final outcome is known So instead of waiting until the entire rollout finishes: *stage1 > stage2 > stage3 > final reward* the system does: *stage1 reward > update now* *stage2 reward > update now* *stage3 reward > update now* *later:* *final reward arrives* *retroactively correct earlier updates* # Analogy Think of training a junior programmer. Traditional RL: * wait until the whole project ships * then say “good job” or “bad job” Agentic GRPO: * give feedback continuously: * “that hypothesis was useful” * “that test caught a bug” * “this optimization helped” * but later revise the evaluation: * “actually the early design decision caused problems” So learning becomes: * faster * denser * more stable # This solve RL specifically for: * long-horizon LLM agents * coding agents * autonomous workflows The most recent best result, Google’s Gemini 3 Deep Think, attained 8th place. This new solution is the first AI system that consistently beats all human participants in live contests of competitive programming:
Original Article
View Cached Full Text

Cached at: 05/23/26, 11:55 AM

# GrandCode: Achieving Grandmaster Level in Competitive Programming via Agentic Reinforcement Learning
Source: [https://arxiv.org/html/2604.02721](https://arxiv.org/html/2604.02721)
###### Abstract

Competitive programming remains one of the last few human strongholds in coding against AI\. The best AI system to date still underperforms the best humans competitive programming: the most recent best result, Google’s Gemini 3 Deep Think, attained 8th place even not being evaluated under live competition conditions\. In this work, we introduce GrandCode, a multi\-agent RL system designed for competitive programming\. The capability of GrandCode is attributed to two key factors: \(1\) It orchestrates a variety of agentic modules \(hypothesis proposal, solver, test generator, summarization, etc\) and jointly improves them through post\-training and online test\-time RL; \(2\) We introduce Agentic GRPO specifically designed for multi\-stage agent rollouts with delayed rewards and the severe off\-policy drift that is prevalent in agentic RL\. GrandCode is the first AI system that consistently beats all human participants in live contests of competitive programming: in the most recent three Codeforces live competitions, i\.e\., Round 1087 \(Mar 21, 2026\), Round 1088 \(Mar 28, 2026\), and Round 1089 \(Mar 29, 2026\), GrandCode placed first in all of them, beating all human participants, including legendary grandmasters\. GrandCode shows that AI systems have reached a point where they surpass the strongest human programmers on the most competitive coding tasks\.🖂

![[Uncaptioned image]](https://arxiv.org/html/2604.02721v1/standings/overview.png)

Figure 1:Codeforces standings overview for the three live contests in which GrandCode participated\. GrandCode ranked first place in all three contests and being the first to finish all tasks in each of them\.

🖂🖂footnotetext:Email: \{xiaoya\_li, xiaofei\_sun, songqiao\_su, chris\_shum, jiwei\_li\}@deep\-reinforce\.com;∗\*independent researcher\.## 1Introduction

Despite rapid progress in AI for coding, the strongest current AI systems still fall short of the best human competitors in competitive programming\. At the same time, the rapid improvement of large language models\[OpenAI,[2023](https://arxiv.org/html/2604.02721#bib.bib21);[2024a](https://arxiv.org/html/2604.02721#bib.bib22);[2024b](https://arxiv.org/html/2604.02721#bib.bib23), Llama Team, AI @ Meta,[2024](https://arxiv.org/html/2604.02721#bib.bib18), Google DeepMind,[2025](https://arxiv.org/html/2604.02721#bib.bib7), Moonshot AI,[2025](https://arxiv.org/html/2604.02721#bib.bib20), Yang et al\.,[2024](https://arxiv.org/html/2604.02721#bib.bib35), DeepSeek\-AI,[2025](https://arxiv.org/html/2604.02721#bib.bib4)\]has driven substantial gains and has also spurred a growing literature on competitive\-programming benchmarks, evaluation, and datasets\[Quan et al\.,[2025](https://arxiv.org/html/2604.02721#bib.bib26), El\-Kishky et al\.,[2025](https://arxiv.org/html/2604.02721#bib.bib6), Yang et al\.,[2025](https://arxiv.org/html/2604.02721#bib.bib36), Liu et al\.,[2025](https://arxiv.org/html/2604.02721#bib.bib17), Wang et al\.,[2025b](https://arxiv.org/html/2604.02721#bib.bib33), Li et al\.,[2025a](https://arxiv.org/html/2604.02721#bib.bib14), Wang et al\.,[2025a](https://arxiv.org/html/2604.02721#bib.bib32), Ma et al\.,[2026](https://arxiv.org/html/2604.02721#bib.bib19), Dou et al\.,[2025](https://arxiv.org/html/2604.02721#bib.bib5), Zheng et al\.,[2026](https://arxiv.org/html/2604.02721#bib.bib40)\]\. AlphaCode achieved a Codeforces rating of approximately 1300, placing it in the top 54% of competitors\[Li et al\.,[2022](https://arxiv.org/html/2604.02721#bib.bib16)\]; AlphaCode2 improved this to the 85th percentile\[AlphaCode Team, Google DeepMind,[2023](https://arxiv.org/html/2604.02721#bib.bib1)\]; and OpenAI’s o3 ranks 175th globally\[OpenAI,[2025](https://arxiv.org/html/2604.02721#bib.bib24)\]\. Most recently, Gemini 3 Deep Think attained a ranking of 8th place, though this result was obtained on historical problems rather than under live contest conditions\.

In this work, we introduceGrandCode, a multi\-agent reinforcement learning system designed for competitive programming\. GrandCode orchestrates a variety of agents and modules, and is optimized through both post\-training and online adaptation with test\-time RL in an explicitly agentic loop: the hypothesis model proposes structural conjectures, the main solver takes the main responsibility of reasoning and solution generation, the summarization model maintains a compact memory of long context, and the test\-case generator produces edge test cases to challenge proposed solutions\. The goal of this design is to enable an agentic loop of reasoning, verification, and feedback, and continually refining its solutions\.

To address the severe off\-policy issue in multi\-turn agentic RL, we introduce Agentic GRPO, a variant of Group Relative Policy Optimization\[Shao et al\.,[2024](https://arxiv.org/html/2604.02721#bib.bib27)\]that combines immediate reward updates with delayed correction, enabling more effective credit assignment under long, multi\-stage rollouts and asynchronous training\.

GrandCode is the first AI system to consistently surpass the best human competitors in competitive programming under live contest conditions: in the three most recent Codeforces rounds under standard live contest conditions: Round 1087 on March 21, Round 1088 on March 28, and Round 1089 on March 29, 2026, GrandCode placed first in all three contests, outperforming every human participant, including multiple top\-ranked legendary grandmasters\.

GrandCode does not emerge in isolation, but is built on a broad ecosystem of prior AI components and systems, which we want to acknowledge\. It builds on Qwen 3\.5 as the foundation model\[Yang et al\.,[2024](https://arxiv.org/html/2604.02721#bib.bib35)\], chosen for its accessible SFT pipeline and multimodal capabilities\. We also employ models such as Kimi 2\.5\[Moonshot AI,[2025](https://arxiv.org/html/2604.02721#bib.bib20)\], GLM\[Zhipu AI and Tsinghua University KEG,[2024](https://arxiv.org/html/2604.02721#bib.bib41)\], and other closed\-source LLMs for data generation in several modules, and incorporates modules and implementation ideas from systems such as Slime\[THUDM,[2026](https://arxiv.org/html/2604.02721#bib.bib30)\]and Tinker\[Thinking Machines Lab,[2025](https://arxiv.org/html/2604.02721#bib.bib29)\]\.

The rest of this paper is organized as follows\.

- •Section[2](https://arxiv.org/html/2604.02721#S2)describes the Codeforces evaluation setting and GrandCode’s contest results\.
- •Section[3](https://arxiv.org/html/2604.02721#S3)presents the overall system design\.
- •Section[4](https://arxiv.org/html/2604.02721#S4)introduces Agentic GRPO and its delayed correction mechanism for multi\-stage agent rollouts\.
- •Section[5](https://arxiv.org/html/2604.02721#S5)describes our test\-case generation pipeline\.
- •Section[6](https://arxiv.org/html/2604.02721#S6)introduces the hypothesis\-generation stage\.
- •Section[7](https://arxiv.org/html/2604.02721#S7)describes continued training and supervised fine\-tuning\.
- •Section[8](https://arxiv.org/html/2604.02721#S8)presents multi\-component RL orchestration\.
- •Section[9](https://arxiv.org/html/2604.02721#S9)describes the supporting RL infrastructure\.
- •Section[10](https://arxiv.org/html/2604.02721#S10)discusses test\-time RL in live contests\.

## 2Codeforces Competition Results

### 2\.1Codeforces

Codeforces111[https://codeforces\.com/](https://codeforces.com/)is one of the most prominent platforms for competitive programming and hosts frequent public contests with large and highly skilled participant pools\. In a typical round, participants are given a sequence of problems with increasing difficulty and must solve them as quickly as possible under strict time and memory limits\. Many rounds are organized by division: Div\. 1 typically targets higher\-rated participants, Div\. 2 targets a broader pool of lower\-rated participants, and Div\. 1\+2 rounds combine both groups in a shared contest\. Each solution is submitted to an online judge that evaluates the code on hidden test cases and returns only limited feedback, such as whether the submission is wrong or exceeds the time limit\. A successful submission must therefore be bothcorrectandefficient, and earlier accepted submissions receive better scores\. Problem statements are often long, combine narrative description with precise constraints and input\-output specifications, and may also include figures, as illustrated in Figure[9](https://arxiv.org/html/2604.02721#A3.F9)\.

It is worth noting that Codeforces has policies against AI\-generated content, and accounts suspected of using AI face removal\. High\-ranking accounts in the contest are under even tighter scrutiny\. To get the final score for the full version, we wait until the human participants have nearly finished the task before submitting the full version\.

### 2\.2Participating Results

GrandCode participated in the three most recent Codeforces live competitions under the contestant IDsaveryjones1in Round 1087,yokekoin Round 1088, andVortex1in Round 1089\.

RoundDiv\.DateTime \(UTC\+3\)DurationID10872Mar\. 21, 202617:35–19:3502:00:00averyjones110881\+2Mar\. 28, 202617:45–20:1502:30:00yokeko10892Mar\. 29, 202617:35–19:5002:15:00Vortex1We report two scores:S​\(separate\)S\(\\mathrm\{separate\}\), which is obtained by summing the scores of tasks at the time they are completed, i\.e\., by submitting each solution as soon as it is ready\. Byseparate, we mean that the submissions are made independently, with submission and standings details shown in Figures[7](https://arxiv.org/html/2604.02721#A3.F7)and[8](https://arxiv.org/html/2604.02721#A3.F8); andS​\(joint\)S\(\\mathrm\{joint\}\), which is the score based on the full set of submissions in a single account, as shown in FigureLABEL:fig:cf\-standings\-overview, with submission and standings details shown in Figure[6](https://arxiv.org/html/2604.02721#A3.F6)\. In practice,S​\(joint\)S\(\\mathrm\{joint\}\)is strictly lower thanS​\(separate\)S\(\\mathrm\{separate\}\)because of waiting time\.

It is worth noting that this can also lead to multiple\-submission penalties that are not reflected\. We believe this effect is small because \(1\) all tasks are solved within at most four submission attempts, and \(2\) in the Codeforces scoring system, the penalty for multiple attempts is small compared with the reward for early accepted submissions\.

RoundS​\(separate\)S\(\\mathrm\{separate\}\)S​\(joint\)S\(\\mathrm\{joint\}\)Finish time10879269833400:51:111088165111500801:40:35108911596950600:56:43GrandCode achieved the best score in all three contests and was also the first to finish all tasks in each of them\. The correspondingS​\(separate\)S\(\\mathrm\{separate\}\)scores were 9269, 16511, and 11596 for Rounds 1087, 1088, and 1089, respectively, and the correspondingS​\(joint\)S\(\\mathrm\{joint\}\)scores were 8334, 15008, and 9506\. Details for submissions and standings forjointis shown in FigiureLABEL:fig:cf\-standings\-overview\.

## 3System Overview

The proposed sytesm combines three learned policies and the test\-case generation module:

1. 1\.Main solverπmain\\pi\_\{\\mathrm\{main\}\}corresponds to the core policy that generates reasoning traces and code\.
2. 2\.Hypothesis modelπhypothesis\\pi\_\{\\mathrm\{hypothesis\}\}proposes intermediate conjectures or structural properties, which will be verified them on small instances\. Accepted hypothesis will be injected into the prompt for Main solver\.
3. 3\.Summarization modelπsummary\\pi\_\{\\mathrm\{summary\}\}compresses very long reasoning traces so that hard problems remain tractable in later RL stages\.
4. 4\.Test\-case generationconstructs adversarial tests, solution\-attack tests, and large\-size stress cases to evaluate candidate programs before submission\.

The overall workflow has two phases:

1. 1\.Post\-training, which can further be divided into three substages: 1. \(a\)Continued pre\-trainingon broad competitive programming data to improve the model’s general problem\-solving ability\. We start from existing task datasets, use them as seeds for data expansion, generate additional data with Claude and Gemini, and continue training the Qwen model on the resulting corpus\. 2. \(b\)Supervised fine\-tuningon high\-quality \(question, thinking, solution\) triples\. Given \(question, solution\) pairs, we generate reasoning traces for data expansion and use the resulting triples for supervised fine\-tuning, together with auxiliary components such asπhypothesis\\pi\_\{\\mathrm\{hypothesis\}\}andπsummary\\pi\_\{\\mathrm\{summary\}\}\. 3. \(c\)Multi\-component reinforcement learningto jointly optimize the system, enabling the main solver and auxiliary components to collaborate more effectively under the final objective\.
2. 2\.Test\-time / live\-contest solving\.During this stage, the model solves the current problem instance using difficulty\-aware routing, direct generation for easy cases, and an onlinetest\-time RLloop with verification feedback for harder cases\.

Figure[2](https://arxiv.org/html/2604.02721#S3.F2)shows the full pipeline\.

![Refer to caption](https://arxiv.org/html/2604.02721v1/figs/pipeline-overview-edited.png)Figure 2:Overview of the full pipeline\. In post\-training, we continue training on noisy competitive\-programming data, perform supervised fine\-tuning on reference solutions, train auxiliary hypothesis generation policyπhypothesis\\pi\_\{\\mathrm\{hypothesis\}\}and summarization policyπsummary\\pi\_\{\\mathrm\{summary\}\}and jointly optimize the system with multi\-component RL\. At test/online\-contest time, the model uses direct generation for easy cases, and an online test\-time RL loop for harder cases\.#### Difficulty\-based routing

We fine\-tune a lightweight classifier to assign each task to one of five difficulty levels, where Level 1 denotes the easiest problems and Level 5 the hardest\.

## 4Agentic GRPO with Immediate Reward and Delayed Correction

In many agentic settings, especially code optimization, it often requires the agent to perform multiple rounds of self\-debugging and troubleshooting\. As a result, the full process from starting a rollout to receiving its final reward can be extremely slow\. This is not only because the generated sequence itself is long, but more importantly because the code must be evaluated multiple times, and each evaluation involves compilation and execution\. For many competitive programming tasks, a single evaluation can easily exceed one minute\.

This creates a severe off\-policy problem\. Asynchronous RL methods such as pipeline\-RLPiché et al\. \[[2025](https://arxiv.org/html/2604.02721#bib.bib25)\], where sampling and training proceed concurrently with in\-flight weight updates and a single sequence may be generated under multiple policy versions, is a necessary solution, but not enough\.

Orthogonal to asynchronous training, we propose*Agentic GRPO*with*Immediate Reward and Delayed Correction*, which is designed to handle multi\-stage rollouts in agentic settings under the asynchronous training framework\. Suppose we have a multi\-stage rollout of the form, the sequence for staget∈\[1,N\]t\\in\[1,N\]is denoted bysts\_\{t\}, with the rewardrtr\_\{t\}:

s1,r1,s2,r2,…,sN,rN\.s\_\{1\},r\_\{1\},s\_\{2\},r\_\{2\},\\ldots,s\_\{N\},r\_\{N\}\.In the standard GRPO, we update the whole trajectory with the final rewardrNr\_\{N\}and ignore the intermediate rewardsr1,r2,…,rN−1r\_\{1\},r\_\{2\},\\ldots,r\_\{N\-1\}\. The core idea behindAgentic GRPOis that to have the trainer update the policy as soon as possible once an intermediate rewardrtr\_\{t\}is available instead of waiting for the final rewardrNr\_\{N\}\. When we finish the whole sequence, we apply a delayed correction termrN−r1,rN−r2,…,rN−rN−1r\_\{N\}\-r\_\{1\},r\_\{N\}\-r\_\{2\},\\ldots,r\_\{N\}\-r\_\{N\-1\}to the trainer\. Therefore, for each subsequencests\_\{t\}with rewardrtr\_\{t\}, gradient updates will be divided into two stages,Immediate RewardandDelayed Correction\.

#### Immediate Reward

we first update the trainer using the immediate rewardrtr\_\{t\}\. For allsts\_\{t\}ofKKrollouts,

At\(i\)=rt\(i\)−μtσt,μt=1K​∑i=1Krt\(i\),σt=std​\(rt\(1\),…,rt\(K\)\)\.A\_\{t\}^\{\(i\)\}=\\frac\{r\_\{t\}^\{\(i\)\}\-\\mu\_\{t\}\}\{\\sigma\_\{t\}\},\\qquad\\mu\_\{t\}=\\frac\{1\}\{K\}\\sum\_\{i=1\}^\{K\}r\_\{t\}^\{\(i\)\},\\qquad\\sigma\_\{t\}=\\mathrm\{std\}\\\!\\left\(r\_\{t\}^\{\(1\)\},\\ldots,r\_\{t\}^\{\(K\)\}\\right\)\.\(1\)The corresponding GRPO loss on tokens insts\_\{t\}is

ℒt=−1K​∑i=1K∑u∈st\(i\)min⁡\(ρu\(i\)​At\(i\),clip​\(ρu\(i\),1−ϵ,1\+ϵ\)​At\(i\)\),\\mathcal\{L\}\_\{t\}=\-\\frac\{1\}\{K\}\\sum\_\{i=1\}^\{K\}\\sum\_\{u\\in s\_\{t\}^\{\(i\)\}\}\\min\\\!\\left\(\\rho\_\{u\}^\{\(i\)\}A\_\{t\}^\{\(i\)\},\\mathrm\{clip\}\\\!\\left\(\\rho\_\{u\}^\{\(i\)\},1\-\\epsilon,1\+\\epsilon\\right\)A\_\{t\}^\{\(i\)\}\\right\),\(2\)where

ρu\(i\)=πθ​\(au∣su\)πθu,beh\(i\)​\(au∣su\)\.\\rho\_\{u\}^\{\(i\)\}=\\frac\{\\pi\_\{\\theta\}\(a\_\{u\}\\mid s\_\{u\}\)\}\{\\pi\_\{\\theta\_\{u,\\mathrm\{beh\}\}^\{\(i\)\}\}\(a\_\{u\}\\mid s\_\{u\}\)\}\.\(3\)Hereθu,beh\(i\)\\theta\_\{u,\\mathrm\{beh\}\}^\{\(i\)\}denotes the behavior policy version that generated tokenaua\_\{u\}in rolloutii, which may vary across tokens under asynchronous pipeline training\.

#### Delayed Correction

When the full rollouts1,s2,…,sNs\_\{1\},s\_\{2\},\.\.\.,s\_\{N\}is completed and the final rewardrNr\_\{N\}becomes available, we use it to correct each earlier stagests\_\{t\}\. We first define the reward correction as follows:

δt\(i\)=rN\(i\)−rt\(i\)\\delta\_\{t\}^\{\(i\)\}=r\_\{N\}^\{\(i\)\}\-r\_\{t\}^\{\(i\)\}\(4\)and normalize it as

At\(i\)=δt\(i\)−μtσt,μt=1K​∑i=1Kδt\(i\),σt=std​\(δt\(1\),…,δt\(K\)\)\.A\_\{t\}^\{\(i\)\}=\\frac\{\\delta\_\{t\}^\{\(i\)\}\-\\mu\_\{t\}\}\{\\sigma\_\{t\}\},\\qquad\\mu\_\{t\}=\\frac\{1\}\{K\}\\sum\_\{i=1\}^\{K\}\\delta\_\{t\}^\{\(i\)\},\\qquad\\sigma\_\{t\}=\\mathrm\{std\}\\\!\\left\(\\delta\_\{t\}^\{\(1\)\},\\ldots,\\delta\_\{t\}^\{\(K\)\}\\right\)\.\(5\)
The delayed correction applied to the older stagests\_\{t\}is

ℒtcorr=−1K​∑i=1K∑u∈st\(i\)min⁡\(ρ^u\(i\)​At\(i\),clip​\(ρ^u\(i\),1−ϵ2,1\+ϵ2\)​At\(i\)\),\\mathcal\{L\}\_\{t\}^\{\\mathrm\{corr\}\}=\-\\frac\{1\}\{K\}\\sum\_\{i=1\}^\{K\}\\sum\_\{u\\in s\_\{t\}^\{\(i\)\}\}\\min\\\!\\left\(\\hat\{\\rho\}\_\{u\}^\{\(i\)\}A\_\{t\}^\{\(i\)\},\\mathrm\{clip\}\\\!\\left\(\\hat\{\\rho\}\_\{u\}^\{\(i\)\},1\-\\epsilon\_\{2\},1\+\\epsilon\_\{2\}\\right\)A\_\{t\}^\{\(i\)\}\\right\),\(6\)where

ρ^u\(i\)=πθ′​\(au∣su\)πθu,beh\(i\)​\(au∣su\),ϵ2≤ϵ\.\\hat\{\\rho\}\_\{u\}^\{\(i\)\}=\\frac\{\\pi\_\{\\theta^\{\\prime\}\}\(a\_\{u\}\\mid s\_\{u\}\)\}\{\\pi\_\{\\theta\_\{u,\\mathrm\{beh\}\}^\{\(i\)\}\}\(a\_\{u\}\\mid s\_\{u\}\)\},\\qquad\\epsilon\_\{2\}\\leq\\epsilon\.\(7\)Hereθ′\\theta^\{\\prime\}denotes the current policy after subsequent updates, whileθu,beh\(i\)\\theta\_\{u,\\mathrm\{beh\}\}^\{\(i\)\}is the behavior\-policy version that originally generated tokenaua\_\{u\}\.

The proposed Agentic GRPO can be used together with asynchronous training methods: the former enables more timely credit assignment in multi\-turn agent rollouts, while the latter overlaps sampling and training for higher throughput\. A more details theoretical analysis of Agentic GRPO is shown in Appendix[C](https://arxiv.org/html/2604.02721#A3)\.

## 5Test Case Generation

In programming contests, the real judge test cases are hidden, so we must construct its own test cases and pass them before the submission\. Therefore, we need to generate edge cases that can expose logical bugs, boundary failures, and incorrect complexity assumptions before submission\.

Test case generation faces two main challenges\. First, it is difficult to generate genuinelyadversarial test casesthat expose subtle logical errors rather than merely checking superficial correctness\. Second,large\-size test casesare hard to use for verification, because in many settings the only trusted solver available to us is a brute\-force implementation, and that solver times out on large inputs, which makes we don’t have gold outputs to compare with for large\-size inputs\.

### 5\.1Adversarial Test Case Generation

We adopt two strategies for adversarial test generation:difference\-driven test generationandsolution attack\.

#### Difference\-driven Test Case Generation

If a test case can expose a difference between two solutions, it is very likely an adversarial case\.

Given a list of candidate solutions sampled during training, we iteratively generate candidate test cases by prompting Claude, GPT, DeepSeek V3, and Kimi 2\.5 by to produce inputs that are likely to reveal corner cases\. No candidate solution is provided to the LLMs at this stage\. We further employ a generator\-validator framework inspired by CodeContests\+\[Wang et al\.,[2025b](https://arxiv.org/html/2604.02721#bib.bib33)\], in which an additional LLM validator is used to filter or refine the generated tests\. We then run the generated test cases on all sampled solutions and check whether any test induces different outputs between them\. Test cases that trigger such differences are preserved\. Whenever such a case is found, we feed it back to the LLM and ask it to describe what edge condition the input may be triggering, and then generate additional tests of a similar kind\. In this way, the test pool is gradually enriched with more informative cases, and by the end of optimization for a problem we are able to maintain a strong problem\-specific test suite\. It is worth noting that this idea is akin to the spirit to the agentic verification approachMa et al\. \[[2026](https://arxiv.org/html/2604.02721#bib.bib19)\]\.

#### Solution Attack

In the training set, where a gold solution is available, we further generate adversarial tests by directly comparing the gold solution with each candidate solution\. We feed both solutions to an LLM and ask it to analyze their differences, identify potential bugs in the candidate solution, and propose edge cases that are likely to expose those bugs\. We carry out this process in a multi\-turn conversation mode, allowing the model to iteratively refine its hypotheses and search for stronger adversarial tests\. Each generated test case is then executed on both the gold solution and the candidate solution to verify whether it indeed induces a behavioral difference\. Test cases that successfully separate the two solutions are preserved, since they provide direct evidence of a real bug in the candidate solution\.

Using the adversarial test cases generated above, we further fine\-tune a Qwen\-3\.5\-27B model to generate such verified adversarial examples given the problem statement and the candidate solution\.

### 5\.2Test\-time Strategies

When we handle a specific contest task, we use the similar online strategy: We prompt the fine\-tuned model to generate multiple adversarial test cases conditioned on each generated solution, and after every few candidate solutions, we regenerate part of the test set and refresh the evaluation pool\. Test examples that trigger a difference are kept, since they are highly informative indicators of edge cases\. A solution is submitted only if it passes all of these test cases\.

### 5\.3Results on Real Codeforces Problems

We evaluate test case genearation on 50 real Codeforces problems by submitting solutions to the real Codeforces website and using the real system as the final criterion\. We check whether a solution that passes our generated test suite also passes the hidden official tests\. Table[1](https://arxiv.org/html/2604.02721#S5.T1)summarizes the results\. The pass count increases from 42 to 48 after applying difference\-driven test case generation and solution attack\. For the remaining two failures, we further incorporate submission feedback and continue generating additional test cases online, which raises the pass count to all of 50 tests\.

StagePassedTotalBase test suite4250After difference\-driven generation \+ solution attack4850After submission feedback \+ continued online generation5050Table 1:Results on 50 real Codeforces problems using the Codeforces judge as the final criterion\.
### 5\.4Large\-size Test Cases

In real\-time contest, feedback from the submission system can also be harnessed to generate test cases with larger input sizes\. A failure due to time limit exceeded often suggests that the generated code snippet may be logically correct but computationally inefficient\. If such the code snippet is faster than the brute\-force baseline, we can use it as a solver on test cases with larger input sizes, allowing evaluation on inputs that are too large for brute force\.

![Refer to caption](https://arxiv.org/html/2604.02721v1/figs/hypo_gen.png)Figure 3:Hypothesis generation and small\-scale verification\. The agent first proposes a compact characterization \(kmax=maxv⁡\(last​\(v\)−first​\(v\)\)k\_\{\\max\}=\\max\_\{v\}\(\\mathrm\{last\}\(v\)\-\\mathrm\{first\}\(v\)\)\), then generates small random instances, computes the exact answer via a brute\-force solver that enumerates all tuples\(i,j,k\)∈S​\(b\)\(i,j,k\)\\in S\(b\), and compares against the hypothesized value\. A mismatch triggers hypothesis revision and only validated hypotheses are promoted to solution synthesis\.

## 6Prelude: Hypothesis Generation

### 6\.1Overview

The first stage of the agent workflow ishypothesis generationandsmall\-scale verification\. Before attempting full solution synthesis, we need to propose intermediate claims, structural properties, or compact mathematical characterizations of the problem, and then checks whether they are valid on small instances\. For example, the agent may verify that whether the problem is a dynamic\-programming problem in nature, or confirm that the input graph satisfies a structural property such as being undirected\. These checks can be easily performed on small\-scale inputs using the brute\-force algorithm\.

This stage can also invoke symbolic tools\. When a problem or a broken\-down subproblem can can be fully translated to a symbolic form, we will query an external engine such as Wolfram Alpha222[https://www\.wolframalpha\.com/](https://www.wolframalpha.com/)to simplify or solve the resulting expression\. This is especially useful when the main difficulty lies in discovering the right formula or invariant rather than in implementation details\.

As a concrete example, consider the Codeforces problem “Binary Not Search and Queries\.” We may first hypothesize thatkmax=maxv⁡\(last​\(v\)−first​\(v\)\)k\_\{\\max\}=\\max\_\{v\}\(\\mathrm\{last\}\(v\)\-\\mathrm\{first\}\(v\)\)\. Next we ask the model to generate many small inputs, computes the exact answer with a brute\-force solver, and checks whether the conjectured formula matches the true value on those instances\. When a mismatch is found, the counterexample is fed back to the model together with the failing hypothesis, and the model is asked to propose a revised conjecture; this verify\-and\-revise loop repeats until the hypothesis is consistent with all small\-scale tests\. This process is illustrated in Figure[3](https://arxiv.org/html/2604.02721#S5.F3)\.

Hypotheses that survive this iterative validation are injected into the prompt of the main solving thread, providing verified structural insights that guide subsequent solution synthesis\. The tools used in this stage include shell execution, Wolfram Alpha, and web search\. For search in particular, we apply a filter to avoid directly retrieving historical answers, editorials, or hints for the target problem\.

### 6\.2Training Hypothesis Generation Model

We use a lightweight model for this component rather than allocating a large model to every instance\. We denote this model byπhypothesis\\pi\_\{\\mathrm\{hypothesis\}\}and use Qwen\-3\.5\-27B as the base model forπhypothesis\\pi\_\{\\mathrm\{hypothesis\}\}\.

#### SFT

We first trainπhypothesis\\pi\_\{\\mathrm\{hypothesis\}\}with supervised fine\-tuning\. To construct SFT data, we use Claude to generate multiple candidate hypotheses given only the problem statement, and retain those that are verified to be correct\. For problems that come with editorials or reference solutions, we additionally provide these materials to Claude and ask it to produce hypotheses implied by the official reasoning, again retaining only the correct ones\. The resulting verified hypotheses are then used as supervision for SFT\.

#### RL

After SFT, we further optimizeπhypothesis\\pi\_\{\\mathrm\{hypothesis\}\}with reinforcement learning using GRPO\. At the current stage, the reward for a generated hypothesishhis the proportion of verification tests it passes:

rverify​\(h\)=1\|T\|​∑t∈T𝟏​\[h​is correct on​t\]\.r\_\{\\mathrm\{verify\}\}\(h\)=\\frac\{1\}\{\|T\|\}\\sum\_\{t\\in T\}\\mathbf\{1\}\[h\\text\{ is correct on \}t\]\.\(8\)At the current stage,πhypothesis\\pi\_\{\\mathrm\{hypothesis\}\}is trained independently for simplicity\. However, this is inherently imperfect, since generating a correct hypothesis does not necessarily imply that it is helpful to generate the correct solution\. In the full system,πhypothesis\\pi\_\{\\mathrm\{hypothesis\}\}will later be jointly trained with the overall solver in the RL training stage for the latter\.

### 6\.3Evaluation

We randomly select 200 problems for evaluation\. Since each problem comes with a test\-based checker, evaluation can be performed directly based on the provided tests\. Table[2](https://arxiv.org/html/2604.02721#S6.T2)reports pass@1 and pass@5 for different models, where pass@1 denotes the success rate of the first generated hypothesis and pass@5 denotes the success rate at which at least one of five generated hypotheses passes the tests\. The results show consistent improvements from the base Qwen\-3\.5\-27B model to \+SFT and further to \+SFT\+RL on both metrics\.

Model for Hypothesis Genpass@1pass@5Qwen\-3\.5\-27B34%44%\+SFT45%52%\+SFT\+RL52%57%Table 2:Pass@1 and pass@5 on a 200\-problem evaluation set for hypothesis generation\. Supervised fine\-tuning substantially improves over the base Qwen\-3\.5\-27B model, and additional RL training brings further gains on both metrics\.
### 6\.4Clue Finding Using OEIS

We also employ a side route that does not involve any additional model training\. We first compute outputs for a few small values ofNN, and query the On\-Line Encyclopedia of Integer Sequences \(OEIS,[https://oeis\.org/](https://oeis.org/)\) with the resulting sequence to search for useful clues\. If the lookup is successful, the returned pattern, formula, or related structural hint is included in the prompt for subsequent solving\.

## 7Post Training with Continue Training and SFT

#### Benchmarking Existing Models

We select 100 questions, equally distributed across the five difficulty categories, and evaluate proprietary models on this benchmark, including Gemini 3\.1 pro, Claude Opus 4\.6 and GPT 5\.4\. Table[3](https://arxiv.org/html/2604.02721#S7.T3)reports three complementary metrics for each model: the overall accept rate, the number of hardest Level 5 problems solved, and a difficulty\-weighted score that assigns weights1,2,3,4,51,2,3,4,5to Levels 1–5, respectively\. Overall, current frontier models achieve an overall accept rate of roughly 70%–75% and solve about 35%–40% of Level 5 problems\.

ModelAccept RateLevel 5 SolvedWeighted Score \(0\-100\)Gemini 3\.1 Pro75%7/2064\.3Claude Opus 4\.673%8/2063\.7GPT\-5\.472%7/2063\.0Kimi K2\.565%5/2053\.3DeepSeek V3\.265%4/2052\.7Qwen 3\.5\-397B64%4/2052\.3Table 3:Accept rates, Level 5 correct answers \(out of 20\), and scaled weighted scores on 100 benchmark questions\. Questions are equally distributed across five difficulty categories\. Weighted scores apply a 1\-5 multiplier based on difficulty, normalized to a 0\-100 scale\.
### 7\.1Continue Training on Noisy Data

For continued pretraining, we first collect a broad seed set of competitive\-programming problems from TACO\[Li et al\.,[2023](https://arxiv.org/html/2604.02721#bib.bib13)\], LeetCode\[LeetCode,[2026](https://arxiv.org/html/2604.02721#bib.bib12)\], USACO\[USACO,[2026](https://arxiv.org/html/2604.02721#bib.bib31)\], CodeContests\[Li et al\.,[2022](https://arxiv.org/html/2604.02721#bib.bib16)\], IOI\[IOI,[2026](https://arxiv.org/html/2604.02721#bib.bib9)\], and additional problems crawled from various online sources\. We then use Gemini 3\.1 Pro to expand this seed set into a much larger and more diverse training corpus\. Next, we directly prompt Claude 4\.6 and Gemini 3\.1 to generate detailed thinking processes for these problems, and use the resulting question\-thinking\-solution tuples to train Qwen 3\.5\-397B\. To make the model familiar with settings where a hypothesis is provided, we randomly convert 20% of the continued\-pretraining examples into hypothesis\-conditioned cases, in which a hypothesis generated byπhypothesis\\pi\_\{\\mathrm\{hypothesis\}\}is incorporated in the prompt before we generate the detailed thinking process\. At this stage, the data can be noisy because it is partly generated, and some synthesized reasoning traces or answers may be incorrect\. However, the goal of continued pretraining is primarily to improve the model’s general competitive\-programming ability rather than to provide precise supervision\. We leave more fine\-grained filtering and high\-quality supervision to the later SFT stage\. It is worth noting that since the model is trained on the data is generated by Claude 4\.6 and Gemini 3\.1, the upper bound for the ckpt by the end of continue training is around 73% accepted rate, as shown in Table[3](https://arxiv.org/html/2604.02721#S7.T3)\.

### 7\.2SFT using Reference Solutions

For SFT, we focus only on non\-synthetic problems with reference solutions, some of which also come with hints\. Our goal is to generate a high\-quality thinking processccthat can plausibly lead to the provided reference solution\. With such tuples, we can directly perform SFT by training the modelGmainG\_\{\\mathrm\{main\}\}to first predictccgivenxx, and then predictyygiven\(x,c\)\(x,c\), denoted byp​\(y,c∣x\)p\(y,c\\mid x\)\.

#### Solution Matching

For each questionxx, we prompt Gemini 3\.1 Pro, Claude Opus 4\.6, GPT\-5\.4, GLM 4\.5, Kimi K2\.5, and DeepSeek V3\.2 multiple times to generate both a reasoning traceccand a solutionyy\. We then compare the generated solution against the gold solution\. If the generated solution is equivalent to the gold solution, we keep the associated reasoning trace\. Even when the implementation is not textually identical, we still retain it if it is comparable to or better than the reference solution in terms of efficiency, since many problems admit multiple valid solutions\.

It is worth noting that this strategy is effective for relatively easy tasks, where we can often recover a solution close to the gold one\. For harder tasks, however, the generated solution frequently fails to match the gold solution, making this simple filtering procedure insufficient\.

#### Finding Optimal Thinking Traceccfor Hard Problems

For each hard question\-solution pair\(x,y\)\(x,y\), we first prompt Claude 4\.6 or Gemini 3\.1 to generateNNcandidate reasoning contextsC=\[c1,…,cN\]C=\[c\_\{1\},\\ldots,c\_\{N\}\]given\(x,y\)\(x,y\)\. We denote the full forward model byπmain\\pi\_\{\\mathrm\{main\}\}, and its original checkpoint byπmain\(0\)\\pi\_\{\\mathrm\{main\}\}^\{\(0\)\}\. We then selectcic\_\{i\}based on the following score:

s​\(ci\)=α⋅log⁡pπmain​\(ci,y∣x\)\|ci\|\+\|y\|\+β⋅log⁡pπmain\(0\)​\(x∣ci\)\|x\|,s\(c\_\{i\}\)=\\alpha\\cdot\\frac\{\\log p\_\{\\pi\_\{\\mathrm\{main\}\}\}\(c\_\{i\},y\\mid x\)\}\{\|c\_\{i\}\|\+\|y\|\}\+\\beta\\cdot\\frac\{\\log p\_\{\\pi\_\{\\mathrm\{main\}\}^\{\(0\)\}\}\(x\\mid c\_\{i\}\)\}\{\|x\|\},\(9\)wherepπmain​\(ci,y∣x\)p\_\{\\pi\_\{\\mathrm\{main\}\}\}\(c\_\{i\},y\\mid x\)is computed by the post\-trained Qwen 3\.5\-397B,pπmain\(0\)​\(x∣ci\)p\_\{\\pi\_\{\\mathrm\{main\}\}^\{\(0\)\}\}\(x\\mid c\_\{i\}\)is computed by the original Qwen 3\.5\-397B, and both terms are length\-normalized\. Intuitively, the first term favors reasoning contexts that make the target reasoning and solution likely under the post\-trained model, while the second term favors contexts that remain predictive of the original question\. The second term is essential for distinguishing genuinely useful reasoning traces from degenerate ones that merely copy or reveal the answer\. At the end of this procedure, the tuples are combined into the the SFT training data\.

### 7\.3Training Summarization Model

For hard questions, the thinking trace can easily exceed 100K tokens, which makes both inference and the later RL stage extremely computationally expensive\. Additionally, extremely long traces are also harder to optimize with RL\. We therefore first train a separate summarization modelπsummary\\pi\_\{\\mathrm\{summary\}\}\.

Given a long reasoning tracecc, we partition it into chunksc\(1\),c\(2\),…,c\(n\)c^\{\(1\)\},c^\{\(2\)\},\\ldots,c^\{\(n\)\}, so that the full example is represented as\(x,c\(1\),c\(2\),…,c\(n\),y\)\(x,c^\{\(1\)\},c^\{\(2\)\},\\ldots,c^\{\(n\)\},y\)\. The summarization model maintains a progressive summary states1,s2,…,sns\_\{1\},s\_\{2\},\\ldots,s\_\{n\}, whereπsummary​\(c\(1\)\)→s1\\pi\_\{\\mathrm\{summary\}\}\(c^\{\(1\)\}\)\\rightarrow s\_\{1\},πsummary​\(s1,c\(2\)\)→s2\\pi\_\{\\mathrm\{summary\}\}\(s\_\{1\},c^\{\(2\)\}\)\\rightarrow s\_\{2\}, and in generalπsummary\(\(st−1,c\(t\)\)→st\\pi\_\{\\mathrm\{summary\}\}\(\(s\_\{t\-1\},c^\{\(t\)\}\)\\rightarrow s\_\{t\}\. Intuitively,sts\_\{t\}is a compact summary seen up to chunktt\.

There has been existing work that integrates summary generation into training mostly in an end\-to\-end fashion, including MemAgent\[Yu et al\.,[2025](https://arxiv.org/html/2604.02721#bib.bib37)\], Agentic Memory\[Yu et al\.,[2026](https://arxiv.org/html/2604.02721#bib.bib38)\], and Composer 2\[Chan et al\.,[2026](https://arxiv.org/html/2604.02721#bib.bib3)\]\. In these approaches, summarization usually shares the parameters with the main model, and is optimized jointly with the main model in an end\-to\-end fashion based on the final answer\.

While this end\-to\-end formulation is natural, its reward is relatively sparse, since supervision is dominated by the terminal outcome of the full trajectory\. By contrast, we first take advantage of the existing SFT data to learn as strong a summarization policy as possible, rather than directly entering the RL stage and relying only on the final reward as the training signal\. We train the summarizer progressively in multiple stages\. This gives denser intermediate supervision in the early stage of training\.

#### Stage 1

We first train each local summarization step with RL\. Starting from Qwen\-3\.5\-27B, the policy maps the first chunkc\(1\)c^\{\(1\)\}to a summarys1s\_\{1\}\. Concretely, for a sampled summarys1s\_\{1\}, we define the score as:

score​\(s1\)=α​log⁡p​\(c\(2\),…,c\(n\),y∣s1,x\)\|c\(2\),…,c\(n\)\|\+\|y\|\+β​log⁡p​\(c\(1\)∣s1\)\|c\(1\)\|\\mathrm\{score\}\(s\_\{1\}\)=\\alpha\\,\\frac\{\\log p\\\!\\left\(c^\{\(2\)\},\\ldots,c^\{\(n\)\},y\\mid s\_\{1\},x\\right\)\}\{\\left\|c^\{\(2\)\},\\ldots,c^\{\(n\)\}\\right\|\+\|y\|\}\+\\beta\\,\\frac\{\\log p\\\!\\left\(c^\{\(1\)\}\\mid s\_\{1\}\\right\)\}\{\\left\|c^\{\(1\)\}\\right\|\}\(10\)
The first term encouragess1s\_\{1\}to preserve information needed for the later chunks and the final answer, while the second term penalizes reconstruction error by encouragings1s\_\{1\}to retain enough information to reconstruct the original chunk\.

We optimize this policy with GRPO\. Given a group of rollout rewards\{ri\}i=1G\\\{r\_\{i\}\\\}\_\{i=1\}^\{G\}, we normalize them within the group asAi=\(ri−mean​\(r\)\)/std​\(r\)A\_\{i\}=\(r\_\{i\}\-\\mathrm\{mean\}\(r\)\)/\\mathrm\{std\}\(r\)and update the policy using these relative advantages\. We use analogous objectives for later transitions\(st−1,c\(t\)\)→st\(s\_\{t\-1\},c^\{\(t\)\}\)\\rightarrow s\_\{t\}\. This stage teaches each summary state to preserve the information necessary for continuing the long reasoning process\.

#### Stage 2

We then train the full progressive chain end to end\. We sample the entire summarization trajectoryc\(1\)→s1c^\{\(1\)\}\\rightarrow s\_\{1\},\(s1,c\(2\)\)→s2\(s\_\{1\},c^\{\(2\)\}\)\\rightarrow s\_\{2\},…\\ldots,\(sn−1,c\(n\)\)→sn\(s\_\{n\-1\},c^\{\(n\)\}\)\\rightarrow s\_\{n\}, and use the final answer likelihood, e\.g\. the normalizedlog⁡p​\(y∣sn\)\\log p\(y\\mid s\_\{n\}\), as the terminal reward for GRPO\.

#### Stage 3

Finally,πsummary\\pi\_\{\\mathrm\{summary\}\}is integrated into the full RL training ofπmain\\pi\_\{\\mathrm\{main\}\}, so that summarization and downstream solving can be optimized jointly in the overall pipeline, as will be described in detail in Section[8](https://arxiv.org/html/2604.02721#S8)\.

In addition, data with summaries is mixed into the SFT training data, so thatπsummary\\pi\_\{\\mathrm\{summary\}\}becomes familiar with both settings where summaries are present and settings where they are not\.

### 7\.4Evaluation

We evaluate the effect of continued training, SFT, and summary\-augmented training on the same 100\-problem benchmark described above\. Table[4](https://arxiv.org/html/2604.02721#S7.T4)reports the results\. Continued training substantially improves over the base model, raising the overall accept rate from 64% to 71% and the weighted score from 52\.2 to 61\.0\. SFT yields a further improvement, reaching 73% accept rate, 7/20 solved Level 5 problems, and a weighted score of 62\.5\. We observe a minor performance degradation when the summarization module is incorporated\.

ModelAccept RateLevel 5 SolvedWeighted Score \(0\-100\)Qwen 3\.5\-397B64%4/2052\.2\+continue training71%6/2061\.0\+continue training \+ SFT73%7/2062\.5\+continue training \+ SFT \+ summary72%7/2061\.7Table 4:Ablation of continued training, SFT, and summary\-augmented training on the 100\-problem benchmark\. Continued training delivers a large gain over the base model, and SFT provides an additional improvement\.
### 7\.5Multimodal Problem Solving

Many competitive\-programming problems come with images or diagrams, as illustrated in Figure[9](https://arxiv.org/html/2604.02721#A3.F9)\. Since Qwen is a multimodal model, we follow its native multimodal input protocol when such visual content is present\. We also experimented with converting images into text descriptions and feeding only the extracted text into the model but find that this text\-only conversion significantly underperforms direct multimodal processing\. A likely reason is that many images are still visually convoluted and difficult to describe faithfully in text, and the conversion often loses precisely the spatial or structural information necessary for reasoning, as illustrated by the examples in Figure[4](https://arxiv.org/html/2604.02721#S7.F4)\.

![Refer to caption](https://arxiv.org/html/2604.02721v1/figs/illu1_converted.png)
![Refer to caption](https://arxiv.org/html/2604.02721v1/figs/illu2_converted.png)

Figure 4:Examples of contest figures whose visual structure is difficult to capture with text\-only descriptions\.

## 8Multi\-Component RL Orchestration

The final stage involves multiple components for RL training, includingπmain\\pi\_\{\\mathrm\{main\}\},πhypothesis\\pi\_\{\\mathrm\{hypothesis\}\}, andπsummary\\pi\_\{\\mathrm\{summary\}\}\. We choose multi\-component RL for three main reasons: \(1\)Smaller auxiliary models:πhypothesis\\pi\_\{\\mathrm\{hypothesis\}\}andπsummary\\pi\_\{\\mathrm\{summary\}\}use smaller models, which saves substantial compute resources; \(2\)Stronger initialization:πhypothesis\\pi\_\{\\mathrm\{hypothesis\}\}andπsummary\\pi\_\{\\mathrm\{summary\}\}are separately pretrained in earlier stages and are already reasonably strong before the final joint RL stage, so they require only moderate joint tuning together withπmain\\pi\_\{\\mathrm\{main\}\}; \(3\)Better disentanglement:separate training makes it easier to isolate the influence of different modules: if one uses only a single final solution reward forπsummary\\pi\_\{\\mathrm\{summary\}\}andπmain\\pi\_\{\\mathrm\{main\}\}and the result is poor, it is unclear whether the failure comes from a bad summary or a bad solver\. This modular design therefore makes the final RL stage substantially more compute\-efficient and easier to optimize\.

### 8\.1Reward forπmain\\pi\_\{\\mathrm\{main\}\}

Reward evaluation of a generated code snippet consists of three stages:

1. 1\.Executability\.If a generated code snippet cannot be compiled or executed, it receives score0\.
2. 2\.Correctness\.Correctness is measured by comparing the code snippet output with a reference output\. When a gold solution is available, as in training\-time evaluation, we use the gold solution to produce the reference output\. At test time, when no gold solution is available, we compare against the output of a brute\-force solver on small inputs\. If a code snippet fails these correctness checks, it receives score0\.
3. 3\.Efficiency\.For a code snippet that pass correctness checking, we compare runtime against a brute\-force baseline on the generated tests, whose scale doesn’t has to be small\. For each test case, the reward is defined as the speedup over the brute\-force algorithm; if the generated code times out, we assign a score of0\.10\.1for that test case\. The final score is the average over all test cases\.

A detailed formalization in math in shown in Appendix[B](https://arxiv.org/html/2604.02721#A2)\.

#### Length Penalty based on Difficulty

More difficult questions typically require longer chains of reasoning, so the thinking\-length penalty should depend on the problem difficulty\. Recall that we fine\-tune a lightweight classifier that assigns each task a difficulty leveld∈\{1,2,3,4,5\}d\\in\\\{1,2,3,4,5\\\}, where largerddindicates a harder problem\. We therefore allocate a larger thinking\-token budget to harder tasks\. Letlldenote the thinking length,BBthe base budget for Level 1 problems, andα\\alphathe budget growth factor per difficulty level\. The difficulty\-dependent budget isB⋅α\(d−1\)B\\cdot\\alpha^\{\(d\-1\)\}, and the penalty is zero when the thinking length stays within this budget and increases only when it is exceeded:

P​e​n​a​l​t​y​\(l,d\)=max⁡\(0,l−B⋅α\(d−1\)B⋅α\(d−1\)\)\.Penalty\(l,d\)=\\max\\\!\\left\(0,\\;\\frac\{l\-B\\cdot\\alpha^\{\(d\-1\)\}\}\{B\\cdot\\alpha^\{\(d\-1\)\}\}\\right\)\.\(11\)In this way, easier problems are encouraged to use short, efficient reasoning traces, while harder problems are allowed more extensive thinking before incurring a penalty\.

### 8\.2Orchestrating ofπmain\\pi\_\{\\mathrm\{main\}\}andπhypothesis\\pi\_\{\\mathrm\{hypothesis\}\}

We first sample multiple candidate hypotheses fromπhypothesis\\pi\_\{\\mathrm\{hypothesis\}\}\. Only hypotheses that pass all verification tests are allowed to continue to the next stage\. The reward for the hypothesis\-generation stage is

r1​\(h\)=rverify​\(h\)=1\|T\|​∑t∈T𝟏​\[h​is correct on​t\]\.r\_\{1\}\(h\)=r\_\{\\mathrm\{verify\}\}\(h\)=\\frac\{1\}\{\|T\|\}\\sum\_\{t\\in T\}\\mathbf\{1\}\[h\\text\{ is correct on \}t\]\.\(12\)
For each passed hypothesishh, we then invokeπmain\\pi\_\{\\mathrm\{main\}\}to generate reasoning traces and candidate solutions conditioned on\(x,h\)\(x,h\)\. In parallel, we also generate rollouts fromπmain\\pi\_\{\\mathrm\{main\}\}without any hypothesis, which we denote by the empty condition∅\\varnothing\. LetS​\(x,h\)S\(x,h\)denote the average score of solutions generated with hypothesishhincorporated, and letS​\(x,∅\)S\(x,\\varnothing\)denote the average score of solutions generated without any hypothesis\.

We define the total reward forπhypothesis\\pi\_\{\\mathrm\{hypothesis\}\}by

r​\(h\)=\{α​r1​\(h\)\+β​\(S​\(x,h\)−S​\(x,∅\)\),if​h​passes all tests,α​r1​\(h\),otherwise\.r\(h\)=\\begin\{cases\}\\alpha r\_\{1\}\(h\)\+\\beta\\bigl\(S\(x,h\)\-S\(x,\\varnothing\)\\bigr\),&\\text\{if \}h\\text\{ passes all tests\},\\\\ \\alpha r\_\{1\}\(h\),&\\text\{otherwise\.\}\\end\{cases\}\(13\)This design encouragesπhypothesis\\pi\_\{\\mathrm\{hypothesis\}\}not only to generate locally valid hypotheses, but also to produce hypotheses that measurably improve downstream solution quality when used byπmain\\pi\_\{\\mathrm\{main\}\}\. Importantly,πhypothesis\\pi\_\{\\mathrm\{hypothesis\}\}is allowed to generate hypotheses over multiple rounds with self\-correction\. This iterative loop lets the hypothesis generator recover from initial mistakes and converge toward hypotheses that are both locally correct and globally useful\.

### 8\.3Orchestrating ofπsummary\\pi\_\{\\mathrm\{summary\}\}andπhypothesis\\pi\_\{\\mathrm\{hypothesis\}\}

πsummary\\pi\_\{\\mathrm\{summary\}\}is triggered only for long reasoning sequences\. During training, we gradually increase its triggering frequency, together with the curriculum that shifts toward harder problems over time\. As a result, early training focuses primarily onπhypothesis\\pi\_\{\\mathrm\{hypothesis\}\}andπmain\\pi\_\{\\mathrm\{main\}\}, while later training increasingly exposes the system to summary\-dependent rollouts\. Whenπsummary\\pi\_\{\\mathrm\{summary\}\}is triggered, we use the same final reward as forπmain\\pi\_\{\\mathrm\{main\}\}\. Concretely, if the summary\-conditioned rollout ultimately produces code snippetPP, then the reward assigned toπsummary\\pi\_\{\\mathrm\{summary\}\}is the final rollout scorer​\(P\)r\(P\)defined for the main solver\.

At the systems level, we place the large MoE solver policyπmain\\pi\_\{\\mathrm\{main\}\}on a dedicated distributed GPU mesh, since it is the only component that requires both expert parallelism and long\-context context parallelism\. The auxiliary policiesπhypothesis\\pi\_\{\\mathrm\{hypothesis\}\}andπsummary\\pi\_\{\\mathrm\{summary\}\}, both implemented as smaller dense models, are served asynchronously on separate small GPU pools\. This avoids fragmenting the main MoE mesh, keeps the main rollout/training pipeline saturated, and allows hypothesis and summary requests to be batched independently\. Code execution, brute\-force checking, and test generation are handled by a separate CPU sandbox pool\.

![Refer to caption](https://arxiv.org/html/2604.02721v1/figs/pipelined_cp.png)Figure 5:An illustration of pipelined context parallelism for one block with 3 DeltaNet layers \(L1, L2, L3\) \+ 1 softmax attention layer with 4 CP ranks and 4 micro\-batches for illustration purposes\. In the DeltaNet phase, each GPU processes micro\-batches \(MB\) in a staggered pipeline, passing the recurrent state forward; startup and drain bubbles \(gray\) are confined to the triangular corners\. The softmax attention layer is executed with synchronized all\-to\-all communication at full utilization\.

## 9RL Infrastructure

### 9\.1Asynchronous Training

As discussed in Section[4](https://arxiv.org/html/2604.02721#S4), we combine Agentic\-GRPO with pipeline\-RL strategyPiché et al\. \[[2025](https://arxiv.org/html/2604.02721#bib.bib25)\]to improve training efficiency and address the off\-line policy problem\.

To control the effect of earlier generated off\-policy tokens, we apply a staleness weightw​\(dt\)w\(d\_\{t\}\)that downweights tokens according to their agedtd\_\{t\}and drops them entirely once a threshold is exceeded:

w​\(dt\)=\{1,if​dt≤K1,exp⁡\(−λ​\(dt−K1\)\),if​K1<dt≤K2,0,if​dt\>K2\.w\(d\_\{t\}\)=\\begin\{cases\}\\\!1,&\\text\{if \}d\_\{t\}\\leq K\_\{1\},\\\\ \\\!\\exp\\\!\\bigl\(\-\\lambda\(d\_\{t\}\-K\_\{1\}\)\\bigr\),&\\text\{if \}K\_\{1\}<d\_\{t\}\\leq K\_\{2\},\\\\ \\\!0,&\\text\{if \}d\_\{t\}\>K\_\{2\}\.\\end\{cases\}\(14\)whereK1K\_\{1\}is the threshold beyond which staleness is penalized andK2K\_\{2\}is the hard max\-lag threshold\. We then weight the token\-level GRPO loss as

Lt=min⁡\(rt​At,clip​\(rt,1−ϵ−,1\+ϵ\+\)​At\)⋅w​\(dt\),L\_\{t\}=\\min\\\!\\bigl\(r\_\{t\}A\_\{t\},\\;\\mathrm\{clip\}\(r\_\{t\},1\-\\epsilon^\{\-\},1\+\\epsilon^\{\+\}\)A\_\{t\}\\bigr\)\\cdot w\(d\_\{t\}\),\(15\)where

rt=πθ​\(yt∣x,y<t\)πθtbeh​\(yt∣x,y<t\)r\_\{t\}=\\frac\{\\pi\_\{\\theta\}\(y\_\{t\}\\mid x,y\_\{<t\}\)\}\{\\pi\_\{\\theta\_\{t\}^\{\\mathrm\{beh\}\}\}\(y\_\{t\}\\mid x,y\_\{<t\}\)\}\(16\)is the token\-level policy ratio, whereθtbeh\\theta\_\{t\}^\{\\mathrm\{beh\}\}denotes the behavior\-policy version that generated tokenyty\_\{t\}, whose age isdtd\_\{t\}\. It is worth noting that the token\-dropping rule in Eq\.[14](https://arxiv.org/html/2604.02721#S9.E14)works naturally together with Agentic\-GRPO\. Intermediate rewards might be not affected, because they are used immediately when they become available\. By contrast, delayed correction terms may be dropped if they arrive too late and exceed the staleness threshold\.

### 9\.2Pipelined CP for DeltaNet\+Softmax Attention Mixture

Because thinking tends to be super long for hard problems, we primarily use context parallelism \(CP\) to address the long\-context issue\.

Hybrid architectures that combine linear attention with softmax attention are becoming increasingly common, balancing the efficiency of linear attention with the stronger modeling capacity of softmax attention\. For example, each block in Qwen3\.5 contains three DeltaNet layers followed by one softmax attention layer\. Since DeltaNet is a linear recurrent operator, standard context parallelism is not a natural fit: CP rankttcannot start processing until CP rankt−1t\-1has finished and passed along the required recurrent state\. Inspired by pipeline parallelism, we therefore use a pipelined CP design by pipelining multiple batches across CP ranks\. Operationally, one block consists of three phases: Phase 1 pipelines the three DeltaNet layers with full overlap across micro\-batches, Phase 2 inserts a synchronization barrier before attention, and Phase 3 executes the softmax attention layer\. This hybrid design preserves the sequential semantics of DeltaNet while amortizing pipeline bubbles over many micro\-batches\. In a representative setting with 4 CP ranks and 4 micro\-batches, one block achieves about 90% overall utilization, and the efficiency further improves when RL training supplies many rollout micro\-batches\. Figure[5](https://arxiv.org/html/2604.02721#S8.F5)illustrates the schedule for 4 CP ranks and 4 micro\-batches\.

### 9\.3Others

#### Balanced Difficulty/Length in Batching

Thinking length is highly correlated with problem difficulty\. As a result, mixing easy and hard problem within the same batch can lead to substantial imbalance in sequence length\. This is also a problem for data parallelism, since different DP workers may otherwise receive batches with very different compute costs\. Therefore, in both RL training and test\-time execution, we organize not only the instances within each batch to have similar difficulty levels, but also align the difficulty of batches across DP workers\. At the beginning, when no runtime statistics are yet available, we batch primarily by difficulty\. We then record the max completion time of its rollout, and when the same instance is revisited in later rounds, we batch it according to the measured completion time from the previous round\.

#### Dynamic CP

Because thinking length varies substantially across difficulty levels, the optimal amount of context parallelism also differs across batches\. Using a single fixed CP size for all batches would therefore be inefficient: easy batches may over\-parallelize short sequences, while hard batches may under\-parallelize very long ones\. We therefore adopt a dynamic CP strategy\[Jiang et al\.,[2025](https://arxiv.org/html/2604.02721#bib.bib10)\], adjusting the CP size based on the difficulty level for each batch\.

#### Expert Routing Stability and Load Balancing

To avoid routing instability during RL training, we freeze the router entirely and update only the expert feed\-forward parameters\. This keeps expert assignments fixed throughout RL, preventing routing drift between rollout and training and avoiding additional instability from changing expert load patterns\.

Micro\-batchesDeltaNet EfficiencyOverall EfficiencyBubble Overhead267%87%13%480%90\.3%9\.7%889%94%∼\\sim6%1694%97%∼\\sim3%NN\(large\)N/\(N\+3\)N/\(N\+3\)→100%\\to 100\\%→0\\to 0Table 5:Efficiency of pipelined context parallelism for the 3DeltaNet\+Softmax Attention mixture as the number of micro\-batches increases\.

## 10Test\-Time/Live\-contest RL

At test time, or equivalently during a live contest, our strategy is centered on test\-time RLAnonymous \[[2025](https://arxiv.org/html/2604.02721#bib.bib2)\], Yuksekgonul et al\. \[[2026](https://arxiv.org/html/2604.02721#bib.bib39)\], Hubert et al\. \[[2025](https://arxiv.org/html/2604.02721#bib.bib8)\]\.

### 10\.1Test\-time RL v\.s\. Post\-training RL

Although RL appears in both the post\-training and test\-time stages, the two settings have different objectives\.Scope:post\-training RL is used to improve the model’s general competitive\-programming ability across many problems, whereas Test\-time RL is used only to solve the specific problem instance at hand, and it optimizes a separate set of parameters for each task instance\.Optimization target:post\-training RL optimizesexpected rewardover rollouts, denoted by

maxθ⁡𝔼s∼πθ\(⋅∣x\)​\[R​\(s\)\],\\max\_\{\\theta\}\\;\\mathbb\{E\}\_\{s\\sim\\pi\_\{\\theta\}\(\\cdot\\mid x\)\}\[R\(s\)\],\(17\)while test\-time RL is primarily concerned with obtaining the single best solution, characterized by the max or best\-of\-N reward as follows:

maxθ𝔼\[maxi=1,…,NR\(si\)\],si∼πθ\(⋅∣x\),\\max\_\{\\theta\}\\;\\mathbb\{E\}\\\!\\left\[\\max\_\{i=1,\\ldots,N\}R\(s\_\{i\}\)\\right\],\\qquad s\_\{i\}\\sim\\pi\_\{\\theta\}\(\\cdot\\mid x\),\(18\)accordingly, the emphasis shifts from improving average reward to finding a rollout with the highest final reward\.

### 10\.2Smoothing the Best\-of\-N Reward

Directly optimizing the exact best\-of\-NNobjective is unrealistic for RL: if one keeps only the single best rollout and discards the others, the reward becomes extremely sparse and training becomes unstable\. Related work such as TTT\-Discover\[Yuksekgonul et al\.,[2026](https://arxiv.org/html/2604.02721#bib.bib39)\]also proposes to smooth the max\-style objective, using weights of the formwβ​\(s\)​\(a\)=eβ​\(s\)​R​\(s,a\)𝔼πθ\(⋅∣s\)​\[eβ​\(s\)​R​\(s,a\)\]w\_\{\\beta\(s\)\}\(a\)=\\frac\{e^\{\\beta\(s\)R\(s,a\)\}\}\{\\mathbb\{E\}\_\{\\pi\_\{\\theta\}\(\\cdot\\mid s\)\}\\\!\\left\[e^\{\\beta\(s\)R\(s,a\)\}\\right\]\}\. Here, we use a simpler rank\-based relaxation\. GivenNNsampled rollouts with rewardsR\(1\)≥⋯≥R\(N\)R^\{\(1\)\}\\geq\\cdots\\geq R^\{\(N\)\}sorted by rank, we optimize

𝒲​\(θ\)=𝔼​\[∑j=1Nwj​\(λ\)​R\(j\)\],\\mathcal\{W\}\(\\theta\)=\\mathbb\{E\}\\\!\\left\[\\sum\_\{j=1\}^\{N\}w\_\{j\}\(\\lambda\)\\,R^\{\(j\)\}\\right\],\(19\)where the weight assigned to rankjjis

wj​\(λ\)=e−λ​j∑m=1Ne−λ​m\.w\_\{j\}\(\\lambda\)=\\frac\{e^\{\-\\lambda j\}\}\{\\sum\_\{m=1\}^\{N\}e^\{\-\\lambda m\}\}\.\(20\)Hereλ\\lambdais a hyperparameter controlling how sharply the weight concentrates on the top\-ranked rollouts\. Whenλ=0\\lambda=0, all weights are uniform and the objective reduces exactly to standard RL based on the average reward\. Asλ\\lambdaincreases, the weight mass shifts toward the best\-ranked rollouts, and the objective increasingly approximates best\-of\-NNoptimization\. We gradually increaseλ\\lambdaduring training, providing a seamless transition from average\-reward optimization to max\-reward optimization\.

### 10\.3Setups

At test time, we optimize LoRA parameters rather than updating the full model\. Unlike post\-training RL, where the context consists primarily of the problem itself, test\-time RL conditions not only on the current question but also on historical candidate solutions generated for this same problem together with their scoresYuksekgonul et al\. \[[2026](https://arxiv.org/html/2604.02721#bib.bib39)\], Li et al\. \[[2025b](https://arxiv.org/html/2604.02721#bib.bib15)\], Surina et al\. \[[2025](https://arxiv.org/html/2604.02721#bib.bib28)\]\. This gap between RLs at post\-training and test\-time conditioning creates a paradigm shift, which justifies the use of LoRA as a lightweight mechanism for fast adaptation\.

StageAccept RateLevel 5 SolvedWeighted Score \(0\-100\)Post\-training72%7/2061\.7Full RL training81%13/2072\.3After test\-time RL85%15/2073\.5Table 6:Progression from post\-training to full RL training and then to test\-time RL on the benchmark\. Test\-time RL is applied only when direct generation is insufficient\.#### Summarizing RL Trials

In addition to historical candidate solutions themselves, we also feed a global summary of the full search history, including which strategies have been explored, how often they have been tried, what works, and what does not\. This idea is akin to the recently popular concept of skills for training LLMs\[Xia et al\.,[2026](https://arxiv.org/html/2604.02721#bib.bib34), Kuroki et al\.,[2024](https://arxiv.org/html/2604.02721#bib.bib11)\]\. This summary is updated online: at each step, we combine the previous summary with the newly generated candidates to form a new summary\. In the current system, this global summarization is handled by a fixed policy rather than being optimized online\. This can significantly improve RL efficiency by making better use of a small number of rollouts, which is especially important in the online test\-time setting where available time is limited\.

### 10\.4Live\-contest Strategies

#### Balancing Direct Generation and Test\-Time RL

At test time, we want to produce a correct submission as quickly as possible, since earlier accepted submissions receive higher scores\. Because test\-time RL is expensive, we do not use it for every problem\. For easier problems, such as early contest problems, we first try direct generation with larger batch size running in parallel and evaluate them\. We use test\-time RL only when direct generation is not enough\.

πhypothesis\\pi\_\{\\mathrm\{hypothesis\}\}, andπsummary\\pi\_\{\\mathrm\{summary\}\}are fixed at test\-time, and onlyπmain\\pi\_\{\\mathrm\{main\}\}is updated\.

### 10\.5Results

Table[6](https://arxiv.org/html/2604.02721#S10.T6)summarizes the progression from the post\-training model to full RL training and then to test\-time RL\. Starting from the post\-training result of 72% accept rate, 7/20 solved Level 5 problems, and a weighted score of 61\.7, full RL training substantially improves performance to 81%, 13/20, and 72\.3, respectively\. Applying test\-time RL yields a further gain to 85% overall accept rate, 15/20 solved Level 5 problems, and a weighted score of 73\.5\. These results suggest that offline RL training already provides a large improvement in core problem\-solving ability, while test\-time RL is especially helpful on the hardest problems\.

## 11Conclusion

In this work, we introduced GrandCode, a multi\-agent reinforcement learning system for agentic competitive programming\. Its performance comes from two main ingredients: a coordinated agentic loop of reasoning, hypothesis generation, summarization, test\-case generation, and verification; and Agentic GRPO, which addresses delayed rewards and severe off\-policy drift in long, multi\-stage agent rollouts\.

Across offline benchmarks, continued training, supervised fine\-tuning, full RL, and test\-time RL all contribute meaningful gains, especially on hard problems\. Under standard live contest conditions, GrandCode ranked first in all three recent Codeforces rounds in which it participated, outperforming all human contestants, including top legendary grandmasters\. Taken together, these results suggest that agentic reinforcement learning, when combined with strong verification and online adaptation, can push coding systems beyond top human performance in real\-time environments\.

## References

- AlphaCode Team, Google DeepMind \[2023\]AlphaCode Team, Google DeepMind\.AlphaCode 2 technical report\.Technical report, Google DeepMind, 2023\.URL[https://storage\.googleapis\.com/deepmind\-media/AlphaCode2/AlphaCode2\_Tech\_Report\.pdf](https://storage.googleapis.com/deepmind-media/AlphaCode2/AlphaCode2_Tech_Report.pdf)\.
- Anonymous \[2025\]Anonymous\.TTRL: Test\-time reinforcement learning\.*arXiv preprint arXiv:2504\.16084*, 2025\.
- Chan et al\. \[2026\]Aaron Chan, Ahmed Shalaby, Alexander Wettig, et al\.Composer 2 technical report\.*arXiv preprint arXiv:2603\.24477*, 2026\.
- DeepSeek\-AI \[2025\]DeepSeek\-AI\.DeepSeek\-V3 technical report\.*arXiv preprint arXiv:2412\.19437*, 2025\.
- Dou et al\. \[2025\]Zhihao Dou, Qinjian Zhao, and Sumon Biswas\.Algoforge: Specializing code generation agents through collaborative reinforcement learning\.OpenReview, 2025\.ICLR 2026 withdrawn submission\.
- El\-Kishky et al\. \[2025\]Ahmed El\-Kishky, Alexander Wei, Andre Saraiva, Borys Minaiev, Daniel Selsam, David Dohan, Francis Song, Hunter Lightman, Ignasi Clavera, Jakub Pachocki, Jerry Tworek, Lorenz Kuhn, Lukasz Kaiser, Mark Chen, Max Schwarzer, Mostafa Rohaninejad, Nat McAleese, o3 contributors, Oleg Mürk, Rhythm Garg, Rui Shu, Szymon Sidor, Vineet Kosaraju, and Wenda Zhou\.Competitive programming with large reasoning models\.*arXiv preprint arXiv:2502\.06807*, 2025\.
- Google DeepMind \[2025\]Google DeepMind\.Gemini 2\.5: Our newest gemini model with thinking\.[https://deepmind\.google/blog/gemini\-2\-5\-our\-most\-intelligent\-ai\-model/](https://deepmind.google/blog/gemini-2-5-our-most-intelligent-ai-model/), 2025\.Technical blog post\.
- Hubert et al\. \[2025\]Thomas Hubert, Rishi Mehta, David Silver, et al\.Olympiad\-level formal mathematical reasoning with reinforcement learning\.*Nature*, 2025\.doi:10\.1038/s41586\-025\-09833\-y\.
- IOI \[2026\]IOI\.International Olympiad in Informatics \(IOI\)\.[https://www\.ioinformatics\.org/](https://www.ioinformatics.org/), 2026\.Accessed 2026\-03\-25\.
- Jiang et al\. \[2025\]Chenyu Jiang, Zhenkun Cai, Ye Tian, Zhen Jia, Yida Wang, and Chuan Wu\.DCP: Addressing input dynamism in long\-context training via dynamic context parallelism\.In*Proceedings of the ACM SIGOPS 31st Symposium on Operating Systems Principles*, pp\. 221–236, 2025\.
- Kuroki et al\. \[2024\]So Kuroki, Taishi Nakamura, Takuya Akiba, and Yujin Tang\.Agent skill acquisition for large language models via CycleQD\.*arXiv preprint arXiv:2410\.14735*, 2024\.ICLR 2025\.
- LeetCode \[2026\]LeetCode\.LeetCode\.[https://leetcode\.com/](https://leetcode.com/), 2026\.Accessed 2026\-03\-25\.
- Li et al\. \[2023\]Ge Li, Zhi Jin, Guang Liu, Chen Lyu, Zhihong Sun, Tao Huang, Bo\-Wen Zhang, Jie Fu, and Rongao Li\.TACO: Topics in algorithmic code generation dataset\.*arXiv preprint arXiv:2312\.14852*, 2023\.
- Li et al\. \[2025a\]Xiangyang Li, Xiaopeng Li, Kuicai Dong, Quanhu Zhang, Rongju Ruan, Xinyi Dai, Xiaoshuang Liu, Shengchun Xu, Yasheng Wang, and Ruiming Tang\.Humanity’s last code exam: Can advanced LLMs conquer human’s hardest code competition?*arXiv preprint arXiv:2506\.12713*, 2025a\.
- Li et al\. \[2025b\]Xiaoya Li, Xiaofei Sun, Albert Wang, Jiwei Li, and Chris Shum\.Cuda\-l1: Improving CUDA optimization via contrastive reinforcement learning\.*arXiv preprint arXiv:2507\.14111*, 2025b\.
- Li et al\. \[2022\]Yujia Li, David Choi, Junyoung Chung, Nate Kushman, Julian Schrittwieser, Rémi Leblond, Tom Eccles, James Keeling, Felix Gimeno, Agustin Dal Lago, et al\.Competition\-level code generation with AlphaCode\.*Science*, 378\(6624\):1092–1097, 2022\.
- Liu et al\. \[2025\]Yifei Liu, Li Lyna Zhang, Yi Zhu, Bingcheng Dong, Xudong Zhou, Ning Shang, Fan Yang, and Mao Yang\.rStar\-Coder: Scaling competitive code reasoning with a large\-scale verified dataset\.*arXiv preprint arXiv:2505\.21297*, 2025\.
- Llama Team, AI @ Meta \[2024\]Llama Team, AI @ Meta\.The Llama 3 herd of models\.*arXiv preprint arXiv:2407\.21783*, 2024\.
- Ma et al\. \[2026\]Zeyao Ma, Jing Zhang, Xiaokang Zhang, Jiaxi Yang, Zongmeng Zhang, Jiajun Zhang, Yuheng Jing, Lei Zhang, Hao Zheng, Wenting Zhao, Junyang Lin, and Binyuan Hui\.Scaling agentic verifier for competitive coding\.*arXiv preprint arXiv:2602\.04254*, 2026\.
- Moonshot AI \[2025\]Moonshot AI\.Kimi k2\.5 release\.[https://www\.moonshot\.ai/news/kimi\-k2\-5\-release](https://www.moonshot.ai/news/kimi-k2-5-release), 2025\.Technical report\.
- OpenAI \[2023\]OpenAI\.GPT\-4 technical report\.*arXiv preprint arXiv:2303\.08774*, 2023\.
- OpenAI \[2024a\]OpenAI\.GPT\-4o system card\.*arXiv preprint arXiv:2410\.21276*, 2024a\.
- OpenAI \[2024b\]OpenAI\.Openai o1 system card\.*arXiv preprint arXiv:2412\.16720*, 2024b\.
- OpenAI \[2025\]OpenAI\.Openai o3 and o4\-mini system card\.Technical report, 2025\.URL[https://cdn\.openai\.com/pdf/2221c875\-02dc\-4789\-800b\-e7758f3722c1/o3\-and\-o4\-mini\-system\-card\.pdf](https://cdn.openai.com/pdf/2221c875-02dc-4789-800b-e7758f3722c1/o3-and-o4-mini-system-card.pdf)\.
- Piché et al\. \[2025\]Alexandre Piché, Ehsan Kamalloo, Rafael Pardinas, Xiaoyin Chen, and Dzmitry Bahdanau\.Pipelinerl: Faster on\-policy reinforcement learning for long sequence generation\.*arXiv preprint arXiv:2509\.19128*, 2025\.
- Quan et al\. \[2025\]Shanghaoran Quan, Jiaxi Yang, Bowen Yu, Bo Zheng, Dayiheng Liu, An Yang, Xuancheng Ren, Bofei Gao, Yibo Miao, Yunlong Feng, Zekun Wang, Jian Yang, Zeyu Cui, Yang Fan, Yichang Zhang, Binyuan Hui, and Junyang Lin\.CodeElo: Benchmarking competition\-level code generation of LLMs with human\-comparable elo ratings\.*arXiv preprint arXiv:2501\.01257*, 2025\.
- Shao et al\. \[2024\]Zhihong Shao, Peiyi Wang, Qihao Zhu, Runxin Xu, Junxiao Song, Xiao Bi, Haowei Zhang, Mingchuan Zhang, Y\.K\. Li, Y\. Wu, and Daya Guo\.DeepSeekMath: Pushing the limits of mathematical reasoning in open language models\.*arXiv preprint arXiv:2402\.03300*, 2024\.
- Surina et al\. \[2025\]Anja Surina, Amin Mansouri, Lars Quaedvlieg, Amal Seddas, Maryna Viazovska, Emmanuel Abbe, and Caglar Gulcehre\.Algorithm discovery with LLMs: Evolutionary search meets reinforcement learning\.*arXiv preprint arXiv:2504\.05108*, 2025\.
- Thinking Machines Lab \[2025\]Thinking Machines Lab\.Tinker\.[https://github\.com/thinking\-machines\-lab/tinker](https://github.com/thinking-machines-lab/tinker), 2025\.Open\-source training API\.
- THUDM \[2026\]THUDM\.slime\.[https://github\.com/THUDM/slime](https://github.com/THUDM/slime), 2026\.Open\-source reinforcement learning post\-training framework\.
- USACO \[2026\]USACO\.USA Computing Olympiad \(USACO\)\.[http://www\.usaco\.org/](http://www.usaco.org/), 2026\.Accessed 2026\-03\-25\.
- Wang et al\. \[2025a\]Zihan Wang, Jiaze Chen, Zhicheng Liu, Markus Mak, Yidi Du, Geonsik Moon, Luoqi Xu, Aaron Tua, Kunshuo Peng, Jiayi Lu, Mingfei Xia, Boqian Zou, Chenyang Ran, Guang Tian, Shoutai Zhu, Yeheng Duan, Zhenghui Kang, Zhenxing Lin, Shangshu Li, Qiang Luo, Qingshen Long, Zhiyong Chen, Yihan Xiao, Yurong Wu, Daoguang Zan, Yuyi Fu, Mingxuan Wang, and Ming Ding\.AetherCode: Evaluating LLMs’ ability to win in premier programming competitions\.*arXiv preprint arXiv:2508\.16402*, 2025a\.
- Wang et al\. \[2025b\]Zihan Wang, Siyao Liu, Yang Sun, Hongyan Li, and Kai Shen\.CodeContests\+: High\-quality test case generation for competitive programming\.*arXiv preprint arXiv:2506\.05817*, 2025b\.
- Xia et al\. \[2026\]Peng Xia, Jianwen Chen, Hanyang Wang, Jiaqi Liu, Kaide Zeng, Yu Wang, Siwei Han, Yiyang Zhou, Xujiang Zhao, Haifeng Chen, Zeyu Zheng, Cihang Xie, and Huaxiu Yao\.SkillRL: Evolving agents via recursive skill\-augmented reinforcement learning\.*arXiv preprint arXiv:2602\.08234*, 2026\.
- Yang et al\. \[2024\]An Yang, Baosong Yang, Beichen Zhang, Binyuan Hui, Bo Zheng, Bowen Yu, Chengyuan Li, Dayiheng Liu, Fei Huang, et al\.Qwen2\.5 technical report\.*arXiv preprint arXiv:2412\.15115*, 2024\.
- Yang et al\. \[2025\]Lei Yang, Renren Jin, Ling Shi, Jianxiang Peng, Yue Chen, and Deyi Xiong\.ProBench: Benchmarking large language models in competitive programming\.*arXiv preprint arXiv:2502\.20868*, 2025\.
- Yu et al\. \[2025\]Hongli Yu, Tinghong Chen, Jiangtao Feng, Jiangjie Chen, Weinan Dai, Qiying Yu, Ya\-Qin Zhang, Wei\-Ying Ma, Jingjing Liu, Mingxuan Wang, and Hao Zhou\.MemAgent: Reshaping long\-context LLM with multi\-conv RL\-based memory agent\.*arXiv preprint arXiv:2507\.02259*, 2025\.
- Yu et al\. \[2026\]Yi Yu, Liuyi Yao, Yuexiang Xie, Qingquan Tan, Jiaqi Feng, Yaliang Li, and Libing Wu\.Agentic memory: Learning unified long\-term and short\-term memory management for large language model agents\.*arXiv preprint arXiv:2601\.01885*, 2026\.
- Yuksekgonul et al\. \[2026\]Mert Yuksekgonul, Daniel Koceja, Xinhao Li, Federico Bianchi, Jed McCaleb, Xiaolong Wang, Jan Kautz, Yejin Choi, James Zou, Carlos Guestrin, and Yu Sun\.Learning to discover at test time\.*arXiv preprint arXiv:2601\.16175*, 2026\.
- Zheng et al\. \[2026\]Shenyu Zheng, Ximing Dong, Xiaoshuang Liu, Gustavo Oliva, Chong Chun Yong, Dayi Lin, Boyuan Chen, Shaowei Wang, and Ahmed E\. Hassan\.When elo lies: Hidden biases in codeforces\-based evaluation of large language models\.*arXiv preprint arXiv:2602\.05891*, 2026\.
- Zhipu AI and Tsinghua University KEG \[2024\]Zhipu AI and Tsinghua University KEG\.GLM\-4: Open multilingual multimodal chat lms\.[https://github\.com/zai\-org/GLM\-4](https://github.com/zai-org/GLM-4), 2024\.Project page\.

## Appendix ASubmission Details

Figure[6](https://arxiv.org/html/2604.02721#A3.F6)shows the standings pages together with the corresponding submission pages for thejointsetup in the three live Codeforces contests, where all codes need to be submitted in a single account\. These screenshots provide direct evidence of the contest identities, submission accounts, scores, accepted solutions, and the times at which the full problem sets were completed\. The three paired screenshots correspond to Round 1087 under the IDaveryjones1, Round 1088 under the IDyokeko, and Round 1089 under the IDVortex1\.

## Appendix BCode Reward

Reward for a generated code snippet can summarized formally as follows\. LetPPdenote a generated code snippet, and letT=\{t1,…,tm\}T=\\\{t\_\{1\},\\ldots,t\_\{m\}\\\}denote the generated test set\. For each test casetit\_\{i\}, define the reference output

ri=\{y⋆​\(ti\),if a gold solution​y⋆​is available,b​\(ti\),otherwise, where​b​is a brute\-force solver\.r\_\{i\}=\\begin\{cases\}y^\{\\star\}\(t\_\{i\}\),&\\text\{if a gold solution \}y^\{\\star\}\\text\{ is available\},\\\\ b\(t\_\{i\}\),&\\text\{otherwise, where \}b\\text\{ is a brute\-force solver\.\}\\end\{cases\}\(21\)Define the executability and correctness indicators by

E​\(P\)=\{1,if​P​compiles and executes,0,otherwise,C​\(P\)=\{1,if​P​\(ti\)=ri​for all correctness\-check tests,0,otherwise\.E\(P\)=\\begin\{cases\}1,&\\text\{if \}P\\text\{ compiles and executes\},\\\\ 0,&\\text\{otherwise,\}\\end\{cases\}\\qquad C\(P\)=\\begin\{cases\}1,&\\text\{if \}P\(t\_\{i\}\)=r\_\{i\}\\text\{ for all correctness\-check tests\},\\\\ 0,&\\text\{otherwise\.\}\\end\{cases\}\(22\)For each efficiency test casetit\_\{i\}, define

si​\(P\)=\{τb​\(ti\)τP​\(ti\),if​P​finishes within the time limit,0\.1,if​P​times out,s\_\{i\}\(P\)=\\begin\{cases\}\\dfrac\{\\tau\_\{b\}\(t\_\{i\}\)\}\{\\tau\_\{P\}\(t\_\{i\}\)\},&\\text\{if \}P\\text\{ finishes within the time limit\},\\\\ 0\.1,&\\text\{if \}P\\text\{ times out,\}\\end\{cases\}\(23\)whereτb​\(ti\)\\tau\_\{b\}\(t\_\{i\}\)andτP​\(ti\)\\tau\_\{P\}\(t\_\{i\}\)denote the runtimes of the brute\-force solver and the generated code snippet, respectively\. The final score is then

R​\(P\)=\{0,if​E​\(P\)=0,0,if​C​\(P\)=0,1m​∑i=1msi​\(P\),otherwise\.R\(P\)=\\begin\{cases\}0,&\\text\{if \}E\(P\)=0,\\\\ 0,&\\text\{if \}C\(P\)=0,\\\\ \\dfrac\{1\}\{m\}\\sum\_\{i=1\}^\{m\}s\_\{i\}\(P\),&\\text\{otherwise\.\}\\end\{cases\}\(24\)

## Appendix CAnalysis on agentic\-GRPO

In standard GRPO, all tokens in the full trajectorys1,s2,…,sNs\_\{1\},s\_\{2\},\\ldots,s\_\{N\}are updated using the final rewardrNr\_\{N\}with a single normalized advantage:

A\(i\)=rN\(i\)−μNσN,μN=1K​∑i=1KrN\(i\),σN=std​\(rN\(1\),…,rN\(K\)\)\.A^\{\(i\)\}=\\frac\{r\_\{N\}^\{\(i\)\}\-\\mu\_\{N\}\}\{\\sigma\_\{N\}\},\\qquad\\mu\_\{N\}=\\frac\{1\}\{K\}\\sum\_\{i=1\}^\{K\}r\_\{N\}^\{\(i\)\},\\qquad\\sigma\_\{N\}=\\mathrm\{std\}\\\!\\left\(r\_\{N\}^\{\(1\)\},\\ldots,r\_\{N\}^\{\(K\)\}\\right\)\.\(25\)In Agentic GRPO, tokens in stagests\_\{t\}receive two updates: an immediate reward advantage normalized byσt\\sigma\_\{t\}, and a delayed correction advantage normalized byσδt=std​\(δt\(1\),…,δt\(K\)\)\\sigma\_\{\\delta\_\{t\}\}=\\mathrm\{std\}\(\\delta\_\{t\}^\{\(1\)\},\\ldots,\\delta\_\{t\}^\{\(K\)\}\)\. The unnormalized signals decompose exactly:

\(rt\(i\)−μt\)\+\(δt\(i\)−μδt\)=rN\(i\)−μN,\\bigl\(r\_\{t\}^\{\(i\)\}\-\\mu\_\{t\}\\bigr\)\+\\bigl\(\\delta\_\{t\}^\{\(i\)\}\-\\mu\_\{\\delta\_\{t\}\}\\bigr\)=r\_\{N\}^\{\(i\)\}\-\\mu\_\{N\},\(26\)sinceμt\+μδt=μN\\mu\_\{t\}\+\\mu\_\{\\delta\_\{t\}\}=\\mu\_\{N\}\. However, because each phase normalizes with its own group statistics, the sum of the two normalized advantages does not recover the standard GRPO advantage:

rt\(i\)−μtσt\+δt\(i\)−μδtσδt≠rN\(i\)−μNσN,\\frac\{r\_\{t\}^\{\(i\)\}\-\\mu\_\{t\}\}\{\\sigma\_\{t\}\}\+\\frac\{\\delta\_\{t\}^\{\(i\)\}\-\\mu\_\{\\delta\_\{t\}\}\}\{\\sigma\_\{\\delta\_\{t\}\}\}\\;\\neq\\;\\frac\{r\_\{N\}^\{\(i\)\}\-\\mu\_\{N\}\}\{\\sigma\_\{N\}\},\(27\)as in generalσt≠σN≠σδt\\sigma\_\{t\}\\neq\\sigma\_\{N\}\\neq\\sigma\_\{\\delta\_\{t\}\}\. We argue that this discrepancy is a feature rather than a limitation\. Independent normalization ensures that each signal as the immediate stage quality and the marginal contribution of future stages—is scaled to its own natural magnitude\. If, for example, the immediate rewardsrtr\_\{t\}concentrate in a narrow range while the correctionsδt\\delta\_\{t\}exhibit high variance \(or vice versa\), a shared normalizerσN\\sigma\_\{N\}would let one signal dominate the other\. Per\-phase normalization gives each stage*equal voice*in the gradient, providing more balanced credit assignment across stages regardless of their respective reward scales\.

![Refer to caption](https://arxiv.org/html/2604.02721v1/standings/1.png)

![Refer to caption](https://arxiv.org/html/2604.02721v1/submissions/1.png)

\(a\)Round 1087, IDaveryjones1\.
![Refer to caption](https://arxiv.org/html/2604.02721v1/standings/2.png)

![Refer to caption](https://arxiv.org/html/2604.02721v1/submissions/2.png)

\(b\)Round 1088, IDyokeko\.
![Refer to caption](https://arxiv.org/html/2604.02721v1/standings/3.png)

![Refer to caption](https://arxiv.org/html/2604.02721v1/submissions/3.png)

\(c\)Round 1089, IDVortex1\.

Figure 6:Standings and submission pages for GrandCode in the three live Codeforces contests\. The score corresponds toS​\(joint\)S\(\\mathrm\{joint\}\), which is based on the full set of submissions in a single account\.![Refer to caption](https://arxiv.org/html/2604.02721v1/x1.png)

![Refer to caption](https://arxiv.org/html/2604.02721v1/x2.png)

Figure 7:Standings and submission pages for GrandCode\. The score corresponds toS​\(seperate\)S\(\\mathrm\{seperate\}\), the score achieved by each solution as soon as it is ready\. \(a\) Round 1087\. A–492, B–685, C–1476, D–1603, E–2169, F–2844;S​\(seperate\)S\(\\mathrm\{seperate\}\): 9269\. \(b\) Round 1088\. A–486, B–1234, C1–1230, C2–959, D–1968, E–2054, F–2895, G–2888, H–2797;S​\(seperate\)S\(\\mathrm\{seperate\}\): 16511\.\\floatpagestyle

empty![Refer to caption](https://arxiv.org/html/2604.02721v1/x3.png)

Figure 8:Standings and submission pages for GrandCode in Round 1089\. The score corresponds toS​\(seperate\)S\(\\mathrm\{seperate\}\), the score achieved by each solution as soon as it is ready\. A – 498, B – 976, C1 – 1225, C2 – 944, D – 2088, E – 2519, F – 3346;S​\(seperate\)S\(\\mathrm\{seperate\}\): 11596\.G\. ToothlessTime limit: 2 s∣\\midMemory: 256 MB∣\\midI/O: standard input / standard outputLetn,m,a,bn,m,a,bbe positive integers witha≤ba\\leq b\. Toothless is drawing in ann×mn\\times mgrid of sand that is initially all white\. In one move, he may do the following:•Select any currently white cell and color it black if it has at most one black cell among its edge\-adjacent neighbors\.Because he is particular about his art, Toothless thinks some cells in the grid are*needy*, and these cells must end up black\. Of the cells that aren’t needy, he also thinks some of them are*special*\. A cell has valuebbif it is special, andaaotherwise\.No special cell borders a needy cell by an edge\.LetPPbe the sum of the values of all the cells in the grid thataren’tneedy\. Because Toothless is very particular about his art, he wants to make some number of moves such that:•Each of the needy cells becomes black after all moves are done,•The total value of cells that are colored black \(includingneedy cells\) is at least23⋅P\\frac\{2\}\{3\}\\cdot P\.Compute any sequence of moves that Toothless could make\. Tests are generated in a such way, that it is guaranteed that all of the needy cells in the input can be shaded black after some number of moves\. Furthermore, it can be shown that for the given constraints, a satisfying sequence of moves always exists\.Input\.Each test contains multiple test cases\. The first line contains the number of test casestt\(1≤t≤1041\\leq t\\leq 10^\{4\}\)\. The description of the test cases follows\.The first line of each test case contains four integersnn,mm,aa, andbb\(1≤n,m≤2⋅1031\\leq n,m\\leq 2\\cdot 10^\{3\},1≤n⋅m≤2⋅1031\\leq n\\cdot m\\leq 2\\cdot 10^\{3\},1≤a≤b≤5⋅1051\\leq a\\leq b\\leq 5\\cdot 10^\{5\}\) — the dimensions of the grid and the values of non\-special and special cells, respectively\. Theii\-th of the nextnnlines each contain a stringsis\_\{i\}— a string of exactlymmcharacters depicting theii\-th row of cells\.•Thejj\-th character is ‘\#’ if the cell at\(i,j\)\(i,j\)is needy\.•Thejj\-th character is ‘x’ if the cell at\(i,j\)\(i,j\)is special\.•Otherwise, thejj\-th character is ‘\.’\.It is guaranteed that no needy cell is adjacent to a special cell\. Tests are generated in a such way, that it is guaranteed that all of the needy cells in the input can be shaded black after some number of moves\. It is guaranteed that the sum of\(n​m\)2\(nm\)^\{2\}over all test cases does not exceed4⋅1064\\cdot 10^\{6\}\.Output\.For each test case, print the following\. In the first line, print the number of moves𝑜𝑝\\mathit\{op\}\(0≤𝑜𝑝≤n⋅m0\\leq\\mathit\{op\}\\leq n\\cdot m\) you want to make\. For each of the𝑜𝑝\\mathit\{op\}moves, print a line containing two integersii,jj\(1≤i≤n1\\leq i\\leq n,1≤j≤m1\\leq j\\leq m\), indicating that you wish to color the cell at\(i,j\)\(i,j\)black\.Input[⬇](data:text/plain;base64,MwozIDMgMSA1CiMuLgouLi4KLi54CjIgMyAxIDIKLi4uCnh4eAozIDUgOCA5CngueC54Ci54LnguCnguIy54)33315\#\.\.\.\.\.\.\.x2312\.\.\.xxx3589x\.x\.x\.x\.x\.x\.\#\.xOutput[⬇](data:text/plain;base64,NgoxIDEKMyAxCjMgMgozIDMKMiAzCjEgMwozCjIgMQoyIDIKMiAzCjEwCjEgMQoxIDIKMSAzCjIgMgoyIDUKMSA1CjMgNQoyIDQKMyAzCjMgMQ==)611313233231332122231011121322251535243331Note\.In the first test case, there is a needy cell in the top left corner and a special cell in the bottom right corner\. Of the cells that aren’t needy, there are 7 non\-special cells worth11each and 1 special cell worth55, soP=12P=12\. So, we need to shade cells with a total value of at least23⋅12=8\\tfrac\{2\}\{3\}\\cdot 12=8; the given sequence of moves achieves a value of1010\. In the second test case, there are no needy cells, but there are three special cells in the bottom row of cells\. There are 3 non\-special cells worth11each and 3 special cells worth22, soP=9P=9\. So, we need to shade cells with a total value of at least23⋅9=6\\tfrac\{2\}\{3\}\\cdot 9=6; the given sequence of moves achieves a value of66\. In the third test case, there is one needy cell at\(3,3\)\(3,3\), and77special cells\. Of the cells that aren’t needy, there are 7 non\-special cells worth88each and 7 special cells worth99, soP=7⋅8\+7⋅9=119P=7\\cdot 8\+7\\cdot 9=119\. So, we need to shade cells with a total value of at least23⋅119=79⁤13\\tfrac\{2\}\{3\}\\cdot 119=79\\tfrac\{1\}\{3\}; the given sequence of moves achieves a value of8787\.![Refer to caption](https://arxiv.org/html/2604.02721v1/figs/1.png)\(a\) Test 1![Refer to caption](https://arxiv.org/html/2604.02721v1/figs/2.png)\(b\) Test 2![Refer to caption](https://arxiv.org/html/2604.02721v1/figs/3.png)\(c\) Test 3Figure 9:Problem G\. Toothless \(Round 1088, Div\. 1\+2\): complete statement, sample I/O, and example illustrations\. Each panel shows the grid before \(left\) and after \(right\) moves; dark cells are colored black\.
## Appendix DSubmitted Code

### Round 1089\-A

1\#include<iostream\>

2\#include<vector\>

3\#include<algorithm\>

4usingnamespacestd;

5

6intmain\(\)\{

7ios::sync\_with\_stdio\(false\);

8cin\.tie\(nullptr\);

9

10inta;

11cin\>\>a;

12while\(a\-\-\)\{

13intb;

14cin\>\>b;

15vector<int\>c\(b\+1\),d\(b\+1\);

16for\(inti=1;i<=b;i\+\+\)\{

17cin\>\>c\[i\];

18d\[c\[i\]\]=i;

19\}

20

21inte=0;

22intf=0;

23intg=1;

24while\(g<=b\)\{

25if\(d\[g\]<g\)e\+\+;

26inth=g\-e;

27if\(h\>f\)f=h;

28g\+\+;

29\}

30

31cout<<f<<'\\n';

32\}

33

34return0;

35\}

### Round 1088\-E

1\#include<bits/stdc\+\+\.h\>

2usingnamespacestd;

3typedefunsignedlonglongu64;

4

5\#ifdefined\(\_WIN32\)\|\|defined\(\_WIN64\)

6\#definegetchar\_unlockedgetchar

7\#endif

8

9structR\{

10template<classT\>

11boolread\(T&x\)\{

12intc=getchar\_unlocked\(\);

13if\(c==EOF\)returnfalse;

14while\(c<=''\)\{

15c=getchar\_unlocked\(\);

16if\(c==EOF\)returnfalse;

17\}

18Tv=0;

19while\(c\>''\)\{

20v=v\*10\+\(T\)\(c\-'0'\);

21c=getchar\_unlocked\(\);

22\}

23x=v;

24returntrue;

25\}

26\};

27

28structS\{

29staticconstintINF=1e9;

30

31structFr\{

32inta;

33u64b;

34intc;

35intd;

36boole;

37\};

38

39intn;

40vector<u64\>a;

41vector<vector<int\>\>b;

42vector<int\>c;

43vector<int\>d;

44vector<vector<pair<u64,int\>\>\>e;

45vector<Fr\>f;

46

47S\(intn\):n\(n\),a\(n\+1,0\),b\(n\+1\),c\(n\+1,0\),d\(n\+1,0\),e\(n\+1\)\{\}

48

49intfc\(intu,u64g\)\{

50auto&v=e\[u\];

51for\(inti=0;i<\(int\)v\.size\(\);i\+\+\)

52if\(v\[i\]\.first==g\)returni;

53return\-1;

54\}

55

56intqr\(ints,u64g0\)\{

57if\(g0==1\)returnINF;

58intp=fc\(s,g0\);

59if\(p\!=\-1\)returne\[s\]\[p\]\.second;

60

61f\.clear\(\);

62f\.push\_back\(\{s,g0,0,0,false\}\);

63

64while\(\!f\.empty\(\)\)\{

65Fr&cur=f\.back\(\);

66intcc=fc\(cur\.a,cur\.b\);

67if\(cc\!=\-1\)\{f\.pop\_back\(\);continue;\}

68

69if\(\!cur\.e\)\{

70if\(gcd\(a\[cur\.a\],cur\.b\)==1ULL\)\{

71e\[cur\.a\]\.push\_back\(\{cur\.b,INF\}\);

72f\.pop\_back\(\);

73continue;

74\}

75cur\.e=true;

76cur\.c=0;

77cur\.d=0;

78\}

79

80boolpushed=false;

81auto&ch=b\[cur\.a\];

82while\(cur\.c<\(int\)ch\.size\(\)\)\{

83intv=ch\[cur\.c\];

84u64ng=gcd\(cur\.b,a\[v\]\);

85if\(ng==1ULL\)\{cur\.c\+\+;continue;\}

86intci=fc\(v,ng\);

87if\(ci==\-1\)\{

88f\.push\_back\(\{v,ng,0,0,false\}\);

89pushed=true;

90break;

91\}

92cur\.d=min\(cur\.d,e\[v\]\[ci\]\.second\-c\[v\]\-1\);

93cur\.c\+\+;

94\}

95if\(pushed\)continue;

96

97e\[cur\.a\]\.push\_back\(\{cur\.b,d\[cur\.a\]\+cur\.d\}\);

98f\.pop\_back\(\);

99\}

100

101p=fc\(s,g0\);

102returne\[s\]\[p\]\.second;

103\}

104\};

105

106intmain\(\)\{

107Rin;

108intt;

109in\.read\(t\);

110

111while\(t\-\-\)\{

112intn;

113in\.read\(n\);

114

115Ssv\(n\);

116vector<int\>ind\(n\+1,0\);

117longlongec=0;

118boolbad=false;

119

120for\(intu=n;u\>=1;u\-\-\)\{

121intk;

122in\.read\(sv\.a\[u\]\);

123in\.read\(k\);

124ec\+=k;

125

126sv\.b\[u\]\.reserve\(k\);

127intbs=1;

128

129for\(inti=0;i<k;i\+\+\)\{

130intv;

131in\.read\(v\);

132sv\.b\[u\]\.push\_back\(v\);

133if\(v<=u\|\|v\>n\)bad=true;

134else\{

135ind\[v\]\+\+;

136if\(ind\[v\]\>1\)bad=true;

137\}

138bs\+=sv\.c\[v\];

139\}

140

141sv\.d\[u\]=bs;

142sv\.e\[u\]\.reserve\(4\);

143sv\.c\[u\]=sv\.qr\(u,sv\.a\[u\]\);

144

145printf\("%d\\n",sv\.c\[u\]\);

146fflush\(stdout\);

147\}

148

149if\(ec\!=n\-1\)bad=true;

150if\(ind\[1\]\!=0\)bad=true;

151for\(inti=2;i<=n;i\+\+\)\{

152if\(ind\[i\]\!=1\)\{bad=true;break;\}

153\}

154

155if\(bad\)\{

156printf\("\-1\\n"\);

157fflush\(stdout\);

158return0;

159\}

160\}

161

162return0;

163\}

### Round 1088\-F

1\#include<bits/stdc\+\+\.h\>

2usingnamespacestd;

3

4constintP=676767677;

5

6longlongpw\(longlonga,longlongb\)\{

7longlongr=1;

8for\(;b\>0;b\>\>=1\)\{

9if\(b&1\)r=r\*a%P;

10a=a\*a%P;

11\}

12returnr;

13\}

14

15structA\{

16vector<longlong\>a,b;

17A\(intn\):a\(n\+1\),b\(n\+1\)\{

18a\[0\]=1;

19for\(inti=1;i<=n;i\+\+\)

20a\[i\]=a\[i\-1\]\*i%P;

21b\[n\]=pw\(a\[n\],P\-2\);

22for\(inti=n;i\>=1;i\-\-\)

23b\[i\-1\]=b\[i\]\*i%P;

24\}

25longlongc\(intn,intk\)const\{

26if\(n<0\|\|k<0\|\|k\>n\)return0;

27returna\[n\]\*b\[k\]%P\*b\[n\-k\]%P;

28\}

29\};

30

31structB\{

32inta,b,c;

33\};

34

35intmain\(\)\{

36ios::sync\_with\_stdio\(false\);

37cin\.tie\(0\);

38

39intt;

40cin\>\>t;

41vector<pair<int,int\>\>q\(t\);

42intmx=0;

43for\(inti=0;i<t;i\+\+\)\{

44cin\>\>q\[i\]\.first\>\>q\[i\]\.second;

45mx=max\(mx,q\[i\]\.first\+q\[i\]\.second\);

46\}

47

48Acb\(mx\);

49

50for\(inti=0;i<t;i\+\+\)\{

51intn=q\[i\]\.first,m=q\[i\]\.second;

52longlongbase=cb\.c\(n\+m\-1,m\-1\);

53longlongans=0;

54

55vector<B\>st;

56st\.push\_back\(\{1,n,1\}\);

57

58while\(\!st\.empty\(\)\)\{

59Bcur=st\.back\(\);

60st\.pop\_back\(\);

61

62intl=cur\.a,r=cur\.b,d=cur\.c;

63intmid=\(l\+r\)\>\>1;

64intls=mid\-l;

65intrs=r\-mid;

66intss=r\-l\+1;

67

68longlongw=base;

69if\(l\>1\)w\-=cb\.c\(n\+m\-ls\-2,m\-1\);

70if\(r<n\)w\-=cb\.c\(n\+m\-rs\-2,m\-1\);

71if\(l\>1&&r<n\)w\+=cb\.c\(n\+m\-ss\-2,m\-1\);

72w%=P;

73if\(w<0\)w\+=P;

74

75ans=\(ans\+w\*d\)%P;

76

77if\(l<=mid\-1\)st\.push\_back\(\{l,mid\-1,d\+1\}\);

78if\(mid\+1<=r\)st\.push\_back\(\{mid\+1,r,d\+1\}\);

79\}

80

81cout<<ans%P<<'\\n';

82\}

83

84return0;

85\}

Similar Articles

Google ramps up agentic AI efforts amid pressure from Anthropic

Reddit r/singularity

Google has formed a dedicated strike team to improve its coding AI models, ramping up agentic AI efforts amid competitive pressure from Anthropic. This signals an intensifying race in AI coding capabilities between major AI labs.