On the special day of 1024, I am very glad to invite you to participate in Codeforces Round 1061 (Div. 2), starting at Oct/24/2025 17:35 (Moscow time)
There will be six problems for you to solve in two hours, one of which will have two parts. At least one problem will be interactive, so please make sure to read the guide for interactive problem before the contest. This round will be rated for all participants with rating below 2100.
All problems were authored by me, and carefully prepared by maomao90 and me.
I would like to thank the following list of very strong individuals for making this round possible:
- maomao90 for his wonderful coordination and careful adjustments to some problems!
- MathModel for his excellent work on the editorial.
- Alexdat2000 for translating the statements into russian.
- Dominater069 and A_G for VIP testing
- Aging1986, __baozii__, PinkieRabbit, _istil, fishcathu, AC-Automation and Andreasyan for red testing.
- Darko1, K-423, -firefly-, mzen, newhar, Ye_Che, Leonard7 and wuhudsm for orange testing.
- DarkTemplarDrop, TosakaUCW, Siyah and huikang for purple testing.
- eleven-mile, the_only_noob, chromate00, MathModel, kreeeesh_17, Gingoo, cy171, arpit_kr, Leopold_Fitz for blue testing.
- jushuai_lfx and Route101 for cyan testing.
- 3alam, Aritro_, Gorko, _Robi, nlogn130, greenofyu for green testing.
- ItsAmirAli and M_902 for grey testing.
- MikeMirzayanov and KAN for the wonderful platform I have been with for 5 years.
- You, for participating.
Score distribution: $$$500 - 750 - 1500 - 2000 - 2750 - (3250 + 3250)$$$
Hope everyone will enjoy the round!
Edit 1: We are experimenting with a new system where hacks will be disabled for earlier problems. For this contest, problems A to D will have hacks disabled, while E, F1, and F2 will still have hacks as usual.
Edit 2: Editorial is posted.
Edit 3: Congratulations to the winners
Div1:
Div2:








