
Hello, Codeforces!
I am very excited to invite you to my second-ever contest, Codeforces Round 1065 (Div. 3), which will start on 20.11.2025 17:35 (Московское время)! In this contest, you will be given 2 hours and 30 minutes to solve 7 problems, two of which have been split into subtasks. The subtasks for a given problem are not necessarily placed adjacently in the problemset.
The round will be hosted by the rules of educational rounds (extended ICPC). Thus, all solutions will be judged on preliminary tests during the round, and after the round, there will be a 12-hour phase of open hacks. After the open hack phase, all accepted solutions will be rejudged on successful hacks. Also, note that there is no score distribution — rank will be determined by number of problems solved, followed by penalty; wrong submissions will incur the usual penalty of 10 minutes, following the rules of educational rounds.
As a reminder, only trusted participants of the third division will be included in the official standings table. This is a compulsory measure for combating unsporting behavior. To qualify as a trusted participant of the third division, you must:
- take part in (and solve at least one problem in) at least five rated rounds
- and not have had a rating of 1900 or higher at any moment in time.
Regardless of whether you are a trusted participant of the third division or not, if your rating is less than 1600, then the round will be rated for you (unless you register unrated).
Also, note the rule restricting the use of AI. If you are caught breaking this rule, you will be condemned to life spent in prison the basement of some unspecified Codeforces user. Said person's basement is a rather unenjoyable place to live in, so I would advise adhering to the rules.
I would like to thank the following people for helping make this round possible!
- cry for his excellent coordination;
- Vladosiya for translating the statements into Russian;
- satyam343 and Lilypad for discussing problem ideas with me;
- djm03178, satyam343, Dominater069, and Intellegent for being very important people who have contributed significantly to the round;
- Dominater069, nifeshe, Intellegent, catgirl, temporary1, Friedrich, djm03178, wuhudsm, -firefly-, efishel, Edeeva, yse, SpyrosAliv, ritam1234, chromate00, Ermiooo159, kevlu8, Argentum47, expertaq, simplelife, ByteRaider, and RJ_Parin_fr for testing;
- macaquedev for pretending to test;
- MikeMirzayanov for the incredible Codeforces and Polygon platforms;
- and most importantly of all, You for participating!
Good luck, and have fun!
UPDATE: Due to issues with Cloudflare, the round has been rescheduled for 20.11.2025 17:35 (Московское время).
UPDATE: Editorial









