This is an interactive problem a contest with an unusual start time.
You are given a Codeforces account and $$$n = 6$$$ problems, authored and prepared by qwexd and jeroenodb.
In one operation, you may choose a problem $$$i$$$ ($$$1 \le i \le n$$$) and submit a program intended to solve it.
The maximum scores are given below. Problem E is divided into two subtasks.
| Problem | A | B | C | D | E | F |
|---|---|---|---|---|---|---|
| Maximum score | 500 | 1250 | 1500 | 2500 | 2000 + 1500 | 3000 |
The points awarded for a correct submission may be lower, as determined by the Codeforces scoring rules.
Your task is to maximize your total score before the time limit expires.
The input consists of the problemset of Codeforces Round 1121 (Div. 2). It became available on Sep/13/2026 20:05 (Moscow time).
The round is rated for participants with a rating below 2100. Participants with a rating of 2100 or higher are welcome to participate out of competition.
For each problem you choose to solve, submit a correct program. You may solve the problems in any order.
Printing YES is not sufficient.
It has been shown that every problem has a solution. The proofs are now available in the editorial.
The following participants were the first to construct correct solutions:
| Problem | A | B | C | D | E1 | E2 | F |
|---|---|---|---|---|---|---|---|
| First to solve | Timosh | maspy | maspy | Zinc-acetate | aryanc403 | Elysion | sevlll777 |
| Submission | 390608920 | 390610083 | 390612143 | 390615219 | 390617508 | 390623166 | 390633124 |
We would like to thank:
- Proof_by_QED for coordinating the round;
- Um_nik for the preliminary review;
- Alexdat2000 for translating the statements to Russian;
- our testers: __baozii__, nifeshe, Noobish_Monk, fuad720, temporary1, turska, Rayo, shorya1835, cry, TAhmed33, Rvess, omsincoconut, flammifer, robert9524, ismailfateen, osvarp, samsoom, Nyemot, SpyrosAliv, Sacha, Argentum47, snowythecat, EduardoBrito, wakanda-forever, linearspace, chromate00, simplelife, Vespasian_1, nik_exists, Svivl, ALnQ417, and HobVIIb1 for testing the round and providing valuable feedback;
- our testers who didn't test: _istil, Arpa, sammyuri, AksLolCoding, BLOBVISGOD, sorry12000, naneosmic, Euclid73, i-love-ayase-momo, and ArnedeB;
- KAN and MikeMirzayanov for Codeforces and Polygon;
- you, for participating in the round.
Thank you for participating!