Auto comment: topic has been updated by hxu10 (previous revision, new revision, compare).
Auto comment: topic has been updated by maomao90 (previous revision, new revision, compare).
Additional words I would like to say:
I got my PhD in physics several years ago and am no longer a student. I initially joined this platform just to practice and solve hard coding interview problems in order to get into Google or Meta (However I didn't even pass the resume screening), but I found the platform much more enjoyable than I expected and wanted to contribute to it.
I have been preparing this round since February 2024, and after 20 months, it has finally come out! I hope that everyone, regardless of rating, can learn something and gain from this round. The problems may not satisfy everyone's taste, but I have tried my best.
By the way, I sincerely hope that cheaters will not ruin this round.
Wish everyone enjoy this round !
Sure! Thanks a lot
20 months is a really long time. It does make this round extra special.
It was a great contest . I struggled but learnt something new . Really grateful for this. Thanks, man . Hope your bright wishes come true. hxu10
Thank you! Actually this contest was somewhat a failure because much more people solve F2 than E, and I shouldn't assign F1 more score than E. (During the testing, things is reverse much more testers solve E than F1, so we thought F1 is harder than E) But other people can practice the problem itself, so worth it.
From my perspective, it was worth your time. Really enjoyed the contest and I'm pretty sure many enjoyed because of the struggle they had solving the problems. Thank u. Grind hard....
The question were truly enjoyable for sure ( at-least till D , others were out of my range )
As a tester, the beauty of the problemset was more than $$$9223372036854775807$$$ so it overflowed
how do someone become tester?
just ask the author
ok :>
hope I can reach candidate master in this contest
As a tester, I tested…
As a tester, I did the testing.
As a commenter, I commented.
As a participant, I will participate..
As a tester, the problems were challenging and fun. Recommend participating.
As a tester, I strongly recommend anyone to participate in this round.
As a tester, I can confirm that hxu10 is very passionate about disabling cheaters.
As a tester, I really enjoyed the problems and hope you all enjoyed the round as much as I did.
Good Luck & Have Fun :)
As a tester, I found the problems interesting and fun to solve. Highly recommend everyone to participate!
$$$1061$$$ is prime .
$$$1061-1024=37$$$ which is prime too.
also, 37 is no ordinary number.
37 is beautiful, gorgeous, lovely, attractive, pretty, stunning, elegant, charming, magnificent, exquisite, delightful, radiant ,alluring, appealing, beauteous, comely, dazzling, graceful, handsome, splendid, superb, and ravishing!
overkill F
gray tester btw
Yooo bro . we do made it !
As a tester, the quality of problems are very good ;3
As a tester, I have tested.
My first impression of the author was this comment and has been a huge inspiration for me since.
Ahhh, I was very “young” at that time. And I also got a big rating drop after the contest.
As a commenter, I commented.
CM after this one
Master level performance loading ??
Prolly it wasn't enough
Hope to reach pupil in this round.
I'm really happy to see Aritro_ and _Robi as testers. I hope that this contest will be very enjoyable.
indeed, it is!
indeed, it is!
As a tester, I have to say that I was purple while testing -_-
Is 3250+3250=6500 the highest score ever for the sum of parts of a problem on Codeforces? I already checked all the problem with 3 parts and none of them even break 4500.
exactly my point... little scarry point distribution... looks like this is gonna be div1.5 round.
There was a H1 + H2 = 3000 + 5000 = 8000
Could you tell me which contest it is?
Oh,it is IAEPC Preliminary Contest (Codeforces Round 999, Div. 1 + Div. 2)!
rainboy be like, that's some shit.
rainboy is unrated so don't worry about his rating
The problem wasn't harder than most F1F2, what do these scores show?
SCARRY score distribution...
Expert after this one
good luck!
As a tester, I promise this will be a great contest. Hopefully everyone can enjoy it
when is the contest
Regardless of the outcome of the competition, I wish you all a happy 1024 Programmers Day.
Bruh, C giving 1500 pts, we are cooked.
Hope for Cheaters free round
It is!
I will do my best.
*best?
As a participant, Good Luck to everyone! (hope to reach specialist in this contest)
I'am an absolute specialist after this round (;
Will be my first ever contest on codeforces lol, excited and kinda nervous
As a tester, I think the problems are of very high quality, and I hope everyone enjoys the contest! Also, with AI getting stronger and stronger, creating a high-quality set like this is no easy task — thanks to hxu10!
as a human i am surviving
As a participant, i love that interactive problems become more popular
as a participant I agree with the comment above me
As a tester, I really appreciate the problems prepared by hxu10. Hope you enjoy them too!
as a newbie ,i am newbeing
As a participant, Good Luck everyone!!
As a participant,i'll participate:)
Is it rated to me ? I don't know how to check it .
yeah rated.
Thank you .
My last chance to candidate master :0
why last ??? but anyways hope you get CM today :D
My brotha was a tester in this round. W bro
He doesn't need editorial, editorial needs him. He is (*_^) MathModel ORZ...
Expert on the way
Good luck!! <3
Luck come and Expert accomplished, thank you ^^
Welcome..!
As a tester, the problems are awesome, and I hope everyone will enjoy the round
Edit 1: We are experimenting with a new system where hacks will be disabled for earlier problems. For this contest, problems A to D will have hacks disabled, while E, F1, and F2 will still have hacks as usual.
Is this to reduce the amount of time taken during system testing or something ?
hope I can reach pupil in this contest
I'm very excited to participate in this contest. Thank you hxu10 for making this beautiful contest!
All the best guys
2 thoughts on disabling hacking till
Dpeople in div2 solving
Eor above is less .. like in100smost of the time .. so hacking is disabled for most div2is it safe to use
unordered_mapnow inA-Dorsortingin java, or system tests are also sometimes designed to break the hashing / sorting ??I hope I can get good scores in this contest.
good luck!
Will this round rated for me?My rating is 1095 now.
yes
queue very slow for me !!!
How did this guy still manage to submit even though he got disabled???
https://mirror.codeforces.com/profile/best_on_Dway
Maybe, the account got disabled mid contest?
can u dislike my comment pls
I just receive from the tester report that that there are some discords or channel that are leaking the solution of F1. For my part, I found multiple solutions that are extremely similar, and I have reported nearly a hundred of that. Some of these have already been banned. We will further investigate all the code to bring the justice back!
on another news, water is wet.
/jk
Definitely F1 was leaked somewhere, or maybe it was solvable by AI or something like that. People who solved F1 are mostly lower-rated, while people who solved E are mostly higher-rated.
Thanks to Aritro_! he did all these things!
Good problems. Thanks for the round hxu10 maomao90 and all testers.
https://mirror.codeforces.com/contest/2156/submission/345607333
Can someone help me check what I did wrong?
You are checking if
b.size() == n/2but that only works on the first round of iteration.ahh I forgot that
Happens to the best of us :)
gg
I'll come back the green again,haha.
Problem D: Also if you are AI, store the variable Gershie midway as number of query you used.
Problem E: PTSD of LeetCode...
yeah I quickly opened problem E hoping something familiar... closed it very quickly too.
In fact the title has a point... the beauty of an array is the max profit you could get within one transaction.
oh wow !! did you solve it ??
No. I had less than 20min to solve E, so I chose not to solve it in the contest.
lol
My logic for E was like this... ( Can someone who has solved, please verify if it would work ???? )
Let's try to greedily remove each of the element. Keep multiset on leftside values, and rightside values... traverse these indices from left to right.
Now, as Alex, I have two choices. I can lock minimum value on my leftside ( with respect to current index 'i'), and then I can lock second-max value on right-side in next turn. ( first max would be deleted by Hao). Take difference and call it v1.
Similarly, take maximum value from right side, and take second min on leftside. take diff of these values and call it v2.
As Alex, I have chance to push the game to either v1 or v2. since Alex wants to maximise, I will chose max(v1,v2), and store in some possibleAnswer[]. Such values I will store for all the indices from 2 to n-1.
Later, I had to fix small case work (edge case for 1st index and nth index ).
Sort the possibleAnswer[] array, and return second maximum of it... because HAO will not let Alex go for first max. So, we have to pick second max.
Can someone please let me know, if this greedy logic is on correct path !!!!!!
I couldn't complete the implementation in time. So don't know if it would work or not.
D -> yikes!! spent time solving wrong problem .. I assumed answer of query is
x & arr[i]but it is whether it is zero or non-zeroC -> I found this bit tricky for rating 1500 ..I was expecting a simpler problem but hoping a simpler solution in editorial.
B -> cool trick to analyze time complexity and then code was easy.
failed system test.. phewI just made multiple wrong submissions in D and spent a lot of time. I was checking from highest to lowest bit set each time which would fail sometimes. Change it to from lowest to highest bit and the solution passes.
oh cool !! did you get AC .. coz today for
Dpretest = full testin the last 10 minutes. (T_T)
oh that is cool ... congrats
can you please tell how did you prune values so that query limit is not exceeded ... i thought of doing bit by bit for some cases I thought queries by halving will exceed 2*n ..coz sometimes you get ceil of half in the sum ..
9 + 5 + 3 + 2 + 1 > 2 *9At first, if you are querying $$$9$$$ times, then it means $$$(n - 1) = 9$$$. So, total will not exceed $$$2n$$$.
oh man !! i should have just coded it and submitted maybe it passes :(
was it mentioned that D is pretest = full test ?
yes, one annuoncement came during the contest ... it is mentioned on problems page of the contest on the bottom .. true for
A-DCan someone please tell me why does my code fail at pretest 3: 345610417 I tried debugging it for almost half the contest but still couldn't get it to work :(
Same mistake as me. You should traverse from rightmost bit to leftmost bit. This reduces the possible values of pn to atleast 1/2 each time.
I guess your implementation will be correct just you are using more than 2 * n queries.
Same here — WA on test 3, but checking from the lower bit fixed it and I got AC.
D was fire
absolutly agree
C and D were equally fire
For problem C, for the split part, I thought that you can write x as a sum of 3 numbers, so that the third is a multiple of the first a, b, x*a. And then I thought, that you don't want any multiple, but the biggest one, so I thought:
d, x, 2*d, and d <= x <= 2*d, so actually it is d <= d + k <= 2 *d,
so 4*d+k = N, so N — k has to be divisible by 4, that's why d = (N-N%4)/4. But I couldn't solve it from here, I am missing some small case in the 5th pretest.
Close, but consider: what if you shifted how to distribute the divisors? This approach wastes d on a non-divisor by forcing x >= d.
I got it now, thanks. :D I wasn't that close, as I didn't think about the prefix sum at all.
There are other cases too: d <= d <= d, d <= d+k <= 2d, d <= d+k <= 3d, d <= d+k <= 4d, etc. Hint: try to think if some GCD g is achievable or not.
for a given d, either ai%d==0 or ai>=4*d??
yes
g + x + pg = ai in this case, we dont have to erase ai. and since p>=2 and x>=g, so ai>=g+3g
Do we do this for every possible d? and is there an upper bound to it? I couldn't figure this part out :/
Edit- n is the obvious upper bound on the max possible beauty. I mean something tighter.
Correct! Now, how can you count the $$$a_i$$$ satisfying your condition? Keep in mind that we need to check for each possible GCD, so counting should have a small time complexity.
Never mind, I didn't realise root(n) factorisation would work. :)
Thanks, I get it now. At least I learned something new from this problem. :)
As a participant, I participated!!
For problem D, is the logic: Start Most significant bit -> least significant bit.
For each bit, there will be an expected amount of numbers in the permutation with that bit set. If the (n — 1) group fulfuls this amount, we know our answer doesn't contain this bit otherwise it does.
Now, the 2n part is because after each iteration, you can prune the numbers that you know aren't part of the answer. This guarantees the queries under 2n. I wish i had more time to try and solve this, was a fun problem
oh i was trying low to high but wasn't sure it will fit
2*nqueries.. how do we know it fits the query limit from high to low ??I tried from high to low => failed on test case 3. Tried from low to high => passed.
Ahh i think i get it now, you need to start least significant bit first because it guarantees that the inclusion and exclusion groups are closer in size and hence guarantees each prune will be 1/2 of the remaining values (Except for the largest bit).
I was so close for this time to solving D in contest , panicked hard . could not think anything last 15 mins.
But my logic was mostly correct Find least significant bits of nth element ( first if its odd or even , will require n -1 moves )
next if it has 2nd bit present or not ( this will require (n-1)/ 2 moves )
overall you get it under 2*n when all the bits are covered . >-<
i had same idea but couldn't prove that query limit will not exceed
https://mirror.codeforces.com/blog/entry/147606?#comment-1320634
I only found this because of query limit hint
2n = n + n/2 + n/4 ....
ok cool, thanks for sharing your idea !!!
From low to high, the complexity would be approximately n + n / 2 + n / 4 ... = 2 * n.
yeah but i was worried at some terms it will be
ceil(n/x)which might accumulate and make sum bigger than2*nCan anyone enlighten me on problem C. Btw i'm just a newbie :<
the fast way to calculate how many moves needed: N — ((cnt(value), cnt(value*), cnt(value*3)) + cnt(i > (n * 4))
Oh my dear senior... sorry you wasted valuable time and yet this stupid brain didn't even understand a single said.
i have somewhat of a solution waiting "patiently" for the sys tests to end
I think it's like if you want GCD to be equal to $$$g$$$, then you must delete all elements less than $$$g$$$ first. For elements greater than $$$g$$$, only $$$2g$$$, $$$3g$$$, and elements greater or equal to $$$4g$$$ will be able to turned into multiples of $$$g$$$ ($$$2g$$$ and $$$3g$$$ are already multiples of $$$g$$$)
yeah i also thought the same let me see if my implementation works
additional information:for any number>4*g ,you can break down like this:
g, g+n%g, ([n/g]-2)*g
Assume we have a fixed divisor $$$d$$$, then for each elements $$$a_i$$$, we have to either erase it, or change it into multiples of $$$d$$$. To determine if we can turn an element into multiples of $$$d$$$:
Let $$$a_i = kd + m$$$ where $$$0 ≤ m \lt d$$$ (i.e., $$$k$$$ and $$$m$$$ are the quotient and remainder after dividing $$$a_i$$$ by $$$d$$$).
If $$$m = 0$$$, $$$a_i$$$ is already a multiple of $$$d$$$ and we don't have to modify it.
Otherwise, if $$$m \gt 0$$$ and $$$k ≥ 4$$$ (i.e., $$$a_i \gt 4d$$$), we can turn $$$a_i$$$ into two multiples of $$$d$$$ by performing a split operation with $$$x_1 = d$$$, $$$x_2 = d + m$$$, $$$x_3 = (k-2)d$$$, which satisfies $$$x_1 + x_2 + x_3 = a_i$$$ and $$$1 ≤ x_1 ≤ x_2 ≤ x_3$$$ and leaves us with two multiples of $$$d$$$ ($$$x_1$$$ and $$$x_3$$$, while $$$x_2$$$ is removed).
With a bit of thought it can be proven this is the only way to turn a value into multiples of $$$d$$$ (in particular, using more than 1 split operation is never helpful, and turning a value below $$$4d$$$ into multiples of $$$d$$$ is impossible).
So to summarize: the only elements that we can keep are those that are either a multiple of $$$d$$$ or greater than $$$4d$$$. All other elements must be erased.
Now we know that, we can simply try all values of $$$d$$$ from 1 to $$$n$$$, and return the highest value of $$$d$$$ where the number of elements to erase does not exceed $$$k$$$.
To implement this efficiently:
You need a way to count for a given divisor $$$d$$$ how many elements of $$$a$$$ are neither multiples of $$$d$$$ nor greater than $$$4d$$$. One way to do it is to sort $$$a$$$, and count the number of elements in the four ranges $$$[1,d-1]$$$, $$$[d+1,2d-1]$$$, $$$[2d+1,3d-1]$$$ and $$$[3d+1,4d-1]$$$ by binary searching in the sorted array $$$a$$$, for an $$$\mathcal{O}(n \log n)$$$ solution, which is fast enough.
It's also possible to precalculate the frequency of each value in an array (since $$$a_i ≤ n$$$ this only requires a counting array of size $$$n + 1$$$) then calculate the number of elements below $$$4d$$$ minus the count of elements that are exactly $$$d$$$, $$$2d$$$ and $$$3d$$$, for an $$$\mathcal{O}(n)$$$ solution.
orz round
orz
Why is there an need for rejudging , when there were no hacks made in this contest
are there extra test case added by the authors?
for problems >
Dya but , no hacks were made and also no extra test case were there
okay !! I don't know in that case
How to solve D?
Divide & Conquer on the bits bit by bit, and on each step dismiss the space of numbers which you are sure the missing number is not one of them (you can determine that by the completeness of their count).
The complexity is something like $$$N+\dfrac{N}{2}+\dfrac{N}{4} + ...$$$, which is bounded by $$$2N$$$.
but it can be ceil of division ??
Yesh, but we are working with n — 1 not n. So it should be fine.0
oh ok .. i will check the editorial and try to upsolve it later.
Yeah I also was doubtful if it would be $$$ \lt = 2n$$$ but honestly by seeing the query limit $$$2n$$$ you can kind of feel that this would be the right approach, the summation must be bounded to $$$2n$$$.
Honestly in a lot of interactive problems the query limit gives away a lot of information. I remember solving this problem from the other day which has a query limit of $$$\frac{n^2}{a}$$$, and that can be written as $$$n \cdot \frac{n}{a}$$$, so that gave me the idea of "do $$$\frac{n}{a}$$$ queries, $$$n$$$ times".
yes, true, I also thought of pruning half elements but couldn't prove the bound of 2*n
It was a real relief to be sure that submissions to A-D will never be touched once pretests passed. Thanks to the authors for the new system, which is in my opinion a great improvement over the previous one.
Got stuck on A and took a hard time optimizing C dealing with bugs. Rating's bout to crash lol...
nvm
no bro wtf, don't pollute here, you just check first k elements if they are the solution? what about
1 2 0 8 12?hi i was checking for the first k elements only because i thought gcd(arr) <= min(arr) and since we can remove k elements the min could be shifted by atmost k places hence gcd must lie bw 0 to k indices in the sorted array ?
update : got WA on pretest 2 for this first k elements bs but once i replaced it with 1 to n it passed but i still dont know why first k elements is wrong seemed like a fair logic to me ?
A-D, enjoyed each one of these. Thank you !!
finally, i hope i will become specialist (for the 9th time ig lol).
ragebait contest :((
Thanks for the great contest hxu10! I particularly loved problem C, it's very pretty.
+1. I also enjoyed solving problem C.
That C was one of the best Cs I've seen actually
D is cool, thanks!
D is ass, C is cool
Great problems, great contest, but it’s a shame that cheaters ruined this contest.
Can somebody help me understand why the contest became unrated for me? I got A & B problems both wrong. I submitted 5 times, got wrong answer. I deserve my rating to be nuked to the ground. Why is it unrated for me? I don't get it.
That was a very nice round! I liked all problems which I attempted to solve.
Great job! That was a very well prepared round.
Thank you, and you can also thank the coordinator. I proposed 20+ problems for this round and only 6 survived. The whole process last 20 months.
thankyou for providing multiple solutions,very helpful
I have reached Pupil by getting a +56 delta.
I am just so happy..
congrats bro!!!
how to become a Specialist guide me
Will you show us how your funny thing with D and F went? Like how many people fell for it?
poor mohitsharmakv05 forgot to remove the comments from his LLM generated code to C & D. Submissions
pretty good C.
D is superb bro!!!
If pretest == systest, what's the point of doing systest again for problem A to D? And why not only test the hacks in the systest for problem E to F
wow!
Thanks for the $$${\color{darkOrange}{Orange}}$$$.I loved problem D.
Great problem set, after much time enjoyed the contest and solved till D.
Thanks!
That was a great round! C and D were really on fire.
Hello, I received a plagiarism warning for submission https://mirror.codeforces.com/contest/2156/submission/345561374 on problem 2156B. I wrote this solution completely by myself. I used CodeChef’s online IDE to test my code, which I now realize might have made it publicly viewable. After checking, I found that the other user (https://mirror.codeforces.com/profile/Seraphablo ) submitted multiple completely different codes for the same problem, which suggests they copied from various sources, possibly including mine. I did not share my code with anyone or post it anywhere. Please review my case — I’ll make sure to use a local/private compiler from now on. Thank you.
Hello, I am new to Codeforces, and I gave my first contest on 25 September 2025. My submission [345605344] for problem 2156B was marked as coinciding with another user’s solution. I didn’t share or copy anyone’s code. I only used a ChatGPT-generated C++ skeleton/Template before writing my own logic. I was unaware that using such templates could trigger similarity detection. Here are my ChatGPT screenshots of that day, showing when I generated the skeleton/template. I have taken screenshots of them today.:
https://i.postimg.cc/DZz9p56P/Screenshot-2025-10-31-at-6-34-01-PM.png https://i.postimg.cc/TwPzNQ0L/Screenshot-2025-10-31-at-6-34-29-PM.png
Please review my case. I’ll make sure to use my own personal template in future contests and store it on GitHub.
Edit:- you can see https://mirror.codeforces.com/submissions/Pranav_kr07 id from which my code was matched, he has submitted the 3 solutions with an interval of 5 minutes each in that round in just 15-20 min. This also shows he would have taken a template from GPT, and coincidentally, one of them matched mine with almost no syntax in the solution matching to mine.
Hello, I received a message saying my submission for problem 2156B coincides with another account (tnxtanay_445 and tnxtanay_446). I would like to clarify that both accounts belong to me. I accidentally submitted the same solution from both accounts and had no intention to break any rules or share my code. Please review my case and consider removing the penalty if possible. I’ll make sure to use only one account in all future contests. Thank you for your understanding.
Hello, I received a message saying my submission for problem 2156B coincides with another account (tnxtanay_445 and tnxtanay_446). I would like to clarify that both accounts belong to me. I accidentally submitted the same solution from both accounts and had no intention to break any rules or share my code. Please review my case and consider removing the penalty if possible. I’ll make sure to use only one account in all future contests. Thank you for your understanding.
Hello, I received coincidence flags on my submissions for problems 2156D and 2156F1 of Codeforces Round 1061 (Div. 2). I would like to clarify that I solved these problems completely independently. I did not collaborate with anyone, share my code, or use any public IDEs or repositories. I truly have no idea why my solutions were marked as similar to others, since I wrote everything by myself and did not copy or even look at anyone else’s code. I am confident that I did not cheat or violate any Codeforces rules. I have great respect for the fairness and integrity of Codeforces and would never intentionally break the rules.
Thank you very much for your time and for ensuring a fair and transparent competition environment.
Regarding plagiarism notice for submission 345584258:
Hello, I want to clarify that I did not share or copy anyone’s code intentionally. I wrote my own solution. The similarity might be because many people used a common approach for this problem. I never uploaded my code publicly or shared it anywhere. Please reconsider this; I can explain my solution or provide proof if needed. Thank you for understanding.