As a tester, yuri is peak
Yuri (from Angel Beats!) is peak.
Totally agree.
K-On and Kobayashi could be great, I think. Though you said Angel Beats is the peak.
Well, I think Toaru Kagaku no Railgun is also great, according to your avatar.:)
the gif is peak
that is true
a @reirugan round ? i wish it will be as good as your previous div3 round !!
anime kiss jumpscare
peak div.3 content
unfortunately i was forced to remove the previous gif... but have an adachi instead!
unfortunately my comment got removed too, I thought it was funny.
No anime kiss ): Thats cool too
what's today's codeforces topic?
yuri
thanks
Could you please remove the gif?
Are you homophobic
No comment. ( Though, I commented :) )
Yeah I am now remove it (and give source thanks).
what the f-
ru sociable, then??
More than you?
codeforces when my mom enters the room
literally loading page in GTA San Andreas when mum enters
as a tester, this gif actually spoils the entire contest
I got jumpscared so hard by that gif.
'condemned to life spent in the basement of some unspecified Codeforces user' when are we specifying this lad
we internally run an auction for each subject to determine whose basement theyll be assigned to
I can confirm that we have increasing bids on the amount of distress given to punish the cheaters, and then the basement with the lowest bid is chosen (We don't want all of our basements occupied by cheaters)
As a tester, unspecified Codeforces user is yuri
As a tester, reirugan tested my yuri knowledge.
What is the anime name so I can watch it with my family later?
I believe the GIF is from Samurai Flamenco.
Edit: the GIF was changed today, current one is from Adachi and Shimamura.
Tester here — had fun with this round! Cool problems (gif got changed)
source? for cf practice ofc
we got gay codeforces before GTA VI?
Who is gay?
you
can't wait for the contest's problem statements
is this a hint that there will be at most 18 problems?
$$$7 \lt 18$$$ you know...
opening codeforces is never disappointing
As a participant always love to taking part in Div. 3 contests
All my favorite NYU students have helped in this contest. Wow!
who is your favorite? :v
you r my og <3
The picture is beautiful, feeling happy when opening codeforces.
Btw, who is the charactor in the picture?
sakura adachi!
Having heard about it for a long time, I haven't seen it. I will do that after the contest, thanks!
As a reirugan fan good luck guys
安達としまむら round!
Who is in u avatar
Related ? $$$67$$$
Adachi Sakura!!!
How lucky I am to see a Yuri picture on CodeForces! It really makes me curious.
"macaquedev for pretending to test;" lol
yeah, I got bored and fell asleep.
Uhh what do you mean by that??
Usually subtasks are enumerated, for example, G1 and G2, and are therefore adjacent.
In this case, it's possible the subtasks are enumerated with different nonadjacent letters.
Can I try? I'm just a new person
Yes, you can. Div 3 and 4 are intended for beginners.
Llegar, partir y merendar
Hope to solve at least 5 problems,thus increase my rating.:)
bro how you predict that?i really dont know, can you say for ex how many problems i need solve every div2 contests to reach speacialist
In common, you should solve 3 problems or solve 2 problems fast(that depends on the difficulty of the contest) in div.2 to reach specialist. In div.3, the number of problems you solve is usually 5.
Today is my birthday:)
how can i participate as a tester in a competition?
hope everybody get a positive Delta
Unfortunately, that’s impossible… unless, of course, a miracle happens!
Looking for a "Demon Slayer" based contest if we are entering the zone of anime in cf!
Thank you cloudflare for forcing this round to be delayed
I blame the vibecoder that broke cloudflare's code
me too
was the contest originally now and they postponed it or am I tripping
The contest was originally now, but was postponed due to Cloudflare's incident I think.
What just even happened XD
Cloudflare exploded
what is wrong with cloudflare :》
I was looking forward to the yuri. At least it didn't happen during the actual round.
Why is the contest delayed?
cloudflare (was or is) down for like an hour.
I don't think it was just an hour, more like 3 hours
cloudflare became wrong
cloudflare crashed so everything crashed
hello?
Wtf???Rescheduled , was looking forward for the contest.
Actually it went well just before the contest begin...lol
I hate Cloudflare:(
I hate Cloudflare(
just wanted to solve some Div3 for me
It's amazing that Cloudflare is fixed a minute before the original contest start time.
I'm seeing that Shayan's and Arpa's streams are scheduled to release within the next three hours. Please get rid of them!
Arpa's video has already been delayed
I believe Shayan hasn't prerecorded his video; my understanding is that he usually screenrecords live during the contest
Thanks for pointing it out, though!
Why the contest has delayed but the stream has not delayed?
I am looking looking forward to the contest.
Why 48 hours delay :(
So, Cloudflare has always been the villain?
cloudflare disappointed us all
thanks i have my exams tomorrow. 2.5 hrs saved. I'll utilise this in sleeping
W organizers!!! I thought I would miss todays round (╥﹏╥)
I hate Cloudflare...
Dead internet theory has a new definition now
Non-hackers getting a crawling ban is sweet justice given all the pain hackers have experienced over the past year.
Adashima is the best!
C2 > DEFG
is c2 not exactly the same as c1? you just do the same logic for all the bits.
Really?
D looked so simple but its soo hard. I am curious to know its greedy strategy
there's a greedy construction, traverse from the back searching for 1 and simultaneously keep a note of the minimum excluded value, when you reach 1, you can jump to the mex value position and iterate like this ...
Really ? C2 is just a little bit harder than C1, we only need more 1 for loop to check from the Most significant bit. Could you show how to solve E ?
loop 2,1,4,6,5,3,9,11,12,10,7,8
Div. 3>>1
For problem E,my code 349964120 construct a permutation with atmost 1 bad index.I wonder whether 6 was there just to confuse.
master for a reason!
Your solution is really great!
but 6 is so that there is more freedom for more solutions and no need to do small and annoying tweaks
for example my code might even have 3 or 4 bad indexes 349936459
mine with 0 :)
what about n = 3?
N>8 :(
you can't change the range of n to justify your answer.it gives 1 for n=11,for n=3,answer will always be 1.
just saw , I mostly checked for larger ones , my claim is wrong :(
5 2 4 7 6 8 (11 10 3) 9 1
https://codeforces.me/contest/2171/submission/349987169
I have started with taking prime number and then there multiples like 2's multiple, 3's multipe, 5's multiple.
If in any case no multiple's are present then I am adding them in between 2's multiple with position gap of 2.
For larger n, #prime numbers <<< #2's multiple.
My B solution kept failing on some hidden case, I am confident my logic is correct. Also for D, I was trying to use DSU based approach but kept timing out. Any ideas on approach for problem D?
In Problem E, why multiples of 2, 5 and 10 doesn't work but multiples of 2, 3 and 6 work ?? Is it because we can have at most 6 bad indices and not 10 indices ?
we can make 0 bads as well , the fact that matters is that for any N there are total primes always <=N/2 with N :)
a proof for why 2,3 specifically work:
consider a solution of the form
**_**_**_...
where the * themselves form a sequence s.t. the adjacent * are not coprime. clearly, such a solution has no bad indices. so, it suffices to find a sequence of the * numbers with length >= 2n/3.
consider multiples 2 and 3. it now suffices to show that these cover 2/3rds of 1 .. n. consider partitioning 1 .. n into disjoint groups of 3 starting from 3. let j be the first number in the block (e.g. 3,6,9,etc.). if j%2==0, then j%2==0 and (j+2)%2==0. so we have covered 2/3 numbers in the range j,j+1,j+2. if j%2!=0, then j%3==0 and (j+1)%2==0. so we have also covered 2/3 numbers in this range. so, from any n we can form a valid sequence * using multiples of 2 and 3, but making sure we carefully place 6 to connect the 2 and 3 multiples. so we use 2 4 8 .. 6 3 9 15 .. for the *'s and fill in the rest.
felt like this was hard compared to other div3
I was able to do G in $$$O(N * log(N) ^ 2)$$$
Code link: https://codeforces.me/contest/2171/submission/349941964
Is there a better solution?
I also thought of the same solution, but too lazy to implement
I transformed b into a, and my solution works in O (N log(max(A)).
Basically, if all b[i] >= 2 * a[i] then we make all even and divide by 2 else we subtract the differences 1 by one
Submission link
That was an awesome contest for me! After giving so much effort, i solved the c problem
I solved A, C1 and C2 but not B wtf?
Woah! C2 >> B
The middle ones cancel out
B is tough if you miss the fact that only a[n]-a[1] matters on the first glance.
Is this div2?
++
Felt difficult than almost all the div3 I participated in till now ...
F is much easier than E, and is too close to D, separating them by E was just evil.
Also, I skipped the first sentence of each problem since it add nothing to the statement, this also caused me to not notice that it has two versions...
E was easy and tough at the same time :)
I got an WA on pD but I don't know why. Can anyone help me? thx
Check this case 4 6 2 5 1 3
Your answer is NO, but the correct answer is YES.
n = 9 consider { {5, 6, 7, 9}, {2, 8}, {1, 3, 4}} All the three components are connected. But min(first) > max(last)
I personally not satisfied by today's div3 :( Maybe I will get downvotes. I just shared my sadness
How tf is this a wrong edge list !?
you have to print the numbers not the indices :)
Please say I didn't waste so much time thinking I had to print indices :)
I'm so happy to reach such a high place in this round! The thrill just won't go away!
Congrats! Well done.
Your code looks good but the hacking round isn’t over haha. Good luck hope you stay at #1.
C1 & C2 are nice problems! I was looking at C2 and had absolutely no idea how to do it but after a quick peek at C1 I had an observation that got me through C2!
Had it not been for C1 i would have been stuck at C.
Why would you want to make the
mod1e6 + 3 on G?Do you have a solution that does not require precomputing factorials?
I missed this. You're right. Thanks for explanation :)
If all the constraints are kept the same except for the mod (most importantly, $$$1 \leq a_i \leq b_i \leq 10^6$$$ is kept) and we only considered $$$t = 1$$$, I'm aware of a (partial) solution with two steps than can be done in $$$O(n)$$$ for the first step and $$$\tilde{O}(sqrt(mod))$$$ for the second step (per test case). This idea still requires precomputation, but only for factorials up to $$$b_i - a_i$$$, so we need an additional $$$O(max(b_i))$$$ precomputation. With $$$t = 1$$$, this idea can support mods around $$$10^9$$$, however it 1) cannot be used to solve G for significantly larger $$$t$$$ (I suspect $$$t = 10$$$ already causes TLE) and 2) is definitely not suitable for Div 3, for reasons I will explain later.
We start from the part of the solution where we are required to evaluate $$$\frac{(\sum c_{i})!}{\prod(c_i!)}$$$.
The denominator can be solved by simply precomputing all possible factorials up to $$$10^6$$$, and using mod inverse.
For the numerator, as we restricted ourselves to $$$t = 1$$$ test case, it suffices to find a fast solution to $$$n!$$$ $$$(mod$$$ $$$p)$$$. This has already been previously explored. It suffices to find a solution to the case where $$$n$$$ is a square number, and let $$$P(x)=(x+1)(x+2) \dots (x+m)$$$, and evaluate $$$P(x)$$$ at $$$x = 0, m, 2m, ... m(m-1).$$$ A naive evaluation takes way too long, so instead evaluate this function using FFT. This calculates $$$(m^2)!$$$ $$$(mod$$$ $$$p)$$$. To extend to $$$n!$$$ $$$(mod$$$ $$$p)$$$, let $$$m = \lfloor \sqrt{n} \rfloor$$$, and perform the calculation. For the final $$$O(\sqrt{n})$$$ missing multiplications, it suffices to do standard naive multiplication over mod $$$p$$$ starting from the $$$(m^2)!$$$ $$$(mod$$$ $$$p)$$$ result. The bottleneck of this solution will be the evaluation of $$$P(x)$$$. In the worst case, $$$(\sum c_{i})!= mod-1$$$ (otherwise, we immediately know our answer is 0), and so $$$m = \lfloor \sqrt{mod} \rfloor$$$. Thus, this step takes $$$\tilde{O}(sqrt(mod))$$$ time.
https://fredrikj.net/blog/2012/03/factorials-mod-n-and-wilsons-theorem/
Can someone please tell me why my dsu code for D is giving WA? Submission:349981598
Consider the case 3 5 2 1 4
Your answer is NO, but the correct answer is YES.
Step 1, the code performs union(5, 3).
Step 2, the code only performs union(4, 1) and union(4, 3).
I gave this contest after registration properly. And it was my first contest. Then why it is appearing in unrated section and not in rated section for me? Help pls
The contest will be rated after the hacking phase is over.
I introduce a solution of problem E,but I can't prove it(maybe I just know a little) Firstly, make a number of (n/2)+1 called Rt , and continue ues it ,if it's a prime number,put in the first.And then,from 2 to n,make the number mutiples,every time chose two number,such as (prime number, a,b(a and b have mutiples relation)),continue to put such numbers,until Rt > n ,put other number using mutiples relation, ans you will pass the problem.
Rt is a number chosing from (n/2)+1 to n which is a prime number.
i was registered as unrated by mistake in Codeforces Round 1065 (Div. 3) .please check my submissions my name is Manisha0369
Can anyone tell / give any hints IN C problem in genral?
try playing the game starting from the index 1 , think like u are the player playing the game and what optimal moves(swap) u need to play in order to :
or in more simple words , at the ith move , u can either choose to swap or not to swap. swap only if the operation increase ur score than current or it decreases ur opponents score.
// here the easy version assumes only 0s and 1s hence the solution is a lil bit different , the above explained algo fits best with the hard version
// C1 — easy
// C2 — hard
do reply me if u got the approach and consider upvoting it :)
i guess $$$O(m \sqrt m)$$$ memory gets passed in problem H (you just need to use 16 bit integers) 349971224
My rating is 1177 and had never got higher than now. I have solved at least one problem in at least five rated rounds, such as 1858, 1879, 1878, 2166, 2169. And I had never cheated in any round. But I wonder why it shows "Unrated allowed"?
Hello
Can anyone please help me to find cases in which mine code will fail (Give Tle) for problem — F It is giving tle on test case — 12 Thanks for helping
i cant write a comment here
I have a very easy solution to c1 and c2, you just have to change the checking condition in the c2 version. Now it says that the play should be optimal, that means if it's the first player's turn and he is ahead in score , then he won't swap. Likewise , if he is down by one then on his turn if on swapping his score increases then only he will swap otherwise not. Second player would do the same. Therefore,the solution might be a very simple greedy approach where on the i'th turn, each player checks the score and then swaps.
Now C1 SOLUTION----->
The snippet shows that first we calculate the original xor of all elements,then on each move swap them. If the score increases like it can be 1 or 0 only. Then on swapping the score of both of them will become their negation.
C2 SOLUTION -------->
In the C2 problem, the score now won't remain 0 or 1, but the logic remains the same, first calculate the default xor of all numbers then the greedy approach to check on each move whether the scores will change or not. We just update the scores in different way in C2 because in C1 only 0 or 1 were possible pair of total xor scores. Thank You, Niksy
very ezzz round for div.3
Tbh when i see a div 3 i smile it's easy and so amazing to pass , Hope they will be more div 3's by the time and also Good luck To everyone on this kind of contests or else !
That animation is so cool. I just love it