As a tester, I may have started a trend with announcement posts :)
When I set a round the announcement will be encrypted and can only be decrypted with a private key I won't give to anyone. And also all the problems will be analytic number theory.
Finally a trend that is not instagram type shi and i appreciate it.
true
I stand by and vouch for him.
Did the registration close, if not how to register?
You can register by clicking the Register Now button on the sidebar
Your blog is answer code for this problem
Deleted
can i have one too
Thank you for making my bedtime 2 a.m.
Mine is 3 a.m.
No more "Sleeping early instead of CP makes a better life" lol
mine 0:05a.m
This contest starts at 00:05 a.m. in Vietnam btw
I'm IN vietnam wtf
just give up atp
Before you add the score distribution put it in a Scoring section instead of where it is right now
Also I think you should note the unusual start time
as a tester, i tested the round announcement
effort
didn't have to call me out like that smh
He did
thank you for making me not have to get up early
as a tester, im glad i didnt end up on the shame board.
please highlight the unusual start time, someone might not notice!
Done.
thanks
maybe bold it?
Maybe you should add something (before the problem statement) like
This is
an interactive problema contest with unsual start timeyay the authors actually did it
As a tester, you shouldn't be saying "We would like to thank you, for participating in the round" because I will not participate.
reading last part be like
inline
its bed time for me
heuristic problem in codeforces!
also, i want examples, i don't read statements, only examples and notes
As a tester, the best thing I did wasn’t solving the problems it was bringing in a better tester than me, shoutout Rayo my goat
Good time for Chinese students
Why is 1:05 friendly to Chinese students?
Do your evening self-study sessions last until 23:00?
That was sarcasm.
1:05 a.m. is obviously a terrible time for Chinese students.
one more outside the box announcement!
Hope to not get a Brain Limit Exceeded verdict :)
By the way, creative announcement though. Initially, I thought I had entered into a problem statement haha...
As a tester I would like to say that this is my very first comment.
Guess I'll be doing Codeforces from midnight Monday, what a good way to start a week.
As a tester who didn't test, my memory limit was eaten by the zombies.
No not midnight again!!!
tested
creativity
Nice way of announcement!
Very pioneering!
The pressure for creativity is going up for the next announcement.
Thank you for making my bedtime 3 a.m.
I guess the next announcement will take the form of a chat message.
Love to see an announcement getting more creative
Bro thinks he's nik_exists
orz nik_exists
Really Amazed by the Announcement Style!!! What an Idea! WOW!!!
memory limit per participant should be 1 brain and 0 ai
Using AI will result in Memory Limit Exceed XD
Well i was not gonna participate but now i will after this creative announcement.
who cares?
As a nontester :(
Good news: I have no brain.
Hope to get back to CM!
You will definetelly return.
why E and F are ordered that way if total score for E is bigger than for F? even in 1120 div2 we have B > C1 scores so its fine, feels like problems should be swapped
Is Shakespeare really dead?
the most creative contest announcement ever
It can be shown that this problem is orz
Amazon SDE II Interview Experience (Bangalore, Selected) ~ Aug 2026
congrats
As a participant, my goal is to solve two problems. Good luck to everyone!
all the best guys
Thanks everyone for participating in Codeforces Round 1120 (Div. 1, Div. 2). Although it was initially difficult to understand from the editorial when I first participating in Codeforces contests. However I found that once I got used to it, the explanations felt very easy to understand, accurate, and highly academic. I'm just saying little advice, I mean do it when there is the editoral. We should read the hint and solution before reading code (Sorry for my bad English) I came from the past, not the future
Interesting annoucement! Thank you for making my bedtime 3AM :(
Bad timing for me
Does this have any interactive problems?
speedforces?
Thank you for making my bedtime 2 a.m.
Ahh man!! Had to unregister because of goofy timing
I hope I reach rating 1500+ after this round good luck to everyone
Awesome contest anouncement this is so creative bravo authors
Why is the competition held at midnight?
Midnight for us, but lunch for them :skull:
i have to become specialist by the end of november
Oh no!!!I have to go to school!!I can't get up at 01:05!
allow hacking
btw why unusual time?Any specific reason? qwexd
Yes, I was wondering about that as well
RIP my sleep
Users in the announcement are displayed with their max rating color instead of their current rating... orz
Except you
Bad time for Chinese programmer!!!
for any asian programmer too lol
wtf was that D
Very difficult round. C was itself very difficult as compared to other D2 C's (atleast for me). Disappointed!
But I think it's much easier than the CF2263C, especially C2.
That I couldn't disagree.
How to solve F? I tried Lagrange interpolation on the first 50 terms of the deranged sequence and then represented it in binary(by using
(n/n+n/n)), but it ended up taking 323612 characters, which is way over the 10000 character limitupd: the answer is n! / e
The problem is writing $$$e$$$ and $$$n!$$$ in few enough symbols and have enough precision on $$$e$$$
You can also use
D_n = n * D_{n - 1} + (-1)^{n}and tweak it a little bit to work for all k <= n.The number of derangements is given by $$$n!/0! - n!/1! + n!/2! - \dots$$$
which can be expanded to be $$$1 - n(1 + (n-1)(\dots))$$$, and you can adjust the sign afterwards using $$$\mathrm{round}$$$, which avoids computing $$$e$$$ entirely
damn, why did I even bother staying up
For $$$D$$$, when we put three 1's, I just guessed something about the sizes of the groups of 0's and it passed. Could anybody prove it?
lets say we have all 0's
this will give us order of len2 segments (every L and every R is a valid — len*(len+1)/2).
so breaking it into half (with only one 1 in the middle) gives us (len2)/4
similarly breaking into more parts will further reduces the segments count
now look at the powers of 2
U know the divisibility property of 3 is the sum of digits should be divisible by 3 in decimal, doing same here in binary its sum of modulo3 for powers of 2
Now we need to choose the indices where we don't try to avoid having three 1's in the mod3=1's position or three 2's in mod3=2's position or one in 1's and one 2's, if its possible
and given it is atmost 3, placing two 1's is always better than placing one 1; depending on the length required we try to place 1's they creates least number of numbers whose mod3==0
now based on length of the binary string there is a pattern that repeats that u need to catch
Modulo with negative numbers...
Is D too non-trivial or am I dumb? First three looked way more intuitive
solved D after long time, but I don't know how it works
n=20and observed the pattern,n=10andn=16was a bit different but that also worked forn=22so I just guessed it will continue to work.this time I might get good delta due to
Dbut then next time it will cause me big negative delta .. lol !!!I didn't create a full proof either but it has to do with modular arithmetic and powers of a number being cyclic under another modulo
oh ok, hope the editorial explains it to us more clearly !!
How to solve E1?
The only thing that matters in a subsequence is the maximum and the minimum value which can be found using dp, then you count.
We can precalculate the X value for any two number using a dp-form thing. like g(a,b) for the max x we can get after operations so that a->x and b->x. Secondly, f(b)=g(min b_i,max b_i). So we can enumerate over all min b_i and max b_i and calculate the corresponding contribution.
(I'm not sure if this is correct)
I hate those problems like C, in which I spend half of the time finding the integer overflow somewhere. I found the recurence in like 10 minutes and then spent 20 minutes debugging. I think I would be able to find solution to D with that aditional time.
#define int long longI wrote integer overflow, but meant anything like that, in this situation it was some stupid modulo with negative numbers.
Just do
if (ans < 0) ans += MODbefore you printansAlways add an extra modulo just to be safe
If you struggle with this (I did too, in this contest), consider using a wrapper type to handle the tricky modular arithmetic.
See 390656416 for example; if you scroll down to the SolveCase() function the core logic is quite simple.
Solution sketches for A-D (I didn't get cooked):
A. We will only have to operate on indicies that are out of place ($$$i \neq a_i$$$), so simulate the operation on all out of place
B. We can compress the formula to $$$b_m \cdot m$$$ minus the rest of the elements. Use a
std::multisetto track the $$$m - 1$$$ least elements behind each potential final element.C. It's a somewhat complex formula, see my submission, but basically we're sorting the array and taking each element's contribution.
D. Write a brute force, and notice for sufficiently large $$$n$$$, there is always a unique solution with three ones that ends with 1. We can find constructions that end with 1 for $$$n = 6 \dots 12$$$ and notice that due to the fact that $$$2^k$$$ is cyclic modulo $$$3$$$, we can construct a similar solution for any $$$n$$$ and $$$n + 6$$$. Store the solutions for $$$n = 1 \dots 12$$$ and construct similar solutions for $$$n \gt 6$$$ from $$$n = 6 \dots 11$$$. See my submission for more details: 390645815
Carrot broke for me, can someone check my performance?
idk how to attach photos but it says you performed at 1615 (edited cuz forgot about system testing lol)
yay maybe I'll be above my peak after rollback
edit: I think 1615 is wrong was that mid systests
I got a rating predictor(idk if it is carrot) and show you got performance 1841 and +48
thank you Roaring Knight
great summary
390653924 I try B as same logic as you ,but i getting Wrong at test 2 ,while my code editor giving correct output.
From the test case you failed on it seems to be integer overflow but I'm not entirely sure
Math contest, good problems!
Solved D fast:)
Great Contest
i'm so happy i managed to solve C for the first time!!!!!!!
Same
I am curious about how checker for D works
The best I can think is that first we can count all the substring whose all element is 0 after that for every index i we will check for the nearest 1s in string and check whether they are multiple of 3 or not and add them in this way i think checker could work in o(n) , but there has to be good and efficient way
some kind of dp
like 'how many substrings end at index
iwithr mod 3' .. I feel this will be linear... didn't think very much thoughsince there are at most 3 1s, the f value can be calculated within O(1) complexity.
(p.s. specifically, this is because only the parity of the index of 1s matter when checking if a string is illegal.)
madly difficult C; had it not been for the unusual start time i may have solved it. good round tho, really challenging for once!
How to solve Problem C?
C Madamant's Skating Dynasty O(N log N) Approach
First, sort the array so we can process the elements in order.
Then, we calculate suffix sums. This lets us quickly find the sum of all the elements to the right of the current position instead of calculating it again and again.
We also precompute factorials up to N, since the formula uses factorials such as (N-1)!. For the division part, we use modular inverses because everything is calculated modulo 998244353.
After that, we go through the array once, calculate the contribution of each element using the formula, and add everything to the answer.
The sorting takes O(N log N), while the rest takes O(N)
What is the formula
Breakdown:-
(n — 1)! / (n — i) Call this Bi
Bi x ∑(a[j] — a[i]) for i < j <= n Call this Ci
Final answer is ∑Ci for 1 <= i < n.
after sorting in desc cost until ith elemet = (i-1)*cost unti i-1 + (prev no of trees) * fixed cost per tree fixed cost per tree= sum till i — i*ai prev trees= prev tree * (i-1) update cost
Also it can be solved with dp too.
Nice contest excellent problems I like it thanks to authors for contest!
E2 question: I solved E1 with an O(n^2) approach and tried submitting the same solution to E2, but it TLE'd on pretest 3. I understand that E2 needs a better complexity, but I'm having trouble seeing the optimization. What was the key observation for making the E1 approach fast enough for E2? I tried submitting it during the contest because I wanted to see whether my E1 solution would surprisingly pass E2 as-is, since I already had the E1 solution working. I didn't want to wait until after the contest because I was curious about the actual result. Also, the solution was completely my own I was just experimenting with whether the E1 complexity would survive the E2 constraints.
C: I tried to
% 998244353before sorting it XPbut it's really a good problem!
i like you so much this round is so good <3<3<3<3<3
It was a really exiting contest.
I enjoyed it.
Thank you, Codeforces.
I love you.
Hi!
What was the accepted time complexity for B?
$$$O(n \log n)$$$
I have an O(N log N) solution using 2 priority_queues, but still get Runtime error, and I don't get it. Could anyone check it out, please?
maybe pq is empty (m=1)?
Yes, that was it. Thank you
wait so do u have to use a priority queue? i lowkey havent learnt that yet so i was wondering if its possible without.
yes, with the formula I reached:
sol = max(sol, M * Bm — S)
where S = B1 + B2 + ... + Bm-1
I basically had to determine the best pair o minimum S sum and maxim Bm
So you do need 2 priority_queues or a multisets (but the priority_queue is a bit better in time complexity)
I used the first pq for the B1, ... , Bm-1 so I can always have the smaller elements <= i, and if something smaller appears I can quickly take out the bigest element I had and replace it (because the priority queue keeps the elements in decresing order)
The second pq is for Bm, to always know the biggest element I have remaining in the interval from i+1 to N. And I only remove elements if they are not in the range any more.
I hope that I answered your question clearly :)
yeah I think i get the solution now. What I did wrong during comp was that I missed the simplification at the start where the sum is just the max element * m — (b1 + b2...bm-1).
yeah, me too, I only realized near the end
also, pq does push operation in O(logN), and top(), pop() in O(1), so it is way more convenientthan sorting every time
I really hate E1 with 5th test
I liked the problem and have no issues with it; I just noticed that many solutions failed on test case 5 (including mine), so I decided to write about it.
Its not a TLE error, logical error. Mine failed there, but I was checking if the primes dividing x and y are the same, and not if the primes dividing y is a subset of those dividing x
I realize the fault is entirely mine—I had a brain fart—but it sort of turned into a local meme that Test 5 fends off all attacks from incorrect solutions.
I was used to the 17:35 time and had it in my head that it started at 20:35; then I logged into the system and was shocked to see that the contest had actually started at 20:05.
Please don't do this again—only hold contests at 17:35.
Why are you downvoting? You could have just written that you disagree with my opinion and that this contest time works for you.
Good contest, really bad time for the round :(
Its bedtime here for me lmao
Deleted
i'm not even the author what
Good contest! Thank you, nik_exists. I hope we can build a great relationship and continue sharing knowledge and experiences.
I didn't read 'exactly m' in problem b and then lost 40 min implementing a solution with two segment tree for frequencies and sums and coordinate compression. Anyway really cool contest, i wished i had more time for D.
Same for me I tilted after that
good contest
we need more div 4 and div 3 contests please for newer
I'd like to thank nik_exists for such a lifechanging contest!
Thank you nik_exists for this beautiful contest! Before this contest I couldn't get past outskirts in rain world and now I've beaten the game on hunter with my limbs removed. I enjoyed how every problem was about obscure number theory algorithms. Thank you.
loved the round ❤️
strange scores for problems and very hard D (at least for me and my friends ) but cool A-B-C thanks for the contest but I hope to have a more balanced D next time :)
Yesterday I give this contest and Now I got a message regarding getting same answer copying from other user. I really do not understand why I get this message because I obviously solved Problem B by my own. It might be coincidence that user loly.talal might get same thinking process for this process, it doesn't say that we cheated on this problem. This is a div2 B and I do not think there might be different solutions for this problem, so it is common to get same solution for this kind of easy problems.
Please remove the “skipped” tag from my contest participation; otherwise, it may negatively affect my rating and could result in my account being banned.
I completely agree with you! This was a straightforward Div. 2 B problem, and it's totally normal for multiple people to have the exact same thought process and standard approach independently. There was no copying at all, and it's just a coincidence. Hopefully, the status gets resolved and our ratings/submissions are restored properly.
how I can get Accepted with this problem?
Hello,i'm not sure but System warned me for my D problem and i will try to clarify my state so i will explain in this blog(System said "If you have conclusive evidence that a coincidence has occurred due to the use of a common source published before the competition, write a comment to post about the round with all the details.").First of all thanks for not blocking my account and giving me a chance to clarify the state.Firstly i accept that some cheaters used same logic with me and their code is AI written(Which they got banned).I want to state that this code was written by me and in my style(You can check my old submissions).Also i tought that n<=2e5 for all test cases which is why i used memorization(also no other people used memorization for this problem).Normally i was not gonna solve this problem but i saw that "Dr. Agos wants a pattern with at most three lit pixels that minimizes f(s) among all binary strings of length n, including strings with more than three ones.". After i saw this i can divide the string in 3 which would reduce answer because a string which it's length is x and only have 0 contributes very very much to answer(x*(x+1)/2) so i need to minimize x.Then i tried all N values from N=1 to N=14(Which is why i spent 50 minutes on this problem)(and i want to upload my notebook page but i don't know how any help will be appreciated.) .After trying i had a general idea and implemented my idea.Also i want to state that Editorials solution uses my idea but it tries more than 1 possibilities.Well i can't prove proofs rn but if i manage to upload fotos this will definitely be helpful for me.Also i want to say that i really tried to get AC because i was saying a lot "Tomorrow i will be Specialist" to my friends from Olympiad and i spent a lot of time on B and C and according to Carrot i couldn't be Specialist and next contest is in 5 weeks and today schools have opened and i want to enter to new school year as a Specialist so i had a really big motivation in solving this problem (Even my friend mhdkr2012 said me that he was gonna send me all of his money to me if i manage to solve problem D.)So in the end i manage to solve this problem because of a big motivation.Also a lot of my friend knows me and they would help me with the case.TIA.
I found some people thanks nik_exists for the great contest, but realizing that he is not even the author...
@MikeMirzayanov
I received a plagiarism/coincidence warning for my submission 390640446 for problem 2264C, which was reported as coinciding with BlackAugust's submission 390638218.
I want to clarify that I do not know this user and did not copy their solution or share my solution with them. I independently solved the problem.
I understand that there are significant structural similarities between the two implementations, particularly the suffix sum, factorial calculation, and modular inverse calculation. However, these came from my own implementation of the solution.
My submission also contains an additional duplicate-value check and differs in several implementation details.
I would appreciate it if the submissions could be reviewed manually before any penalty is applied.
My submission: 390640446 Flagged submission: BlackAugust/390638218
wait how am i yellow in the blog
Subject: Explanation for Code Coincidence (Problem 2264C — ArefinMahir)
Hello Codeforces Team,
I am writing regarding the plagiarism warning for Problem 2264C (coinciding with user 'SuperIntelligence'). I did not intentionally share code or collaborate with anyone during the round.
The code coincidence occurred due to two unintentional public exposures during the contest:
Public Online Compiler: I experienced local setup issues running C++ directly in VS Code, so I executed my code using an online compiler without changing the default privacy setting from public.
Public GitHub Repository: I configured automatic code pushes to a public GitHub repository as part of learning Git and GitHub.
Someone likely scraped the public compiler output or public GitHub repository during the round and submitted the code.
I understand that public code exposure is my responsibility. I have changed my GitHub repository to private and configured an offline C++ compiler in VS Code to ensure this does not happen again.
Submission ID: 390651278
Matching Submission ID: 390651632
Thank you for your understanding.
[Deleted]
Hello Codeforces Team,
I sincerely apologize for the violation related to my submissions in the contest.
My Codeforces account 23h51a05w2_codeforces has been disabled, and I am currently unable to access it. Therefore, I am posting this comment from another account only because I cannot access my original account.
During the contest, I was experiencing problems with my PC. Because of this, I used Ideone to run and cross-check my code. I now understand that using Ideone with publicly accessible code could have resulted in my code being exposed and could explain the significant similarity detected in my submissions.
I sincerely regret this mistake. I understand that even if the code leakage was unintentional, I was responsible for following the Codeforces contest rules and for ensuring that my code was not publicly accessible.
I did not intend to gain an unfair advantage or share my solutions with other participants. Nevertheless, I understand the seriousness of the situation and accept responsibility for my mistake.
During the contest, I was experiencing problems with my PC. Because of this, I used Ideone to run and cross-check my code. I now understand that using Ideone with publicly accessible code could have resulted in my code being exposed and could explain the significant similarity detected in my submissions.
I respectfully request the Codeforces administrators to please review my case and consider restoring my account 23h51a05w2_codeforces.
I have learned from this incident and will be much more careful in the future. If my account is restored, I promise to strictly follow the Codeforces rules and will never use a public external service for contest code again.
I understand that the final decision is completely up to the Codeforces administration, and I will respect whatever decision is made.
I sincerely apologize to the Codeforces Team and the community and kindly request one opportunity to correct my mistake.
Thank you for taking the time to review my request.
Again massive cheating, just block everyone from India.
Hey someone kindly give this post an upvote it's currently at 1299 make it 1300.