Hello, Codeforces!
We are proud to invite you to participate in Atto Round 1 (Codeforces Round 1041, Div. 1 + Div. 2) which will be held on Aug/07/2025 17:35 (Moscow time).
The round will be rated for everyone. You will be given 8 problems, one of which is divided into two subtasks, and 3 hours to solve them. One of the problems will be interactive, so make sure to read the guide for interactive problems before the contest.
The problems are authored and prepared by Ali_BBN, Bahamin, _R00T, eren__, sweetweasel, and me.
We would like to thank:
- Error_Yuan for his great coordination.
- Alexdat2000 for Russian translation.
- errorgorn, StarSilk for nutella testing.
- _istil, abc864197532, yuanruiqi, [MVP] LMydd0225, A_G, maomao90, AmShZ, N_z__, Keshi, zeemanz for red testing.
- arashmemar, ooscode, A_M_Namdar, radal, mohammadsam, ParsaF, IliyaEslahi for orange testing.
- AlefHeKaaf, Shahrad_Mirzaei, rewhile, Siyah, ParsaS for purple testing.
- theSkeleton, iliya_mon, Kosar, amir_AP, Ardelion, KiaRash24, hamidh100, mathtsai, Behrad. for blue testing.
- FrontMan. for cyan testing.
- MikeMirzayanov and KAN for the great platforms.
- You for participating!
Special thanks to [MVP] LMydd0225 for his invaluable help during testing!
The scoring distribution is below.
| A | B | C | D | E | F | G1 | G2 | H |
|---|---|---|---|---|---|---|---|---|
| $$$500$$$ | $$$1000$$$ | $$$1500$$$ | $$$2000$$$ | $$$2500$$$ | $$$3000$$$ | $$$2750$$$ | $$$2750$$$ | $$$4000$$$ |
Now, a few words from our sponsor!

At Atto Trading, we are a science-driven quantitative trading firm where engineers, quants, and researchers combine their efforts to engineer cutting-edge trading systems that execute in nanoseconds, powering decisions at the speed of light in the world’s most competitive market. Many of our team members started their journey on platforms like Codeforces. We are thrilled to announce our own round on Codeforces platform.
Follow the link below and complete the application form to explore career opportunities with us.
We prepared some exciting rewards for participants in this round.
- Rank 1: Apple MacBook + backpack + branded T‑shirt + sports bag
- Ranks 2-3: Apple iPad + backpack + branded T‑shirt + sports bag
- Ranks 4-5: Apple Watch + backpack + branded T‑shirt + sports bag
- Ranks 6-20: Backpack + branded T‑shirt + sports bag
- Ranks 21-100: Branded T‑shirt + sports bag
If we encounter difficulties delivering your gift, we reserve the right to reimburse its value in cryptocurrency
Good luck!
UPD 1: Score distribution was released!
UPD 2: Editorial
UPD 3: Congratulations to the winners!








as a tester, i can confirm the problems are "absolute cinema"
Huge thanks in advance to all the problem setters. Really excited for this round and the amazing problems ahead!
As a tester, “googooli” contest
its means cute in persian? lol nice. nice..
Nice problems, recommend to participate
Hoping for a positive $$$\Delta$$$
Ayy, massive congratulations to Hamed_Ghaffari and eren__ for snagging silver medals at IOI2025! The GOAT has officially announced his round!
ORZ ORZ ORZ
And a huge shoutout to the entire Iranian National Computer Team for achieving the 7th global rank at IOI2025, with Hamed and Mani being a part of this incredible squad! What an outstanding achievement for all of you and our country!
What about sweetweasel who got bronze :(
My bad, I thought that account is for another person, anyways it seems that they're cooking ;))
sweetweasel <3
As a tester, it would be fun for every participants, from gray to Nutella!
As a tester, this is one of the best rounds of the past 2yrs, I actually enjoyed solving the problems and didn't swear at the writers
As the "MVP", I want to copy Error_Yuan's words:
Nice problems, recommend to participate:)as a tester, my biggest regret is not being able to participate in this round
I think the problem statements should be short and easy.
"What is the probability of me winning an Apple MacBook?"
nonzero
depend on tourist performance
like this comment if you join this contest in order to miss gf :heartpulse :heartpulse
as a tester, this contest is "MAMAMIA MAMACITA COACHELA"!
August 7th is my birthday. Although I won't take part in the contest, best regards for everyone.
happy birthday
I'm new to comp. coding and this is my first contest, and I hope to give it my all. I love codeforces and the community so far :)
Why are the competitions held in my sleeping time?
unfortunately, almost every contest is held at this time, so you might be kind of screwed
EST has to get up at 4 in the morning lol
Can kevin exceed tourist?
Yes, because I am also a huge fan of Kevin.
as a tester , I wish i could go back in time and choose to participate in this round instead of testing it ! :)
.
Wish interactive problem is D.
Rank 1 tourist.
It started with 9 rejected problems. It ended like this:
Iranian tradition is so goood.. liked it..
I originally planned but now I am unable to participate this round. Anyway, hope it has great problems and may it be cheater free!
Otto Round?
Thanks! Hamed_Ghaffari for providing this Information and I'm so much excited to participate in this contest.
It is essential to identify and prevent the use of AI-generated code. Dear author, please consider taking appropriate action regarding this issue.
It would be much better if you also gave away prizes for some of the ranks 100-1000. This would increase the competition.
as it is a round sponsored by quant company i guess this will be a math round
Standings/leaderboard is broken? I can't open it
nope
I can't open it either. Fortunately the rest of the system seems to work. With the dashboard you can see how many people solved a given problem.
true, but what i wanted to know is whether i can safely go sleep without getting -delta
I HOPE I GOT + Δ
B>>
aaaaaahhhhh !!! got idea of D so quickly .. but the WA -> WA -> WA -> WA -> WA ..... -> WA -> AC
and 1 to 3 is CASEWORKforces
u don`t need casework for C
or any of the A-C
oh ok .. I solved it that way ...
for A -> I was thinking mex can be 0,1,2,3 ( but later realized not needed ) for B -> 2 cases ... go left or go right .. and put wall to left or put wall to right for C -> ranges overlap ... don't overlap.
feel free to check my submissions, i feel today's A-C I wrote it beautifully
I think you are awesome because you are able to think simple solutions .. my strategy is called
PANIC and FREAK OUToh I did range merging kind of thing .. where I had to handle overlapping and non-overlapping ranges
but I guess we can say minimum gap which I later figured out.
Can you explain how you solve D
so if
any cycle... not possible ..ans = 0.. cycle check can be justm >= nbecause it is given that all are connectedbecause if you have cycle then either edges will cross or it will not be bipartite
otherwise it will be a tree
now it has to be like a chain where every node with degree > 1 has to be along a chain ( like a linked list ) .. otherwise edges will cross .. if any node in that tree which has deg > 2 is connected to more than 2 such nodes .. .we return 0
once you make that chain then it is kind of how many nodes are connected to chain .. product of their factorial ... because chain nodes are fixed but nodes connected to those node can be independently permuted so their factorials get multiplied
then you can flip across the river so
x2if length of chain > 1, then you can flip the chain so
x2Thank you, I had the same idea but cannot figure out the implementation.
https://mirror.codeforces.com/contest/2127/submission/332891533
yeah I also had hard time in this.. just look at my WA submissions .. so many :(
... got lucky like 5 min before end
My test case for deg>1 not in single chain also contained a cycle so it didn't catch my nonworking detector. Caught it right after the contest ended :/
sorry !! not clear
all nodes deg > 1 will be connected in a single chain right ... what do you mean
not in single chain.. but I understand the frustration.. I also solved like 5min before contest after struggling for hours .. was almost crying LOL
If any node is connected to more than 2 nodes with degree>1 then they cannot be put into a chain. My solution skipped already visited nodes so they didn't get counted. All I had to do was change count>2 to count>1 and it would pass lol
oh no I get it ... lol .. I also wrote some messy code to handle this.
Struggled alot to understand questions :<
can anyone please explain how they solved D?
It may not be difficult to implement, but it requires careful analysis of the problem For the problem to have a solution: 1. The graph must not be a circle (it must be a tree) 2. If we root the tree from a leaf, all children except one must be leaves (you can check) Then you have to go and multiply your answer by the following value at each step: (count is the number of leaves) ans *= count! ans %= mod Finally multiply by 4 (horizontal and vertical symmetry) We also have an exception!!! If the graph is star-shaped (all vertices are connected to one vertex) Then the answer is 2 * (n-1)!
First, note that if the graph isn't a tree (or a forest, but statement says it's connected), the answer is $$$0$$$, because there's no way to build a cycle of bridges without a self-intersection or a bridge connecting two houses on the same side. Then, note that assuming the answer is $$$ \gt 0$$$, in the tree, every vertex can have at most $$$2$$$ neighbors which aren't leaves, otherwise there is a non-leaf neighbor fully cut off by remaining bridges from this vertex, a contradiction. Thus, the non-leaf vertices of the tree form a path (assuming a non-leaf vertex exists, but otherwise $$$n=2$$$ and the answer is clearly $$$2$$$)). Then, note that there are either $$$2$$$ or $$$4$$$ "distinct" ways to create the path, depending on whether it's size is at least $$$2$$$ (choices are first riverbank and "direction"), and then for each vertex on the path neighboring $$$d$$$ leaves, they all have to be between the neighbors on the path in any order, so we get $$$d!$$$ options for each. Just multiply everything and we're done.
I was trying this, but only passed the given test case
If both of the above conditions are satisfied, then only we can have an arrangement
For the total number of arrangements
Not sure what is wrong with this approach. Can someone please point out the mistake
Based on what you've written (haven't seen the code), you appear to be incorrectly answering the case when there's only one vertex with degree $$$ \gt 1$$$, and therefore the right-left flip doesn't do anything. EDIT: Checked the code and you did take care of that, so I don't know.
no that case is correct when only 1 node with degree > 1 then x1 will be n-1 I do not consider the up-down flip, so skips multiplying by 2 But I am considering a left-right flip, so multiply by 2
The final answer comes out to be 2 * (n-1)!
One clarification -> I am considering the right-left flip to be across the river — different from the picture given in the question
-- I feel like my approach is correct, but I have made it unnecessarily complex, and must've made some implementation error
Your explanation makes it much easier — thinking in terms of a tree. Thanks, will try to implement that
first off labeling nodes with colors isnt needed because the graph must be a tree, and all trees are bipartite graphs so you can check if $$$n = m-1$$$ instead. Second your "one of these nodes should have a degree >1 to prevent the crossing" is either wrong or worded badly. The right condition is that "at most 2 neighbors of any node can have a degree >1". There are only 2 places for a neighbor with degree >1 to fit (right and left) and any middle spot will cause a cross.
Looking at your code, your counting seems right but you don't make sure the graph has no cycles and your double bfs for degree counting is funky.
Was I the only one unable to access standings throughout the whole duration of the contest?
probably
bro did not read my comments
I can only access it using my phone.
I turned off my wifi and tried to access the standings using mobile data and it worked instantly. Seems my ISP is blocking standings? That's really weird...
Great problems! But sadly problem F is chatgpt-solvable. Proved by BinaryPhoenix10 and other talented participants. Bless them!
You are right! I couldn't find a solution better than O(nk) then I just search on chatgpt on find number of n-element arrays of sum y such that each element is at most k, and it gives me the closed solution using exclusion-inclusion. Then, I ask to do the same on number of n-element arrays of sum at most y and each element at most k, and it gives me a very clean solution computable in O(k) time (by using some combinatoric magic) which gives us a O(nlogn) solution! Too bad, I only read your comment after the contest!
OHH MAN B WAS SO TOUGH . IS IT SAME FOR OTHERS?
istg same
literally got me brainstorming with pen and paper for an hour. When I finally got AC, I was so happy.
HOW DID YOU SOLVE IT CAN YOU PLEASE HELP
the formula is
optimal = min(minCover + canCover, maxCover) + 1
here minCover is the minimum of leftCovered and rightCovered. maxCover is max of leftCovered, rightCovered. leftCover is the distance between left most index (0) to the closest left side wall from the position of hamid, similarly rightCover is the distance between the right most index(n-1) and the closes right side wall. canCover is the distance between left closest wall and hamid, if leftCover is minCover or it is the distance between right closest wall and hamid if rightCover is minCover. The entire problem is based on which side will Mani put the first wall, once that is found, the problem will naturally be easy. The formula i told is based on which is the most optimal side to place the wall at
My code for C Can anybody tell me where I m wrong
gainFromPaircan larger than 1e9suppose that:
A: 0 1e9
B: 0 1e9
Omg wtf did I do lol ;(( Wasted nearly 2 hrs and missed this, anyways thanks
awesome man. I only thought about sorting a. somehow i did not think about sorting b and checking. Good for me that by the time i got to "my solution" time ran out xD
Hahaaha lol
I GOT THE BEST RANK I'VE EVER GOTTEN IN CF TODAY. I'M SO HAPPY.
guys what this error Compilation error this is first time This appears to me
your code did not compile on judge compiler,
if it compiled successfully on your machine then it might be setting difference.
How to do C guys? I can't think anymore
You can take some (i, j) pair over and over again so its basically solve for k = 1 everytime. Then u just need to find (i, j) pair that adds least amount to original answer and just take that all the time. Furthermore if u have a[i], b[i] and a[j], b[j] then this pair only adds extra if max(a[i], b[i]) < min(a[j], b[j]) or vice versa and it adds 2*(min-max). So we sort pairs {min(a[i], b[i]), max(a[i], b[i])} check if there exists any adjacent pairs such that min < max(basically add 0) and if none exist take the minimum of min-max of adj pairs.
First thing first, only 1 round matters, because Ali can keep choosing the same i and j and only one time Bahamin can gain points. Now, If you have i and j, such that max(ai, bi) >= min(aj, bj), then there will no score gain from this pair and Ali can choose this pair, otherwise try to minimise gain, which you can see here: 332903480
thanks for this one! I cannot believe I did everything else apart from this and how close I was to this one...aaaaaah man! Anyways thanks a lot brother, very well written code!
how C?
C is doing good, thank you for you concern.
this can help https://mirror.codeforces.com/blog/entry/145242?#comment-1300336
too hard -_-
B was really easy in retrospect, but I was in off-by-one indexing hell during the contest. Also didn't help that I misread at first and thought you could only move one space at a time :|
C was interesting, it was pretty funny that K didn't matter at all (noticed this <5min lol)
Overall good problems in retrospect and orz to the problemsetters, even if I trolled
can you please share you easy idea for B
the best way Mani can put a wall is 1 on the right or on the left of Hamid. He chooses the maximum of the two cases. Once the wall is placed, Hamid chooses the minimum of going to the right or to the left, and the best choice is where the first wall is closer to the edge
yeah I did something similar, thanks for sharing this idea.
Thank you for these problems! I don't remember the last time I enjoyed solving a codeforces round as much as I did today (:
E was nice, proving that adding additional color to a subtree(if the subtree doesn't already have that color) doesn't improve the cost was the key!
What's up with H limitations? Is the model solution exponential in $$$n$$$?
Yes. It is about $$$\exp(n/2)$$$. Now we realize that we should change this problem into counting...
Even counting version can be solved in O(M)...
Now we found some really obvious solutions to this problem (like graph matching), but none of them are found during testing. Even worse, the only tester who solved this problem used the same algorithm as MCS.
We apologize for this bad-setting problem — it shouldn't have occurred in the round. We are very very sorry for the bad experience.
The problem is fine. Just give $$$n \le 500$$$ or $$$n \le 50000$$$
I wouldn't say it's bad, just unexpected for me. It's not a big issue when authors don't have the best solution for their own problem.
I think most linear-time solutions can also support counting as well (at a cost of being quadratic, possibly)
Enjoyed D a lot. Literally the first time to go through an hour of thinking to get to a correct answer, and the trill of seeing the pretests passed is just incomparable!
I can't remember a codeforces round where the problems were as enjoyable as today. Thank you!
H is the worst problem in the history of cf. Just random shuffle the edges 1e5 times and choose greedily(as the order of the edges) passes. 332898118
I loved this contest, thank you for such great problems.
Amazing contest... thank you very much!
I need 29 rank to become red... And predictor shows +29... Hope
Good luck! Where is that predictor?
Carrot extension
oh wow !! ... all the best... also I am hoping that some AI cheaters will be skipped so hope you make better delta than what predictor says
also can you please share which predictor you use ?
carrot
oh alright, thanks for the reply
ATB!
I need 1 more rank to become purple :( Good luck bro
2399 :))
I hope you become red in the next contest :>
rk103… No!!! My tshirt!
sad/(ㄒoㄒ)/~~
C Good problem.
I don't understand whats wrong with my code for problem B.
Anyone please explain.
I was doing something similar but I can suggest you not to use x--. Anyway, if you count based on the position of x (not x--), the answer is either x or n-x+1, while if you count based on the position p of the wall you place, the answer is either p+1 or n-p+2
I couldn't figure out where I messed up on D
Successful hacks in A are not put in to main test? There are 6 successful hacks in A during contest but no fst!
Hacks were added to the main tests before system testing. This problem has ~10 tests now.
I filtered the submissions with more or equal to 5 test cases and sorted them by judging time in desending order, and it seems only codes that are submitted after contest are tested in 10 test cases. And when I open my own A code which submitted during contest, it only has 4 tests.
I was also wondering why there are so few FSTs when people managed to hack 6 submissions just during the contest time (which highly suggests that many, possibly hundreds or even thousands of solutions will fail with the hacks).
I think this really requires rejudging the solutions of A... Why is rating already udpated before addressing this issue?
Great contest, thanks to the authors!
Can my A be judged please? It is still at "pretest passed", and my position in the standings does not include my points on problem A
Hamed_Ghaffari sweetweasel eren__
https://mirror.codeforces.com/contest/2127/submission/332803312
Update: Thanks for the help
I love the round! Thanks...
deleted
I wasted like 1 hour in A and ended up not solving it anyway i guess it happens ???
yes it does. you atleast tried for 1 hour .. I just get frustrated and give up around 15-20 min mark .. keep up the practice.
I've found the tree cute in the cutie points problem!
The questions are quite interesting, especially question C. Thank you to everyone for their contributions! (Please forgive me for commenting using a translation software. My English is not very good QAQ)
Excluding the issues on H, I think the round was pretty nice. Thanks to the authors.
Very good round, thanks for brilliant problems
Could you give me a +1 in rating after the rollback? Thanks in advance!
Another red Syrian in queue...
Our GM couch.
MikeMirzayanov
I have to be annoying this time. Give that man his +1!
Take a look at Reyna's max-rate.
take 3 lol. Congrats.
Thanks!
What the hell was question D my gawd wasn't able to configure it out at all
D problem was very good
Hello, My handle is 10_Mahen. I received a warning about solution 332893401 coinciding with others. I did not knowingly share my solution publicly, but a friend (handle: madhurdingalwar123) copied it without me understanding that this was against the rules. I now understand that even unintentional leaks are not allowed, and I take responsibility for being careless. This won’t happen again, and I ask that you please consider this as a first-time mistake. Thank you for your understanding.
I would like to sincerely apologize for violating the Codeforces rules in Round 2127A. I submitted a solution (ID: 332894758) that was copied from my friend, not fully realizing that this constitutes a serious rules violation, including unintentional sharing. I now understand that Codeforces does not allow any form of code sharing or copying during contests, even between friends.
This was my mistake, and I take full responsibility for it. I assure you it won’t happen again in the future. I’ve read the rules and guidelines at http://mirror.codeforces.com/blog/entry/8790 to make sure I understand them clearly now.
Please accept my apology, and I respectfully request leniency this time as I was unaware of the seriousness of this action. I am committed to fair and honest participation going forward.
I(Darsh_01) recieved a mail regarding that my solution of problem 2172B coincides with many others solution but I have not used any third-party apps or shared my code with anyone. I think it is because of those people also thought of the same logic for the problem which is a legitimate case in my opinion. I have not copied my code from anywhere and I give all my contests honestly. If there are any further clarifications needed I am open to give as I have written a genuine code by myself. Thank You
I just received the prize from Atto Round. It indeed contained some nice gifts, thank you for that.
However, I have one concern. I was asked by the delivery person to pay a tariff and tax in cash then. Although the amount was small this time (around $2), such payment without any prior notice does not seem appropriate to me. I would appreciate it if future shipment situation is improved.
Yeah, that's something I've ran into with prizes before as well.
Problem is the sender can't afford to make sure everything is ok on your end. Import authorities are rather harsh on prizes/gifts — sometimes they demand an extra fee, sometimes a declaration that you really only received it for free and its value is low enough, etc. It depends on the country and on how an import/export officer woke up that day. The sender can try to pay what they understand as correct for your country, but it's imperfect and they're not going to know if everything went ok unless you tell them since communicating with various imports offices is tough and tracking package status doesn't give that much info.
It's not on the contest organiser. Your import/export office may be at fault, or otherwise it's just that there are too many rules for these things in the world for a tech company to watch out for. Maybe an intermediary company dedicated to sending the prizes correctly could be found... or there was one here and then it's their fault.
What are the import rules for material prizes in Japan? They're not free under a certain value limit?
Then I'm so lucky that I haven't ran into this kind of issues for $$$\ge15$$$ years.
Thanks for the explanation, sounds true. I even heard that the payment differed for another recipient this time. I don't think these issues are common sense and the "without any prior notice" part in my comment still makes sense.
I can't say for sure as I'm not a law expert (and Japanese official site for this seems down for some time now...), but my understanding is that there is a tax exempt for <=10000JPY in this case. I received much valuable prize without an issue recently.